admin管理员组文章数量:1201413
How to set the folder to lint in the .eslintrc.json
file, instead after the eslint
command in package.json
.
package.json (snippet)
"scripts: {
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
}
I want only:
"scripts: {
"lint": "eslint",
}
and define the path and ext in the .eslintrc.json
.
Alternativ, set .eslintignore
to ignore ALL
but not ./src
.
I only want to lint the src-folder. Not the root.
Also for the eslint
plugin of vscode
.
My current solution:
.eslintignore
/*
!/src
But I wondering, why is there no option in the config files to set the folder/s to lint. I'm looking for the most common and elegant solution. Maybe it sounds like a duplicate here. But I searched a lot of topics and found nothing similar to solve my problem.
How to set the folder to lint in the .eslintrc.json
file, instead after the eslint
command in package.json
.
package.json (snippet)
"scripts: {
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
}
I want only:
"scripts: {
"lint": "eslint",
}
and define the path and ext in the .eslintrc.json
.
Alternativ, set .eslintignore
to ignore ALL
but not ./src
.
I only want to lint the src-folder. Not the root.
Also for the eslint
plugin of vscode
.
My current solution:
.eslintignore
/*
!/src
But I wondering, why is there no option in the config files to set the folder/s to lint. I'm looking for the most common and elegant solution. Maybe it sounds like a duplicate here. But I searched a lot of topics and found nothing similar to solve my problem.
Share Improve this question edited May 11, 2020 at 1:09 Siluck asked May 11, 2020 at 0:41 SiluckSiluck 1511 gold badge1 silver badge4 bronze badges 1- 3 Your solution with eslintignore is the best I have found so far, thank you! – Renato Commented May 4, 2022 at 15:21
3 Answers
Reset to default 12I've adapted your solution with the .eslintignore
file and put the rules directly into my config file's ignorePatterns
option (.eslintrc.cjs
in my case). Works like a charm for me:
module.exports = {
ignorePatterns: ['/*', '!/src']
[...]
}
Set in overrides inside .eslintrc.json
If you specified directories with CLI (e.g., eslint lib), ESLint searches target files in the directory to lint. The target files are *.js or the files that match any of overrides entries (but exclude entries that are any of files end with *).
{
"rules": {
"quotes": ["error", "double"]
},
"overrides": [
{
"files": ["bin/*.js", "lib/*.js"],
"excludedFiles": "*.test.js",
"rules": {
"quotes": ["error", "single"]
}
}
]
}
Refer: document of Configuring ESLint
In addition to @billythetalented's comment I had to add a dot in the package.json:
"scripts": {
"lint": "eslint .",
...
}
Otherwise, It didn't lint anything
本文标签: javascriptESLint define folder in config file (Ignore all butInclude only)Stack Overflow
版权声明:本文标题:javascript - ESLint define folder in config file. (Ignore all but..., Include only...) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738551180a2097404.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论