0
我需要爲ESLint編寫自定義規則來檢查某人是否使用某些代碼結構。我是ESLint的新手,在註冊規則時遇到了一些問題,所以我實際上可以在.eslintrc
配置文件中使用它。規則本身看起來如下:ESLint無法識別的自定義規則
一些定製-rule.js
'use strict';
module.exports = function(context) {
function applyRule(node) {
// some logic
}
return {
"Identifier": applyRule
}
};
module.exports.schema = [];
然後,我有以下配置文件:
.eslintrc
{
"ecmaFeatures": {
"blockBindings": true,
"forOf": true,
"modules": true,
"arrowFunctions": true,
"classes": true
},
"rules": {
"semi": 2,
"some-custom-rule": 2
},
"env": {
"es6": true,
"browser": true
}
}
當我嘗試使用Gulp任務執行ESLint時,彈出以下錯誤:1:1 error Definition for rule 'some-custom-rule' was not found
。我認爲這是因爲我沒有正確要求規則。
吞氣任務如下:
var gulp = require('gulp');
var path = require('path');
var conf = require('./conf');
var eslint = require('gulp-eslint');
var rule = require('./rules/some-custom-rule');
gulp.task('eslint', function() {
return gulp.src(path.join(conf.paths.src, '**/*.js'))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
我怎樣才能讓我使用自定義規則的?我必須將它傳遞給ESLint嗎?提前致謝!
以下是信息:http://eslint.org/docs/developer-guide/working-with-plugins – Gyandeep