是否可以使用 Husky + lint 阶段来检查 Console.logs?
Is it possible to use Husky + lint stages to check for Console.logs?
只是想知道是否可以在预提交期间使用 husky/lint 阶段检查控制台日志,如果有控制台日志则失败?我找不到任何特定于控制台日志的内容。
这将验证您的代码中是否有一些 console.log。
在你的 .eslintrc 中放这个人
"no-console": "error",
在 husky 文件中:
{
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "yarn test:coverage"
}
}
在我的vue项目中我是这样使用的。
eslintrc.js:
module.exports = {
extends: ['./.eslintrc.js'], // it contains other rules
rules: {
'no-console': 'error',
},
};
huskyrc.js:
module.exports = {
hooks: {
'pre-commit': 'lint-staged'
}
}
和包裹json:
"scripts": {
"lint:eslint": "eslint --ext .js,.vue --ignore-path .gitignore --ignore-path .eslintignore .",
},
"lint-staged": {
"*.{js,vue}": [
"npm run lint:eslint"
],
}
编辑:您还需要安装 "lint-staged"
包。
您可以通过两种方式完成:
- 在.eslintrc.js文件中:
module.exports = {
plugins: ["security"],
rules: {
"no-console": ENV === "production" ? "error" : "off",
"no-debugger": ENV === "production" ? "error" : "off"
}
}
- 在
.git/hooks/pre-commit
文件中:
你可以粘贴这段代码
https://gist.github.com/guilherme/9604324#file-gistfile1-sh
Difference is that you can commit *.eslintrc.js* file but *pre-commit* is only for you.
只是想知道是否可以在预提交期间使用 husky/lint 阶段检查控制台日志,如果有控制台日志则失败?我找不到任何特定于控制台日志的内容。
这将验证您的代码中是否有一些 console.log。
在你的 .eslintrc 中放这个人
"no-console": "error",
在 husky 文件中:
{
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "yarn test:coverage"
}
}
在我的vue项目中我是这样使用的。
eslintrc.js:
module.exports = {
extends: ['./.eslintrc.js'], // it contains other rules
rules: {
'no-console': 'error',
},
};
huskyrc.js:
module.exports = {
hooks: {
'pre-commit': 'lint-staged'
}
}
和包裹json:
"scripts": {
"lint:eslint": "eslint --ext .js,.vue --ignore-path .gitignore --ignore-path .eslintignore .",
},
"lint-staged": {
"*.{js,vue}": [
"npm run lint:eslint"
],
}
编辑:您还需要安装 "lint-staged"
包。
您可以通过两种方式完成:
- 在.eslintrc.js文件中:
module.exports = {
plugins: ["security"],
rules: {
"no-console": ENV === "production" ? "error" : "off",
"no-debugger": ENV === "production" ? "error" : "off"
}
}
- 在
.git/hooks/pre-commit
文件中:
你可以粘贴这段代码 https://gist.github.com/guilherme/9604324#file-gistfile1-sh
Difference is that you can commit *.eslintrc.js* file but *pre-commit* is only for you.