Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard reports unfixable errors for Flow code #1045

Closed
strager opened this issue Jan 15, 2018 · 9 comments

Comments

@strager
Copy link

commented Jan 15, 2018

I followed these instructions to set up Standard with Flow support: https://standardjs.com/#can-i-use-a-javascript-language-variant-like-flow-or-typescript

Unfortunately, Standard reports problems I don't know how to fix. For example, in the following code, I have a Flow-annotated class property called _greeting:

// @flow

class Greeter {
  _greeting: string

  constructor () {
    this._greeting = 'hello world'
  }

  greet (): void {
    console.log(this._greeting)
  }
}

new Greeter().greet()

For this code, Standard reports the following problem:

  /Users/mg/Projects/standard-js-flow-issue/index.js:4:3: '_greeting' is not defined.

If I remove line 4 which declares _greeting, Standard no longer reports the problem, but now Flow complains:

Error: index.js:5
  5:     this._greeting = 'hello world'
              ^^^^^^^^^ property `_greeting`. Property not found in
  5:     this._greeting = 'hello world'
         ^^^^ Greeter

Error: index.js:9
  9:     console.log(this._greeting)
                          ^^^^^^^^^ property `_greeting`. Property not found in
  9:     console.log(this._greeting)
                     ^^^^ Greeter


Found 2 errors

How can I make both Standard and Flow happy for this code?

The following script lets you reproduce the problem from scratch: https://gist.github.com/strager/02f2dbebb3a4f5aafeb0b0fa4041936f/b77094b402bb8ed5cb55e304205a206543696b78#file-set_up-sh (That Gist also includes my yarn.lock file so you can see what version of the packages I installed.)

@on3iro

This comment has been minimized.

Copy link

commented Jan 16, 2018

This is an issue with babel-eslint. Try to downgrade babel-eslint to 8.0.3 then it should work :)

@strager

This comment has been minimized.

Copy link
Author

commented Jan 17, 2018

@on3iro, thanks! I confirm that running the following command makes yarn run standard --parser babel-eslint --plugin flowtype report no issues:

$ yarn add --dev babel-eslint@8.0.3

Even with this workaround, I'm still having problems with my real project. I'll investigate some more and close this issue if my other problems are unrelated.

@strager

This comment has been minimized.

Copy link
Author

commented Jan 18, 2018

I think I figured out what's wrong with my project.

Installing lab (a project which I think is unrelated to Standard) re-breaks Standard:

$ yarn add --dev lab
...
$ yarn run standard --parser babel-eslint --plugin flowtype
yarn run v1.3.2
$ /Users/mg/Projects/standard-js-flow-issue/node_modules/.bin/standard --parser babel-eslint --plugin flowtype
standard: Use JavaScript Standard Style (https://standardjs.com)
  /Users/mg/Projects/standard-js-flow-issue/index.js:4:3: '_greeting' is not defined.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

lab has a dependency on eslint@4.9.x, and it looks like Standard starts using that version of the eslint package instead of its own version (eslint@~3.19.0).

I'm not very familiar with Node's module system. Is Standard using eslint incorrectly? Is this a bug in Yarn? Is something broken in lab?

I tried to work around this issue by explicitly installing eslint@3.19.0 in my project, but that seemed to have no effect.

$ yarn add --dev eslint@3.19.0
...
$ yarn run standard --parser babel-eslint --plugin flowtype
yarn run v1.3.2
$ /Users/mg/Projects/standard-js-flow-issue/node_modules/.bin/standard --parser babel-eslint --plugin flowtype
standard: Use JavaScript Standard Style (https://standardjs.com)
  /Users/mg/Projects/standard-js-flow-issue/index.js:4:3: '_greeting' is not defined.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Script to reproduce: https://gist.github.com/strager/02f2dbebb3a4f5aafeb0b0fa4041936f/74231871320c68db7dd08be67fb8c0aff80270ef#file-set_up-sh

Side note: Standard's cache is broken. I had to run rm ~/.standard-cache/.cache_* in many cases while figuring out what's wrong.

@strager

This comment has been minimized.

Copy link
Author

commented Jan 18, 2018

I had the same issue with npm, so I don't think this issue is Yarn's fault:

$ rm -rf node_modules
$ npm install
...
$ ./node_modules/.bin/standard --parser babel-eslint --plugin flowtype
standard: Use JavaScript Standard Style (https://standardjs.com)
  /Users/mg/Projects/standard-js-flow-issue/index.js:4:3: '_greeting' is not defined.
@strager

This comment has been minimized.

Copy link
Author

commented Jan 18, 2018

With lab installed, installing babel-eslint@7.2.1 makes Standard much more tolerable:

$ yarn add --dev babel-eslint@7.2.1

I have no idea why this works or why babel-eslint@8.0.3 worked without lab.

@stale

This comment has been minimized.

Copy link

commented May 10, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label May 10, 2018

@feross

This comment has been minimized.

Copy link
Member

commented May 11, 2018

standard v11 (released a few months ago) now uses ESLint 4 internally so perhaps this issue is fixed now?

Edit: Meant v11 instead of v12.

@lithium2013

This comment has been minimized.

Copy link

commented May 22, 2018

@feross Maybe you mean v11 instead of v12?

@feross

This comment has been minimized.

Copy link
Member

commented May 22, 2018

@lithium2013 Yes, I meant v11.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 20, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.