Coder Social home page Coder Social logo

Comments (10)

AoDev avatar AoDev commented on May 18, 2024

Not exactly the same issue but probably the same cause.
I can only format with the option format_on_save: true.

It seems it's not running against the current altered version of the file.

from eslint-formatter.

TheSavior avatar TheSavior commented on May 18, 2024

The formatter doesn't run on the buffer, it runs on the underlying file. If you save the file and then run the command to format it, it will format the underlying file which will update the buffer. You should then be able to format without format_on_save: true.

from eslint-formatter.

AoDev avatar AoDev commented on May 18, 2024

We understood that so far. But that's not what people expect. If we run the command, we expect it to run against the buffer, state of the code that we are seeing.

If for some reason it is not possible, I don't know sublime API, then it would help to mention it in the docs. No?

from eslint-formatter.

TheSavior avatar TheSavior commented on May 18, 2024

I believe it would be possible by having a command that takes the buffer, writes it to a tmp file in the current directory, runs eslint on it, and copies the file contents back to the buffer and cleans up the temp.

Happy to accept a PR adding that functionality or updating the docs explaining how it currently works.

from eslint-formatter.

s7726 avatar s7726 commented on May 18, 2024

I believe this is typically handled by sending the contents of the buffer to the 'executable' via stdin.

from eslint-formatter.

s7726 avatar s7726 commented on May 18, 2024

So some investigating revealed that eslint won't run the fix option if the stdin option is given.
And the fix-dry-run option doesn't seem to actually output anything... Unless you tell it to do the output in json. Which you could grab and write back to the buffer.

cat filename.js | eslint --fix-dry-run --format json --stdin --stdin-filename /full/path/to/the/filename.js

results in a json file on stdout.

[{"filePath":"/full/path/to/the/filename.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"output":"FIXED_TEXT_OF_INPUT"}]

There is a spot in the eslint engine file where it grabs the current working directory. There may be a need to file a pull request/issue to get that cwd exposed as a command line option, that way all the proper config files and things would be pulled relative to /full/path/to/the/
I managed to hack in stdout by modifying only ~two lines of code in eslint. More would be needed to properly cover the options and what not. But it's not too far off from the capability.

from eslint-formatter.

s7726 avatar s7726 commented on May 18, 2024

Getting this working would also allow for the formatting of inline <script>s in html

from eslint-formatter.

TheSavior avatar TheSavior commented on May 18, 2024

Wow, thanks for digging into this! It sounds like there might be some work on the ESLint side to support this functionality. @s7726, I've also gone ahead and made you a collaborator on this project. The investigation you did makes me trust you. :P Feel empowered to modify and add the functionality to this plugin you find necessary.

from eslint-formatter.

s7726 avatar s7726 commented on May 18, 2024

Just noticed eslint_d has a --fix-to-stdout option that works in conjunction with the --stdin option.

@TheSavior Thanks for the Maintainorship. I'm still looking into this on the side of the project that prompted the issue.

from eslint-formatter.

katerlouis avatar katerlouis commented on May 18, 2024

just spent over an hour figuring out why this bloody file wouldn't get formatted .. (after even more hours trying to resolve node path issues..)

I haven't read the entire issue, but my 2 cents on the matter are:
It should definitely format unsaved files;
but if it can't, atleast throw an error with an explanation, so I know what's going on :F

from eslint-formatter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.