Detects it.only in specs on commit (example)
How to stop committing test files with it.only
in BDD tests?
- Use eslint with whatever rules you want
- Add eslint-plugin-no-only-tests and maybe set it as a warning by default
{
"plugins": [
"no-only-tests"
],
"rules": {
"no-only-tests/no-only-tests": 1
}
}
- Use husky and lint-staged to grab changed files before commit
- Enable "no-only-tests" rule in the
lint-staged
command from command line using eslint --rule to enable the rule. Thepackage.json
should define a script name invoked by the linter
"scripts": {
"test": "eslint src/*.js",
"precommit-lint": "eslint --fix --rule 'no-only-tests/no-only-tests: 2'",
"precommit": "lint-staged"
},
"lint-staged": {
"src/*.js": ["precommit-lint", "git add"],
"verbose": false
}
Try committing JS file with it.only
block and it reports and error
$ git commit -m "try commit"
> husky - npm run -s precommit
> husky - node v6.8.1
❯ Running tasks for src/*.js
✖ precommit-lint
git add
↓ Running tasks for verbose [skipped]
→ No staged files match verbose
🚫 precommit-lint found some errors. Please fix them and try committing again.
/Users/git/detect-only-in-specs/src/foo-spec.js
2:6 error it.only not permitted no-only-tests/no-only-tests
✖ 1 problem (1 error, 0 warnings)
> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'