question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaks magic comments for eslint, Flow, &c.

See original GitHub issue

Prettier 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 by eslint-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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lydellcommented, Nov 22, 2018

@bardware As mentioned in the docs we recommend using eslint-disable-next-line:

Prettier 1.15.2 Playground link

--parser babylon

Input:

/* eslint-disable-next-line func-names */
(function(){
  return 1;
})()

Output:

/* eslint-disable-next-line func-names */
(function() {
  return 1;
})();

1reaction
suchipicommented, Sep 20, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found