[英]Gulp eslint doesn't find my .eslintrc file
看起來我的.eslintrc
文件沒有找到我gulp-eslint
我定義了一個lint
任務:
gulp.task('lint', function () {
gulp.src(['src/**/*.js', 'src/**/*.jsx'])
.pipe(eslint())
.pipe(eslint.format());
})
它運行但不顯示任何錯誤。
我的.eslintrc
文件在src
文件夾中定義。 我試圖將它移動到我的項目的根文件夾,但它沒有改變任何東西。
這是一個非常簡單的文件:
{
"parser": "babel-eslint",
"ecmaFeatures": {
"classes": true,
"jsx": true
},
"plugins": [
"react"
],
"extends": "eslint-config-airbnb"
}
當我在終端中運行eslint src
時,我收到了一堆 eslint 錯誤,這很好。
知道什么不能正常工作嗎?
根據文檔,您需要因管道中的錯誤而失敗。
gulp.task('lint', function () {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src(['**/*.js','!node_modules/**'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
提醒一下,該文檔對使用配置文件、它們的使用優先級以及它們的位置非常有用和簡潔。 您還可以添加路徑以指定特定管道的配置文件的位置:
gulp.task('lint', function () {
gulp.src(['src/**/*.js', 'src/**/*.jsx'])
.pipe(eslint({ configFile: '.eslintrc'}))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
在 gulp-eslint文檔中,應該注意的是,建議使用 failOnError() 和 failAfterError() 方法,因為任務/流已停止,因此沒有將無效代碼寫入輸出。
如果兩者都不使用,則錯誤仍會被捕獲,但僅顯示在控制台輸出中。 因此,取決於您的任務流程和設計,目標文件可能仍會被寫入,但您可以方便地立即糾正錯誤並繼續進行,而無需再次啟動管道處理/觀察任務。 另一種方法是研究gulp-plumber或其他一些方法,這樣您就不會中斷 gulp watch 任務,也不會編寫包含未通過 linting 驗證的代碼的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.