Skip to content

Commit

Permalink
feat: 文件名黑名单设置,添加min.js/iconfont.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxudong13804 committed Jan 29, 2024
1 parent 983825b commit a0a290e
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 5 deletions.
16 changes: 13 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { ESLint } = require("eslint");
const LibRulesAndConfigs = require("../lib/index"); // lib定义的规则名称集
const supportFileExtNames = require("../lib/execConfigs/supportFileExtNames"); // 支持的文件类型名后缀集合
const BlackFilesList = require("../lib/execConfigs/BlackFilesList"); // 排除的路径集合
const FileIgnoredList = require("../lib/execConfigs/FileIgnoredList"); // 排除的文件集合

let targetPath = "";
let type = "";
Expand All @@ -22,7 +23,7 @@ function generateEslintInstances() {
const pathToConfigFile = require.resolve(`@afuteam/eslint-plugin-fe/lib/configs/${name}.js`);

// 禁止行内配置 allowInlineConfig
eslintInstances[name] = new ESLint({ overrideConfigFile: pathToConfigFile, useEslintrc: false, allowInlineConfig: allowInlineConfig });
eslintInstances[name] = new ESLint({ overrideConfigFile: pathToConfigFile, useEslintrc: false, allowInlineConfig: allowInlineConfig, });
}

}
Expand All @@ -39,16 +40,24 @@ function handleSelectWhichEslintInstances(type, eslintInstances) {
return eslintInstances[type] || "";
}

// TODO lintType 可能是多个,需要支持的,暂时不支持
// 判断文件名后缀是否在黑名单
function isFileIgnored(filePath) {
const fileName = path.basename(filePath);
return FileIgnoredList.some(blackName => fileName.endsWith(blackName));
}

// TODO lintType 暂不支持 多个,比如 Astro 类型的项目

async function lintFiles(filePaths) {

let totalErrors = 0;
let totalWarnings = 0;

for (const filePath of filePaths) {
const curFileIsIgnored = isFileIgnored(filePath);

const extName = path.extname(filePath).slice(1);
if (fileGroups[extName]) {
if (!curFileIsIgnored && fileGroups[extName]) {
fileGroups[extName].push(filePath);
}
}
Expand Down Expand Up @@ -87,6 +96,7 @@ async function lintFiles(filePaths) {
}

console.log('Total 排除目录列表:', BlackFilesList);
console.log('Total 排除文件名规:', FileIgnoredList);
console.log('Total 支持文件类型:', supportFileExtNames);

console.log('Total errors:', totalErrors);
Expand Down
2 changes: 1 addition & 1 deletion lib/configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ module.exports = {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
ignorePatterns: ['*.min.*'],
ignorePatterns: ['*.min.js', 'iconfont.js'],
}
5 changes: 4 additions & 1 deletion lib/configs/js.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const BaseOptions = require('./base.js');

module.exports = {
rules: {
'no-unused-vars': 1, // 非TS项目,此项需设为1
Expand Down Expand Up @@ -100,5 +102,6 @@ module.exports = {
"wrap-iife": 0,
"wrap-regex": 0,
"yield-star-spacing": 0
}
},
ignorePatterns: BaseOptions.ignorePatterns,
}
2 changes: 2 additions & 0 deletions lib/configs/react-ts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const BaseOptions = require("../base.js");

const JSRules = require("../js.js");

Expand Down Expand Up @@ -65,4 +66,5 @@ module.exports = {
'@typescript-eslint/prefer-namespace-keyword': 'off', // error -> off
'@typescript-eslint/triple-slash-reference': 'off', // error -> off
},
ignorePatterns: BaseOptions.ignorePatterns,
};
3 changes: 3 additions & 0 deletions lib/configs/ts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const BaseOptions = require("../base.js");
const JSRules = require("../js.js");

module.exports = {
Expand Down Expand Up @@ -46,4 +47,6 @@ module.exports = {
'@typescript-eslint/prefer-namespace-keyword': 'off', // error -> off
'@typescript-eslint/triple-slash-reference': 'off', // error -> off
},
ignorePatterns: BaseOptions.ignorePatterns,

};
2 changes: 2 additions & 0 deletions lib/configs/vue2-ts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const BaseOptions = require("../base.js");
const JSRules = require("../js.js");

module.exports = {
Expand Down Expand Up @@ -47,4 +48,5 @@ module.exports = {
'@typescript-eslint/prefer-namespace-keyword': 'off', // error -> off
'@typescript-eslint/triple-slash-reference': 'off', // error -> off
},
ignorePatterns: BaseOptions.ignorePatterns,
};
2 changes: 2 additions & 0 deletions lib/configs/vue3-ts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const BaseOptions = require("../base.js");
const JSRules = require("../js.js");

module.exports = {
Expand Down Expand Up @@ -51,4 +52,5 @@ module.exports = {
'@typescript-eslint/prefer-namespace-keyword': 'off', // error -> off
'@typescript-eslint/triple-slash-reference': 'off', // error -> off
},
ignorePatterns: BaseOptions.ignorePatterns,
};
5 changes: 5 additions & 0 deletions lib/execConfigs/FileIgnoredList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const FileIgnoredList = [
'min.js',
'iconfont.js'
]
module.exports = FileIgnoredList
1 change: 1 addition & 0 deletions tests/blackfile/a.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(kkkk)
3 changes: 3 additions & 0 deletions tests/blackfile/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log(qdii)

var unused_var = 1;
1 change: 1 addition & 0 deletions tests/blackfile/iconfont.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(yyy);

0 comments on commit a0a290e

Please sign in to comment.