2015-09-05 32 views
0

這裏是我的lint任務:通配符不一飲而盡eslint正與JSX文件

gulp.task('lint', function(){ 
    gulp.src(fileString) 
    .pipe(eslint()) 
    .pipe(eslint.format()); 
}); 

如果fileString'js/**/*.js',它絨毛只是.js文件完全沒有問題。如果它是'js/components/**.jsx',那麼它完全正確地處理.jsx。但'js/**/*.jsx''js/**/*/.*{js,jsx}',它看到所有正確的文件,但沒有與他們。

這裏是我的/js目錄(一個反應項目):

├── stores 
│   └── heyStore.jsx 
├── models.js 
├── mixins.js 
├── data 
│   └── states.js 
├── config.js 
├── components 
│   ├── firstThing.jsx 
│   ├── aThing.jsx 
│   ├── whoaWhat.jsx 
│   └── nahYo.jsx 
├── app.jsx 
└── api 
    ├── prod.js 
    └── mock.js 

以防萬一,這裏是我的.eslintrc文件:

{ 
    "parser": "babel-eslint", 
    "plugins": [ 
    "react" 
    ], 
    "ecmaFeatures": { 
    "jsx": true, 
    "arrowFunctions": true, 
    "blockBindings": true, 
    "generators": true 
    }, 
    "rules": { 
    "strict": 0, 
    "no-underscore-dangle": 0, 
    "no-unused-vars": 0, 
    "curly": 0, 
    "no-multi-spaces": 0, 
    "key-spacing": 0, 
    "no-return-assign": 0, 
    "consistent-return": 0, 
    "no-shadow": 0, 
    "no-comma-dangle": 0, 
    "no-use-before-define": 0, 
    "no-empty": 0, 
    "new-parens": 0, 
    "no-cond-assign": 0, 
    "quotes": [2, "single", "avoid-escape"], 
    "camelcase": 0, 
    "semi": [2, "always"], 
    "new-cap": [1, { "capIsNew": false }], 
    "no-undef": 2 
    }, 
    "env": { 
    "browser": true, 
    "node": true 
    }, 
    "globals": { 
    } 
} 

回答

1

我找到了解決here

基本上我一飲而盡任務是這樣的:

gulp.task('lint', function(){ 
    gulp.src('js/**/*.{js,jsx}') 
    .pipe(eslint()) 
    .pipe(eslint.format()) 
    .on('data', function(file) { 
     if(file.eslint.messages && file.eslint.messages.length){ 
     gulp.fail = true; 
     } 
    }); 

}); 

process.on('exit', function() { 
    if (gulp.fail) { 
    process.exit(1); 
    } 
}); 

我爲什麼需要或雖爲什麼固定它,不知道。

0

輸入到gulp.src你可以提供一個數組globs。其實這個組合應該工作:[js/**/*.jsjs/**/*.jsx]。如果說只有js/components/**.jsx,也這是很不理想,使用你的作品:js/**/*.jsjs/components/**.jsxjs/**.jsxjs/stores/**.jsx]