Skip to content

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

Merged
ljharb merged 3 commits into
import-js:masterfrom
gajus:issue-1098
Aug 2, 2018
Merged

feat: make no-cycle ignore Flow imports (fixes #1098)#1126
ljharb merged 3 commits into
import-js:masterfrom
gajus:issue-1098

Conversation

@gajus

@gajus gajus commented Jun 26, 2018

Copy link
Copy Markdown
Contributor

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

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread src/rules/no-cycle.js Outdated
function checkSourceValue(sourceNode, importer) {
const imported = Exports.get(sourceNode.value, context)

if (sourceNode.parent.importKind === 'type') {

Copy link
Copy Markdown
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
Copy Markdown
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

gajus commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

@ljharb What is the fix here?

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

@ljharb

ljharb commented Jun 26, 2018

Copy link
Copy Markdown
Member

@gajus can eslint 4 parse the types at all?

@gajus

gajus commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown

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

@ljharb

ljharb commented Jul 28, 2018

Copy link
Copy Markdown
Member

The tests need to pass before it can be merged.

@PinkaminaDianePie

Copy link
Copy Markdown

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

@ljharb

ljharb commented Jul 28, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown

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

coveralls commented Jul 29, 2018

Copy link
Copy Markdown

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
Copy Markdown

Coverage Status

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

@gajus

gajus commented Jul 29, 2018

Copy link
Copy Markdown
Contributor Author

Looks like the CI is failing because of unrelated tests.

@ljharb

ljharb commented Jul 30, 2018

Copy link
Copy Markdown
Member

@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
Copy Markdown

nice, i hope it will be merged finally :D

@benmosher benmosher left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown

The issue appeared again in v2.17.1

@ljharb

ljharb commented Apr 15, 2019

Copy link
Copy Markdown
Member

@IhorSyerkov please file a new issue for that.

@murrayju

Copy link
Copy Markdown

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