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

feat: make no-cycle ignore Flow imports (fixes #1098) #1126

Merged
merged 3 commits into from
Aug 2, 2018

Conversation

gajus
Copy link
Contributor

@gajus gajus commented Jun 26, 2018

No description provided.

@gajus gajus changed the title feat: make no-cycle ignore Flow imports (fixes 1098) feat: make no-cycle ignore Flow imports (fixes #1098) Jun 26, 2018
@ljharb ljharb added the flow label Jun 26, 2018
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -30,6 +30,10 @@ module.exports = {
function checkSourceValue(sourceNode, importer) {
const imported = Exports.get(sourceNode.value, context)

if (sourceNode.parent.importKind === 'type') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sourceNode.parent seems undefined at times - many tests are failing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Was running tests with --grep option. Fixed.

@gajus
Copy link
Contributor Author

gajus commented Jun 26, 2018

@ljharb What is the fix here?

eslint <= 4 does not provide the necessary AST information to describe type import.

@ljharb
Copy link
Member

ljharb commented Jun 26, 2018

@gajus can eslint 4 parse the types at all?

@gajus
Copy link
Contributor Author

gajus commented Jun 26, 2018

@gajus can eslint 4 parse the types at all?

It is the babel-eslint that enables parsing.

However, I am not familiar enough with the internals of ESLint to say what is the reason ESLint <= 4 AST visitor does not inherit properties required to describe the import kind.

All sourceNode can see is:

 Node {
  type: 'Literal',
  start: 29,
  end: 42,
  loc:
   SourceLocation {
     start: Position { line: 1, column: 29 },
     end: Position { line: 1, column: 42 } },
  range: [ 29, 42 ],
  value: './depth-one',
  raw: '"./depth-one"',
  _babelType: 'Literal' } RuleContext {
  id: 'no-cycle',
  options: [],
  settings: {},
  parserOptions:
   { sourceType: 'module',
     ecmaVersion: 6,
     ecmaFeatures: { globalReturn: false } },
  parserPath: 'babel-eslint',
  meta:
   { docs:
      { url:
         'https://github.com/benmosher/eslint-plugin-import/blob/v2.13.0/docs/rules/no-cycle.md' },
     schema: [ [Object] ] },
  eslint:
// [..]

@PinkaminaDianePie
Copy link

Whats the status of this? Without this fix eslint-plugin-import is unusable if I have Flow in my project :(

@ljharb
Copy link
Member

ljharb commented Jul 28, 2018

The tests need to pass before it can be merged.

@PinkaminaDianePie
Copy link

Of course, but does anybody work on it? Or this PR is abandoned?

@ljharb
Copy link
Member

ljharb commented Jul 28, 2018

If you want to help finish it, please post a link here to your branch (not a new PR) and I’ll pull in your commits :-)

@PinkaminaDianePie
Copy link

Sorry, I probably didn't get how to do it properly, but here is my branch: https://github.com/PinkaminaDianePie/eslint-plugin-import/tree/fix/no-cycle-false-positive-for-flow-imports
It works for ESLint 2-4, but I checked it manually by installing old versions - I don't really know how to check it on Travis without creating PR, so I wasn't able to check everything :(

@coveralls
Copy link

coveralls commented Jul 29, 2018

Coverage Status

Coverage increased (+0.02%) to 97.292% when pulling 3feb54c on gajus:issue-1098 into 3b04d5f on benmosher:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 97.292% when pulling 3feb54c on gajus:issue-1098 into 3b04d5f on benmosher:master.

@gajus
Copy link
Contributor Author

gajus commented Jul 29, 2018

Looks like the CI is failing because of unrelated tests.

@ljharb
Copy link
Member

ljharb commented Jul 30, 2018

@gajus the travis failures are flukes; i've rerun them. the appveyor failures are unrelated, and likely in master.

@ljharb ljharb requested a review from benmosher July 30, 2018 18:51
@PinkaminaDianePie
Copy link

nice, i hope it will be merged finally :D

Copy link
Member

@benmosher benmosher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not obvious to me why this is necessary but I trust @gajus so 👌🏻😄

@ljharb ljharb merged commit 0336ef9 into import-js:master Aug 2, 2018
@IhorSyerkov
Copy link

The issue appeared again in v2.17.1

@ljharb
Copy link
Member

ljharb commented Apr 15, 2019

@IhorSyerkov please file a new issue for that.

@murrayju
Copy link

It happens in v2.17.0, but not v2.16.0. @IhorSyerkov did you make that issue? Please link it to this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

7 participants