Skip to content

import check breaks when exported objects contain spread #49

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

Closed
chase opened this issue Sep 5, 2015 · 4 comments
Closed

import check breaks when exported objects contain spread #49

chase opened this issue Sep 5, 2015 · 4 comments

Comments

@chase
Copy link

chase commented Sep 5, 2015

Here's a strange little edge case I just bumped into.

If any exported object contains a spread of another exported object, import/named and import/namespace breaks.

package.json dependencies:

"babel": "^5.8.23",
"babel-core": "^5.8.23",
"babel-eslint": "^4.1.1",
"eslint": "^1.3.1",
"eslint-plugin-import": "^0.7.8",
"eslint-plugin-react": "^3.3.1"

eslintrc:

{
  "parser": "babel-eslint",
  "plugins": [
    "react",
    "import"
  ],
  "env": {
    "browser": true,
    "node": true
  },
  "ecmaFeatures": {
    "arrowFunctions": true,
    "blockBindings": true,
    "classes": true,
    "defaultParams": true,
    "destructuring": true,
    "forOf": true,
    "generators": false,
    "modules": true,
    "objectLiteralComputedProperties": true,
    "objectLiteralDuplicateProperties": false,
    "objectLiteralShorthandMethods": true,
    "objectLiteralShorthandProperties": true,
    "spread": true,
    "superInFunctions": true,
    "templateStrings": true,
    "jsx": true
  }
}

test1.js contains:

export const test = {
    hello: '1'
};

export const betterTest = {
    ...test,
    world: '1'
};

test2.js contains:

import * as mock from './test1';
import {test} from './test1';

console.log(mock.betterTest);
console.log(test);

Running local ESLint:

`npm bin`/eslint --no-color test2.js

Outputs:

test2.js
  1:8   error  No exported names found in module './test1'        import/namespace
  2:9   error  test not found in './test1'                        import/named
  4:18  error  'betterTest' not found in imported namespace mock  import/namespace

✖ 3 problems (3 errors, 0 warnings)
@chase
Copy link
Author

chase commented Sep 5, 2015

To make it easier for you to reproduce, I've put the files in a Gist you can download: https://gist.github.com/chase/a2da4eee17a14278ec33

I also included a non-spread version that returns no issues when running:

`npm bin`/eslint --no-color test2-nospread.js

@benmosher
Copy link
Member

I think it's likely because Espree won't parse spread, and while you've got ESLint configured to use Babel instead, you have to add the import/parser setting to use it for imports, too.

If you add

"settings": { "import/parser": "babel-eslint" }

...to your .eslintrc, the plugin will also use Babel to parse imports and I think this should work.

@chase
Copy link
Author

chase commented Sep 5, 2015

Sure enough that did the trick, I must be daft for missing it... what with that being mentioned in the README. Thanks again!

@chase chase closed this as completed Sep 5, 2015
@benmosher
Copy link
Member

No worries. I would much rather have the top-level parser be the source of truth for the plugin parser as well, but as of yet I haven't found a way to get at it.

lumodon added a commit to lumodon/echo that referenced this issue Sep 14, 2017
silverwind pushed a commit to silverwind/eslint-plugin-import that referenced this issue Jul 18, 2024
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants