![](/img/trans.png)
[英]create-react-app eslint error "Parsing error: 'import' and 'export' may appear only with 'sourceType: module'"
[英]ESLint only target a specific directory (eslintrc, create-react-app)
我有一個類似於這樣的文件夾結構:
/root
.eslintrc.json
package.json
/someFolder
/sub
/sub
/anotherFolder
/src
/containers
/components
/oneMoreFolder
/sub
/sub
我正在使用 create-react-app 並正在應用 airbnb 規則。 我已經能夠從 CLI 輕松地在特定文件夾中運行 linter,但在編譯時,它針對所有文件夾。
我只想在/src文件夾中的文件上運行 linter 編譯。
我該怎么辦? 我嘗試了多種解決方案。
謝謝!
TL:DR 使用 eslint 和 create-react-app 時,如何僅針對一個子文件夾及其所有文件進行編譯?
在你的.eslintrc.json
里面
{
"rules": {
"quotes": [ 2, "double" ]
},
"overrides": [
{
"files": [ "src/**/*.js" ],
"rules": {
"quotes": [ 2, "single" ]
}
}
]
}
在.eslintignore
/someFolder
/anotherFolder
/oneMoreFolder
你需要做一些類似eslint src/**/*.js[x]
事情。 如果您正在運行執行 linting 檢查的 webpack 構建(或預提交鈎子),則將其添加到package.json
的scripts
對象中。
我使用了ignorePatterns
選項。 它會告訴 ESLint 忽略特定的文件和目錄。 當您的 IDE(例如 VS Code)報告不需要的文件中的錯誤時,它很有用。
{
"ignorePatterns": ["gulpfile.js", "gulp/**/*", "webpack.config.js"]
}
您也可以使用.eslintignore
文件。
在您編寫腳本以在package.json
運行 lint 的地方,只提到了您想要定位的文件夾
scripts:{"lint": "eslint src public"}
那么如果你想忽略相應文件夾中的某些類型的文件,你可以在 ESLint 配置文件中提及。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.