Comments (10)
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.
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.
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.
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.
I believe this is typically handled by sending the contents of the buffer to the 'executable' via stdin.
from eslint-formatter.
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.
Getting this working would also allow for the formatting of inline <script>
s in html
from eslint-formatter.
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.
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.
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)
- Programmatically find Node and ESLint directory HOT 2
- Default eslint_path for Windows 10 Pro 64bit on Sublime Text 3 does not seem to work when there is a "whitespace" (aka a "space") inside profile user name. HOT 2
- Feature request - Exclude folders from formatting
- Files with starting dot in the name are ignored
- Support package.json eslintConfig
- Vue SFC doesn't format missing commas HOT 1
- reload on fix HOT 1
- Jumps to top of file randomly HOT 1
- eslint command-line options support HOT 2
- How to set NODE_ENV or BABEL_ENV in formatter config
- Global name 'data' is not defined HOT 5
- Error panel popping on save HOT 4
- Vue SFC Error HOT 1
- Performance HOT 4
- How to selectively run Eslint-Formatter ("On save" mode) on particular files HOT 1
- Babel 7 upgrade HOT 1
- Slow performance creating new file?
- `eslint_d` instance per Sublime Window causing performance issues
- spawn node ENOENT HOT 1
- Error: Failed to load plugin 'import'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-formatter.