0
"scripts": {
   "precommit": "pretty-quick --staged & npm run lint & npm run test",
   "lint": "eslint 'src/**/*.{js,jsx}' --quiet --fix",
   "test": "cross-env CI=true react-scripts test --env=jsdom --coverage"
}

enter image description here

Even after the failure of lint, the code gets committed. How to prevent this?

If i dont add cross-env CI=true, the jest test cases wont break. I am trying to perform for both linting and unit testing for clean code.

Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95

2 Answers2

-1

Just to be sure, did you installed any of this ?

And did you tried to use &&, like: "precommit": "pretty-quick --staged && npm run lint && npm run test",

If not, your lint failure are ignored I guess.

Blitz
  • 500
  • 3
  • 10
-2

Installed the prettier eslint dependencies such as:

"eslint-config-prettier": "^6.0.0",
"eslint-plugin-prettier": "^3.1.0",

Test script command retained:

"test": "cross-env CI=true react-scripts test --env=jsdom",

Adding husky for pre-commit and pre-push as below:

  "husky": {
     "hooks": {
     "pre-commit": "pretty-quick --staged && npm run linttest",
     "pre-push": "npm run linttest"
    }
  }

Commit will be successful with errors, but push fails. That is also fine for me now, so that my commits wont be blocked, but i can only push the clean code to repo.

enter image description here

.eslintrc configured as below:

{
  "settings": {
    "react": {
      "version": "latest"
    }
  },
  "parser": "babel-eslint",
  "extends": ["plugin:react/recommended", 
              "eslint:recommended", 
              "plugin:prettier/recommended"],
  "env": {
    "browser": true,
    "node": true,
    "jest": true
  }
}
Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95