2016-03-21 144 views
0

它看起來像我的.eslintrc文件中找不到我gulp-eslint咕嘟咕嘟eslint沒有找到我的.eslintrc文件

我定義了一個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錯誤的,這是罰款。

任何想法什麼是不正確的工作?

+0

你必須趕上吞嚥錯誤。 – Neal

回答

1

根據docs你需要失敗的管道錯誤。

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()); 
}); 
0

只是擡頭,在documentation是使用配置文件,其使用的優先級以及它們如何定位非常有用和簡潔。您還可以添加的路徑來指定配置文件的位置特定管道:

gulp.task('lint', function() { 
    gulp.src(['src/**/*.js', 'src/**/*.jsx']) 
    .pipe(eslint({ configFile: '.eslintrc'})) 
    .pipe(eslint.format()) 
    .pipe(eslint.failAfterError()) 
}) 

在吞氣,eslint documentation應該指出的是,failOnError()和failAfterError的使用()方法是不可取因爲任務/流被停止,因此沒有寫入輸出的無效代碼。

如果您不使用,那麼錯誤仍然會被捕獲,但僅在控制檯輸出中顯示。因此,依賴於您的任務流程和設計,目標文件仍然可以寫入,但您可以方便地立即糾正錯誤並繼續執行,而無需再次啓動管道處理/監視任務。另一種方法是查看gulp-plumber或其他一些方法,從而您不會突破一個吞噬觀察任務,同時也不會編寫包含未通過驗證驗證的代碼的文件。