Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  74] [ 5]  / answers: 1 / hits: 121008  / 7 Years ago, sun, march 26, 2017, 12:00:00

I've installed eslint-config-airbnb that is supposed to pre configure ESLINT for React:




Our default export contains all of our ESLint rules, including
ECMAScript 6+ and React. It requires eslint, eslint-plugin-import,
eslint-plugin-react, and eslint-plugin-jsx-a11y.




My .eslintrc extending its configuration:



{ extends: eslint-config-airbnb,
env: {
browser: true,
node: true,
mocha: true
},
rules: {
new-cap: [2, { capIsNewExceptions: [List, Map, Set] }],
react/no-multi-comp: 0,
import/default: 0,
import/no-duplicates: 0,
import/named: 0,
import/namespace: 0,
import/no-unresolved: 0,
import/no-named-as-default: 2,
comma-dangle: 0, // not sure why airbnb turned this on. gross!
indent: [2, 2, {SwitchCase: 1}],
no-console: 0,
no-alert: 0,
linebreak-style: 0
},
plugins: [
react, import
],
settings: {
import/parser: babel-eslint,
import/resolve: {
moduleDirectory: [node_modules, src]
}
},
globals: {
__DEVELOPMENT__: true,
__CLIENT__: true,
__SERVER__: true,
__DISABLE_SSR__: true,
__DEVTOOLS__: true,
socket: true,
webpackIsomorphicTools: true
}
}


Unfortunatelly I'm getting the following error when linting a .js file with React JSX code inside it:



 error  JSX not allowed in files with extension '.js'              react/jsx-filename-extension


Wasn't eslint-config-airbnb configured react to support JSX already, as stated ?



What should be done to remove that error ?


More From » reactjs

 Answers
33

Either change your file extensions to .jsx as mentioned or disable the jsx-filename-extension rule. You can add the following to your config to allow .js extensions for JSX.



rules: {
react/jsx-filename-extension: [1, { extensions: [.js, .jsx] }],
}

[#58380] Friday, March 24, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
claudiofredye

Total Points: 583
Total Questions: 101
Total Answers: 115

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;