Skip to content

Commit

Permalink
Merge pull request #6 from VicSolWang/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VicSolWang committed Dec 27, 2021
2 parents c3a00b1 + ef5b82c commit 4f4fbb9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

const config = require('./src/config');

config.rules['import/no-extraneous-dependencies'] = 'off';

module.exports = config;
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@
},
"homepage": "https://github.com/VicSolWang/eslint-config-wzx-react#readme",
"dependencies": {
"eslint": "^8.5.0",
"eslint-config-airbnb": "^19.0.2",
"eslint-config-airbnb-typescript": "^16.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-config-wzx": "^0.5.2",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0"
Expand Down
46 changes: 25 additions & 21 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@
* Email: [email protected]
*/

const customRules = {
'global-require': 'warn',
'import/no-dynamic-require': 'warn',
const baseConfig = require('eslint-config-wzx');

const reactConfig = ['airbnb/hooks', 'plugin:react/jsx-runtime'];
const reactRules = {
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'no-bitwise': 'off',
'no-nested-ternary': 'off',
'no-script-url': 'warn',
'no-underscore-dangle': 'off',
};

const handleExtendsConfig = (extendsConfig = []) => {
const result = extendsConfig.map((item) =>
item.indexOf('airbnb') !== -1 ? item.replace(/[-/]base/g, '') : item,
);
result.splice(result.length - 1, 0, ...reactConfig);
return result;
};

const { overrides: defaultOverrides, ...defaultConfig } = baseConfig;
const config = {
extends: ['airbnb', 'airbnb/hooks', 'plugin:react/jsx-runtime', 'prettier'],
...defaultConfig,
extends: handleExtendsConfig(defaultConfig.extends),
plugins: ['react'],
rules: customRules,
rules: {
...defaultConfig.rules,
...reactRules,
},
};

try {
Expand All @@ -27,19 +37,13 @@ try {
require('@typescript-eslint/eslint-plugin');
config.overrides = [
{
files: ['*.ts', '*.tsx'],
extends: [
'airbnb',
'airbnb-typescript',
'airbnb/hooks',
'plugin:react/jsx-runtime',
'prettier',
],
parserOptions: {
project: './tsconfig.json',
},
...defaultOverrides[0],
extends: handleExtendsConfig(defaultOverrides[0].extends),
plugins: ['react'],
rules: customRules,
rules: {
...defaultOverrides[0].rules,
...reactRules,
},
},
];
} catch (err) {
Expand Down

0 comments on commit 4f4fbb9

Please sign in to comment.