Breaks magic comments for eslint, Flow, &c.
See original GitHub issuePrettier 1.14.3 Playground link
Input:
// $FlowFixMe: Missing definitions for bowser?
const _setImmediate = bowser.msie || bowser.msedge ? window.setImmediate.bind(window) : setImmediate;
Output:
// $FlowFixMe: Missing definitions for bowser?
const _setImmediate =
bowser.msie || bowser.msedge
? window.setImmediate.bind(window)
: setImmediate;
Expected behavior:
Well…I don’t know what the expected behaviour would be, exactly; but what happens is that the magic comment, which applies to the next line, no longer applies to the code it was written for (in this case, the property lookups on bowser
), because the line was chopped down. You can get the same effect with various eslint-disable
-type directives (eslint-disable-line
, eslint-disable-next-line
). Result: Flow (or eslint) now fails.
I don’t know what the proper solution is; perhaps this needs discussion. Possibilities include:
- Issue warnings when reformatting AST nodes following known marker comments
- Refuse to change line numbers when reformatting AST nodes following known marker comments
- For some types of comments, it could possibly be automatically fixed: e.g. an
eslint-disable-line
directive could be replaced byeslint-disable [rule]
/eslint-enable [rule]
block comments before and after the AST node - Do nothing but at least put a warning in the docs!
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
lines-around-comment - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Flow best practices - Notes about software engineering
Make sure that the project has a working and reliable eslint. Consider adding meaningful rules from the existing eslint plugin created to cover ......
Read more >How I solved and debugged my Webpack issue through trial ...
I mean, this is probably not magic, and there is some module ... stylish = require('eslint/lib/formatters/stylish');const webpack ...
Read more >eslint | Yarn - Package Manager
ESLint is a tool for identifying and reporting on patterns found in ... flat config unignores work consistently like eslintrc (#16579) (Nicholas C....
Read more >Flow – JavaScript Type Checker | Object Computing, Inc.
Types document expectations about code such as types of variables, object properties, function parameters, and function return types. Comments can be used ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bardware As mentioned in the docs we recommend using eslint-disable-next-line:
Prettier 1.15.2 Playground link
Input:
Output:
I think we should start with at least a mention in the docs, and then if we want to do further work beyond that, we can add that later