Skip to content

Commit

Permalink
fix: Fix the problem of always reporting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Dec 27, 2020
1 parent 7b90a7c commit afbff1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-unicorn": "^20.0.0",
"fast-glob": "^3.2.4",
"stylelint": "^13.7.0",
"stylelint-config-css-modules": "^2.2.0",
"stylelint-config-prettier": "^8.0.1",
Expand Down
24 changes: 22 additions & 2 deletions src/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ const parserOptions: {
project: './tsconfig.json',
};

const isJsMoreTs = async (path = 'src') => {
const fg = require('fast-glob');
const jsFiles = await fg(`${path}/src/**/*.{js,jsx}`, { deep: 3 });
const tsFiles = await fg(`${path}/src/**/*.{ts,tsx}`, { deep: 3 });
return jsFiles.length > tsFiles.length;
};

const configPath = path.join(__dirname, 'fabric.rc');
const isTsProject = fs.existsSync(path.join(process.cwd() || '.', './tsconfig.json'));

if (isTsProject) {
console.log('这是一个 TypeScript 项目,如果不是请删除 tsconfig.json');
if (!fs.existsSync(configPath)) {
isJsMoreTs(configPath).then((jsMoreTs) => {
fs.writeFileSync(configPath, new Date().getDate().toString());
if (!jsMoreTs) return;
console.log('这是一个 TypeScript 项目,如果不是请删除 tsconfig.json');
});
} else {
const cacheTime = fs.readFileSync(configPath).toString();
if (new Date().getDate() !== parseInt(cacheTime, 10)) {
fs.rmSync(configPath);
}
}
}

module.exports = {
extends: ['eslint-config-airbnb-base', 'prettier', 'prettier/react'].concat(
isTsProject ? ['prettier/@typescript-eslint', 'plugin:@typescript-eslint/recommended'] : [],
Expand Down Expand Up @@ -55,7 +75,7 @@ module.exports = {
'jsx-a11y/anchor-is-valid': 0,
'sort-imports': 0,
'class-methods-use-this': 0,
'no-confusing-arrow': 1,
'no-confusing-arrow': 0,
'linebreak-style': 0,
// Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins
'no-prototype-builtins': 'off',
Expand Down

0 comments on commit afbff1a

Please sign in to comment.