6

Help to run eslint in create react app.

I created react app with tutorial

Then I installed

babel-eslint

standard

snazzy

and then I added to script in package.json next line

"lint": "standart --verbose | snazzy"

and now I tried to run eslint with command: npm run lint

but I have an error Parsing error: Unexpected token = null

My full package.json is below

{
  "name": "square_app_react",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-scripts": "1.0.10"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "lint": "standart --verbose | snazzy"
  },
  "devDependencies": {
    "babel-eslint": "^7.2.3",
    "standard": "^10.0.2"
  }
}

Please help to understand how to fix it or how to correct run eslint in my situation.

Thank you in advance.

4 Answers 4

9

I added this following script to scripts in package.json:

"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
4

Your spelling is off in your package.json script. It should be:

"lint": "standard --verbose | snazzy"

You also need to configure standard to use babel-eslint. Make sure to add this to your package.json.

{
  "standard": {
    "parser": "babel-eslint"
  }
}
7
  • the same result, did not help Commented Jul 13, 2017 at 20:24
  • You also need to install snazzy
    – EJ Mason
    Commented Jul 13, 2017 at 20:30
  • Ah, there is one more thing to add to your package.json. It needs this: { "standard": { "parser": "babel-eslint" } }
    – EJ Mason
    Commented Jul 13, 2017 at 20:33
  • awesome, you saved my time for sleep) Commented Jul 13, 2017 at 20:35
  • 1
    try "standard --fix". In the docs it says this will format everything for you. Another thing to try is using a standard plugin in your text editor.
    – EJ Mason
    Commented Jul 13, 2017 at 20:51
4

To run EsLint inside src folder:

./node_modules/react-scripts/node_modules/.bin/eslint src
2
  • 2
    Is there a way to run eslint not from node_modules? I have a CRA project where it can be run like this but cannot figure out how it was set up this way. Commented Jun 1, 2020 at 12:03
  • @lazy.lizard Just use the path to your eslint binary followed by src.
    – shivangg
    Commented Nov 23, 2020 at 11:46
0

Recent React scripts (version 5 at least, it appears) install eslint directly, so you can add the following line to the "scripts" section of package.json:

"lint": "eslint .",

(Omitting the dot causes eslint not to do anything.)

1
  • 1
    That does not lint anything, you need to define what to run on, like tal952 does Commented Jan 4, 2023 at 8:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.