Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Last active February 5, 2021 07:19
Show Gist options
  • Save tangoabcdelta/4ec738ef8abc560c2e1328acd841e9ac to your computer and use it in GitHub Desktop.
Save tangoabcdelta/4ec738ef8abc560c2e1328acd841e9ac to your computer and use it in GitHub Desktop.
If you're working on a React App with thousands of eslint warnings, first run prettier from the command line and prettify all files in a repository. It makes the hunting down easier for you (as a human, does do no benefit for the machine). Then, follow the instruction in the part of the gist, add them to your `package.json` and run them to fix `…
  • Prettify all JavaScript files: npx prettier --write "./src/**/*.js"

  • Check if your files are formatted: `npx prettier --check "src/**/*.js"

  • For more: https://prettier.io/docs/en/cli.html#--check

  • Simple commands: npx eslint --fix

  • Somewhat complicated command: npx eslint --fix --ext .js,.jsx .

Add these to the root package.json.

"scripts": {
  "lint": "eslint --fix --ext .js,.jsx .",
  "lint:scss": "stylelint 'src/**/*.scss' --syntax scss",
  "lint:scss:fix": "stylelint 'src/**/*.scss' --syntax scss --fix",
  "lint:js": "eslint . --ext .js,.jsx",
  "lint:js:fix": "npm run lint:js -- --fix",
}
"lint-staged": {
  "src/**/*.{js,jsx}": [
    "eslint . --fix", "git add"
  ],
  "src/**/*.scss": [
    "stylelint --syntax scss --fix", "git add"
  ],
},
"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment