ngjamesng / weatherWear

Based on the weather forecast, this app makes clothing suggestions based on the conditions. This connects to an API.
https://weatherwear.jamesng.dev/
2 stars 0 forks source link

Add eslint w/ airbnb styleguide and pre-commit #18

Open GroverW opened 4 years ago

GroverW commented 4 years ago

I thought this was super helpful and maybe worth scoping out. Since you're using React I think there's a bunch of plugins you might need.

Info on possible plugins: https://github.com/react-boilerplate/react-boilerplate/blob/master/package.json

But basically

  1. npm install --save-dev eslint@6.8.0 eslint-config-airbnb [ADD OTHER PLUGINS] I had issues with the latest version (hence @6.8.0), but you may not
  2. npm install --save-dev pre-commit
  3. in package.json - well, you can follow basically what they did in react-boilerplate, but an example:
    "scripts": {
    < ... other scripts >
    "eslint": "eslint --ignore-path .gitignore",
    "eslint:fix": "eslint --ignore-path .gitignore --fix",
    "lint": "npm run eslint -- . ",
    "lint:fix": "npm run eslint:fix -- . "
    },
    "pre-commit": [
    "lint:fix"
    ],
  4. create .eslintrc.json next to package.json. And the most basic config would be (but probably gotta follow react boilerplate):
    {
    "extends": [
        "airbnb"
    ]
    }
GroverW commented 4 years ago

Forgot to add - once you have the scripts setup you can do "npm run eslint -- . " to test. As far as I can tell you can't run eslint directly unless you have it installed globally, so you gotta setup a script.