[英]ESLint only target a specific directory (eslintrc, create-react-app)
I have a folder structure similar to this:我有一个类似于这样的文件夹结构:
/root
.eslintrc.json
package.json
/someFolder
/sub
/sub
/anotherFolder
/src
/containers
/components
/oneMoreFolder
/sub
/sub
I'm working with create-react-app and am applying airbnb rules.我正在使用 create-react-app 并正在应用 airbnb 规则。 I have been able to run the linter in a specific folder easily from the CLI but on compile, it targets ALL folders.
我已经能够从 CLI 轻松地在特定文件夹中运行 linter,但在编译时,它针对所有文件夹。
I want to run the linter on compile on just the files within the /src folder.我只想在/src文件夹中的文件上运行 linter 编译。
How can I go about this?我该怎么办? I've tried a number of solutions.
我尝试了多种解决方案。
Thank you!谢谢!
TL:DR How do I target just one subfolder and all of its files on compile when using eslint and create-react-app? TL:DR 使用 eslint 和 create-react-app 时,如何仅针对一个子文件夹及其所有文件进行编译?
inside your .eslintrc.json
在你的
.eslintrc.json
里面
{
"rules": {
"quotes": [ 2, "double" ]
},
"overrides": [
{
"files": [ "src/**/*.js" ],
"rules": {
"quotes": [ 2, "single" ]
}
}
]
}
in .eslintignore
在
.eslintignore
/someFolder
/anotherFolder
/oneMoreFolder
You need to do something like eslint src/**/*.js[x]
.你需要做一些类似
eslint src/**/*.js[x]
事情。 If you are running a webpack build(or precommit hook) that does linting check then add it within the scripts
object inside package.json
.如果您正在运行执行 linting 检查的 webpack 构建(或预提交钩子),则将其添加到
package.json
的scripts
对象中。
I used ignorePatterns
option.我使用了
ignorePatterns
选项。 It'll tell ESLint to ignore specific files and directories.它会告诉 ESLint 忽略特定的文件和目录。 It's useful when your IDE (ex. VS Code) is reporting errors in unwanted files.
当您的 IDE(例如 VS Code)报告不需要的文件中的错误时,它很有用。
{
"ignorePatterns": ["gulpfile.js", "gulp/**/*", "webpack.config.js"]
}
You can Also use the .eslintignore
file.您也可以使用
.eslintignore
文件。
Where you have written the script to run lint in package.json
, there only mention the folders you want to target在您编写脚本以在
package.json
运行 lint 的地方,只提到了您想要定位的文件夹
scripts:{"lint": "eslint src public"}
Then if you want to ignore some type of files in the respective folders, you can mention in ESLint config file.那么如果你想忽略相应文件夹中的某些类型的文件,你可以在 ESLint 配置文件中提及。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.