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

Dependency parser doesn't respect ecmaFeatures #94

Closed
jameslnewell opened this issue Nov 7, 2015 · 7 comments
Closed

Dependency parser doesn't respect ecmaFeatures #94

jameslnewell opened this issue Nov 7, 2015 · 7 comments
Milestone

Comments

@jameslnewell
Copy link
Contributor

This style of code is very common in projects using React and higher order components. This rule doesn't seem to detect the default export in this case.

//connect a redux store
export default connect()(App);
@benmosher
Copy link
Member

Weird. Not sure why it wouldn't be picked up. I'll add a test and scope it out.

benmosher added a commit that referenced this issue Nov 7, 2015
@benmosher
Copy link
Member

Test passes on my machine OS X w/ Node 4. Can you fork redux-default and see if you can write a default test that fails?

Or send me the import statement that is being errantly reported as having no default (with your .eslintrc)?

@jameslnewell
Copy link
Contributor Author

Ah sorry, it actually appears that JSX is the cause.
My classes with JSX were wrapped in connect calls and didn't work but my classes with standard exports worked fine.

App.js

export default class App {
  render() {
    return <h1>Hello World!</h1>; //comment this line out and it works
  }
}

index.js

import App from './App';

.eslintrc

{
  "root": true,

  "env": {
    "es6": true
  },

  "ecmaFeatures": {
    "classes": true,
    "modules": true,
    "jsx": true
  },

  "plugins": [
    "import"
  ],

  "rules": {
    "import/default": 2
  }

}

eslint ./index.js

/Users/james/demo/index.js
  1:8  error  No default export found in module  import/default

@benmosher
Copy link
Member

Ah, yeah, you have to configure the parser for JSX. It only parses spec ES6 by default.

If you look at the config/es7-jsx shared config, you can see how to configure it; or you can just extends: "import/es7-jsx" if you install the config package. (eslint-config-import)

@benmosher
Copy link
Member

Actually, I'll take another look and see if I can read the ecmaFeatures from inside the plugin and avoid explicit config on the dependency parser.

@benmosher benmosher reopened this Nov 7, 2015
@benmosher benmosher changed the title default rule doesn't work with functions Parser settings don't respect ecmaFeatures: jsx Nov 8, 2015
@benmosher
Copy link
Member

Yep, plugin context includes ecmaFeatures. I will make the parser sensitive to jsx defined there.

I think I may actually use an es7 flag there too. Or just feed whatever is there to the parser. Seems obvious, in retrospect. 😅

@benmosher benmosher changed the title Parser settings don't respect ecmaFeatures: jsx Dependency parser doesn't respect ecmaFeatures Nov 8, 2015
@benmosher benmosher added this to the 0.10.0 milestone Nov 8, 2015
@jameslnewell
Copy link
Contributor Author

Awesome!

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