eslint-config-gorgon 1.2.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -16
- package/package.json +24 -10
- package/src/configs/base.ts +12 -0
- package/src/configs/import.ts +22 -0
- package/src/configs/index.tsx +6 -0
- package/src/configs/jsx-a11y.ts +5 -0
- package/src/configs/prettier.ts +4 -0
- package/src/configs/tailwind.ts +3 -0
- package/src/configs/typescript.ts +7 -0
- package/src/constants.ts +9 -0
- package/src/index.ts +52 -0
- package/src/rules/react.ts +8 -0
- package/src/types.d.ts +5 -0
- package/src/utils/check-react.ts +17 -0
- package/src/utils/check-tailwindcss.ts +17 -0
- package/src/utils/check-typescript.ts +8 -0
- package/src/constants.js +0 -13
- package/src/index.js +0 -20
- package/src/rules/base.js +0 -14
- package/src/rules/imports.js +0 -11
- package/src/rules/prettier.js +0 -6
- package/src/rules/react.js +0 -13
- package/src/rules/tailwind.js +0 -6
- package/src/rules/typescript.js +0 -12
- package/src/utils/check-react.js +0 -16
- package/src/utils/check-tailwindcss.js +0 -17
- package/src/utils/check-typescript.js +0 -8
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
> [!IMPORTANT]
|
|
2
|
+
> This package is not ready yet.
|
|
3
|
+
|
|
1
4
|
### Why
|
|
2
5
|
|
|
3
6
|
this package include prettier and eslint in one extends.
|
|
@@ -7,28 +10,33 @@ you can eazy use it.
|
|
|
7
10
|
### Install
|
|
8
11
|
|
|
9
12
|
```zsh
|
|
10
|
-
pnpm i -D eslint-config-
|
|
13
|
+
pnpm i -D eslint-config-gorgon
|
|
11
14
|
```
|
|
12
15
|
|
|
13
16
|
### Start
|
|
14
17
|
|
|
15
|
-
in your
|
|
18
|
+
in your eslint config file
|
|
16
19
|
|
|
17
|
-
`.
|
|
20
|
+
`.eslint.config.mjs`
|
|
18
21
|
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
```js
|
|
23
|
+
import gorgon from 'eslint-config-gorgon';
|
|
24
|
+
export default gorgon;
|
|
25
|
+
// or
|
|
26
|
+
import { init } from 'eslint-config-gorgon';
|
|
27
|
+
export default init();
|
|
23
28
|
```
|
|
24
29
|
|
|
30
|
+
### VsCode Setting (Optional)
|
|
25
31
|
`./vscode/settings.json`
|
|
26
32
|
|
|
27
33
|
```json
|
|
28
34
|
{
|
|
29
|
-
"
|
|
35
|
+
"prettier.enable": false,
|
|
36
|
+
"editor.formatOnSave": false,
|
|
30
37
|
"editor.codeActionsOnSave": {
|
|
31
|
-
"source.fixAll.eslint":
|
|
38
|
+
"source.fixAll.eslint": "explicit",
|
|
39
|
+
"source.organizeImports": "never"
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
```
|
|
@@ -36,12 +44,8 @@ in your eslintrc file
|
|
|
36
44
|
`./vscode/extensions.json`
|
|
37
45
|
|
|
38
46
|
```json
|
|
39
|
-
|
|
40
47
|
{
|
|
41
|
-
"recommendations": [
|
|
42
|
-
"dbaeumer.vscode-eslint",
|
|
43
|
-
"rvest.vs-code-prettier-eslint"
|
|
44
|
-
]
|
|
48
|
+
"recommendations": ["dbaeumer.vscode-eslint"]
|
|
45
49
|
}
|
|
46
50
|
```
|
|
47
51
|
|
|
@@ -49,11 +53,11 @@ in your eslintrc file
|
|
|
49
53
|
|
|
50
54
|
[using-a-shareable-configuration-package](https://eslint.org/docs/latest/use/configure/configuration-files#using-a-shareable-configuration-package)
|
|
51
55
|
|
|
52
|
-
### Desc
|
|
56
|
+
<!-- ### Desc
|
|
53
57
|
|
|
54
58
|
> just collect recommended eslint, no more custom rules.
|
|
55
59
|
|
|
56
60
|
- eslint
|
|
57
61
|
- typescript
|
|
58
62
|
- react
|
|
59
|
-
- prettier
|
|
63
|
+
- prettier -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-gorgon",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "src/index.js",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"keywords": [
|
|
@@ -11,20 +12,33 @@
|
|
|
11
12
|
"src/*"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"@typescript-eslint/parser": "^7.3.1",
|
|
16
|
-
"eslint-config-prettier": "^9.1.0",
|
|
17
|
-
"eslint-plugin-import": "^2.29.1",
|
|
15
|
+
"eslint-plugin-import": "^2.30.0",
|
|
18
16
|
"eslint-plugin-jsx-a11y": "^6.9.0",
|
|
19
|
-
"eslint-plugin-perfectionist": "^3.
|
|
17
|
+
"eslint-plugin-perfectionist": "^3.3.0",
|
|
20
18
|
"eslint-plugin-prettier": "^5.2.1",
|
|
21
|
-
"eslint-plugin-react": "^7.35.
|
|
19
|
+
"eslint-plugin-react": "^7.35.1",
|
|
22
20
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
23
|
-
"eslint-plugin-tailwindcss": "^3.17.4"
|
|
21
|
+
"eslint-plugin-tailwindcss": "^3.17.4",
|
|
22
|
+
"fast-glob": "^3.3.2",
|
|
23
|
+
"ignore": "^5.3.2",
|
|
24
|
+
"prettier": "^3.3.3",
|
|
25
|
+
"typescript-eslint": "^8.4.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"eslint": "^
|
|
27
|
-
"prettier": "^
|
|
28
|
+
"@eslint/js": "^9.9.1",
|
|
29
|
+
"@types/eslint-config-prettier": "^6.11.3",
|
|
30
|
+
"@types/eslint-plugin-jsx-a11y": "^6.9.0",
|
|
31
|
+
"@types/eslint-plugin-tailwindcss": "^3.17.0",
|
|
32
|
+
"@types/eslint__js": "^8.42.3",
|
|
33
|
+
"@types/node": "^22.5.2",
|
|
34
|
+
"eslint": "^9.9.1",
|
|
35
|
+
"tsup": "^8.2.4",
|
|
28
36
|
"typescript": "^5.5.4"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"lint": "npx eslint",
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"build:watch": "tsup --watch",
|
|
42
|
+
"dev": "npm run build && npm run lint"
|
|
29
43
|
}
|
|
30
44
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import perfectionist from "eslint-plugin-perfectionist";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
perfectionist.configs["recommended-natural"],
|
|
5
|
+
{
|
|
6
|
+
rules: {
|
|
7
|
+
"no-console": "warn", // handle console
|
|
8
|
+
"no-unused-vars": "warn", // unused
|
|
9
|
+
"perfectionist/sort-enums": "warn", // sort enums
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import importPlugin from "eslint-plugin-import";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
{
|
|
5
|
+
plugins: { import: importPlugin },
|
|
6
|
+
rules: {
|
|
7
|
+
"import/first": "error",
|
|
8
|
+
"import/newline-after-import": "error",
|
|
9
|
+
"import/no-duplicates": "error",
|
|
10
|
+
},
|
|
11
|
+
settings: {
|
|
12
|
+
// This will do the trick
|
|
13
|
+
"import/parsers": {
|
|
14
|
+
espree: [".js", ".cjs", ".mjs", ".jsx"],
|
|
15
|
+
},
|
|
16
|
+
"import/resolver": {
|
|
17
|
+
node: true,
|
|
18
|
+
typescript: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import checkHasReact from "./utils/check-react";
|
|
2
|
+
import checkHasTailwindcss from "./utils/check-tailwindcss";
|
|
3
|
+
import checkHasTypeScript from "./utils/check-typescript";
|
|
4
|
+
|
|
5
|
+
const hasReact = checkHasReact();
|
|
6
|
+
const hasTailwindcss = checkHasTailwindcss();
|
|
7
|
+
const hasTypeScript = checkHasTypeScript();
|
|
8
|
+
|
|
9
|
+
export { hasReact, hasTailwindcss, hasTypeScript };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TSESLint } from "@typescript-eslint/utils";
|
|
2
|
+
import type eslint from "eslint";
|
|
3
|
+
|
|
4
|
+
import tseslint from "typescript-eslint";
|
|
5
|
+
|
|
6
|
+
import base from "./configs/base";
|
|
7
|
+
import jsxA11y from "./configs/jsx-a11y";
|
|
8
|
+
// import _import from "./configs/import";
|
|
9
|
+
import prettier from "./configs/prettier";
|
|
10
|
+
import tailwind from "./configs/tailwind";
|
|
11
|
+
import { hasReact, hasTailwindcss, hasTypeScript } from "./constants";
|
|
12
|
+
|
|
13
|
+
const initialConfigs: eslint.Linter.Config[] = [...base];
|
|
14
|
+
|
|
15
|
+
type InitConfigProps = {
|
|
16
|
+
a11y?: boolean;
|
|
17
|
+
ignores?: string[];
|
|
18
|
+
prettier?: boolean;
|
|
19
|
+
react?: boolean;
|
|
20
|
+
tailwind?: boolean;
|
|
21
|
+
typescript?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type InitConfigReturnType = eslint.Linter.Config | TSESLint.FlatConfig.Config;
|
|
25
|
+
|
|
26
|
+
export const init = (configs?: InitConfigProps): InitConfigReturnType[] => {
|
|
27
|
+
let reasonConfigs: InitConfigReturnType[] = initialConfigs;
|
|
28
|
+
// 判断是否存在 a11y
|
|
29
|
+
if (configs?.a11y ?? hasReact) reasonConfigs.push(...jsxA11y);
|
|
30
|
+
// 判断是否存在 tailwindcss
|
|
31
|
+
if (configs?.tailwind ?? hasTailwindcss) reasonConfigs.push(...tailwind);
|
|
32
|
+
// 判断是否存在 prettier
|
|
33
|
+
if (configs?.prettier ?? hasReact) reasonConfigs.push(...prettier);
|
|
34
|
+
// 判断是否存在 typescript
|
|
35
|
+
if (configs?.typescript ?? hasTypeScript) {
|
|
36
|
+
const defaultIgnores = ["**/node_modules/**", "dist/**", "output/**"];
|
|
37
|
+
reasonConfigs = [...initialConfigs, ...tseslint.configs.recommended].map(
|
|
38
|
+
(config) => ({
|
|
39
|
+
...config,
|
|
40
|
+
files: [
|
|
41
|
+
"**/*.ts",
|
|
42
|
+
"**/*.tsx",
|
|
43
|
+
...(config?.files?.flat(Infinity) ?? []),
|
|
44
|
+
],
|
|
45
|
+
ignores: [...defaultIgnores, ...(configs?.ignores ?? [])],
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return reasonConfigs;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default initialConfigs;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// /** @type {import('eslint').Linter.Config} */
|
|
2
|
+
// export default {
|
|
3
|
+
// extends: ["plugin:react-hooks/recommended", "plugin:jsx-a11y/recommended"],
|
|
4
|
+
// plugins: ["react"],
|
|
5
|
+
// rules: {
|
|
6
|
+
// "react/self-closing-comp": "warn", // 要求没有子元素的组件使用自闭合标签
|
|
7
|
+
// },
|
|
8
|
+
// };
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
const checkHasReact = () => {
|
|
5
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
6
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
7
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
8
|
+
const dependencies = packageJson.dependencies || {};
|
|
9
|
+
const devDependencies = packageJson.devDependencies || {};
|
|
10
|
+
const isReactProject =
|
|
11
|
+
"react" in dependencies || "react" in devDependencies;
|
|
12
|
+
return isReactProject;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default checkHasReact;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
const checkHasTailwindcss = () => {
|
|
5
|
+
const possibleConfigFiles = [
|
|
6
|
+
"tailwind.config.js",
|
|
7
|
+
"tailwind.config.cjs",
|
|
8
|
+
"tailwind.config.mjs",
|
|
9
|
+
"tailwind.config.ts",
|
|
10
|
+
"tailwind.config.mts",
|
|
11
|
+
];
|
|
12
|
+
const configFileExists = possibleConfigFiles.some((file) =>
|
|
13
|
+
fs.existsSync(path.join(process.cwd(), file)),
|
|
14
|
+
);
|
|
15
|
+
return configFileExists;
|
|
16
|
+
};
|
|
17
|
+
export default checkHasTailwindcss;
|
package/src/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const checkHasTailwindcss = require("./utils/check-tailwindcss");
|
|
2
|
-
const checkHasReact = require("./utils/check-react");
|
|
3
|
-
const checkHasTypeScript = require("./utils/check-typescript");
|
|
4
|
-
|
|
5
|
-
const hasReact = checkHasReact();
|
|
6
|
-
const hasTailwindcss = checkHasTailwindcss();
|
|
7
|
-
const hasTypeScript = checkHasTypeScript();
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
hasReact,
|
|
11
|
-
hasTailwindcss,
|
|
12
|
-
hasTypeScript,
|
|
13
|
-
};
|
package/src/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const { hasReact, hasTailwindcss, hasTypeScript } = require("./constants");
|
|
2
|
-
|
|
3
|
-
const baseExtendsList = [
|
|
4
|
-
"/rules/base.js",
|
|
5
|
-
"/rules/imports.js",
|
|
6
|
-
"/rules/prettier.js",
|
|
7
|
-
];
|
|
8
|
-
|
|
9
|
-
if (hasReact) baseExtendsList.push("/rules/react.js");
|
|
10
|
-
if (hasTailwindcss) baseExtendsList.push("/rules/tailwind.js");
|
|
11
|
-
if (hasTypeScript) baseExtendsList.push("/rules/typescript.js");
|
|
12
|
-
|
|
13
|
-
const extendsList = baseExtendsList.map((item) => require.resolve(__dirname + item));
|
|
14
|
-
|
|
15
|
-
/** @type {import('eslint').Linter.Config} */
|
|
16
|
-
const config = {
|
|
17
|
-
extends: extendsList,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
module.exports = config;
|
package/src/rules/base.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** @type {import('eslint').Linter.Config} */
|
|
2
|
-
const config = {
|
|
3
|
-
extends: [
|
|
4
|
-
'plugin:perfectionist/recommended-natural-legacy',
|
|
5
|
-
// "plugin:perfectionist/recommended-alphabetical", // sort by alphabetical
|
|
6
|
-
],
|
|
7
|
-
plugins: ["perfectionist"],
|
|
8
|
-
rules: {
|
|
9
|
-
"no-console": "warn", // handle console
|
|
10
|
-
"perfectionist/sort-enums": "warn", // sort enums
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
module.exports = config;
|
package/src/rules/imports.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** @type {import('eslint').Linter.Config} */
|
|
2
|
-
const config = {
|
|
3
|
-
plugins: ["import"],
|
|
4
|
-
rules: {
|
|
5
|
-
// handle import
|
|
6
|
-
"import/first": "error",
|
|
7
|
-
"import/newline-after-import": "error",
|
|
8
|
-
"import/no-duplicates": "error",
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
module.exports = config;
|
package/src/rules/prettier.js
DELETED
package/src/rules/react.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** @type {import('eslint').Linter.Config} */
|
|
2
|
-
const config = {
|
|
3
|
-
extends: [
|
|
4
|
-
"plugin:react-hooks/recommended",
|
|
5
|
-
"plugin:jsx-a11y/recommended",
|
|
6
|
-
],
|
|
7
|
-
plugins: ["react"],
|
|
8
|
-
rules: {
|
|
9
|
-
"react/self-closing-comp": "warn", // 要求没有子元素的组件使用自闭合标签
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
module.exports = config;
|
package/src/rules/tailwind.js
DELETED
package/src/rules/typescript.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** @type {import('eslint').Linter.Config} */
|
|
2
|
-
const config = {
|
|
3
|
-
extends: ["plugin:@typescript-eslint/recommended"],
|
|
4
|
-
parser: "@typescript-eslint/parser",
|
|
5
|
-
plugins: ["@typescript-eslint"],
|
|
6
|
-
rules: {
|
|
7
|
-
"@typescript-eslint/no-explicit-any": "warn", // handle explicit any
|
|
8
|
-
"@typescript-eslint/no-shadow": "off", // handle shadow
|
|
9
|
-
"@typescript-eslint/no-unused-vars": "error", // handle unused
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
module.exports = config;
|
package/src/utils/check-react.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const checkHasReact = () => {
|
|
5
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
6
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
7
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
8
|
-
const dependencies = packageJson.dependencies || {};
|
|
9
|
-
const devDependencies = packageJson.devDependencies || {};
|
|
10
|
-
const isReactProject = 'react' in dependencies || 'react' in devDependencies;
|
|
11
|
-
return isReactProject;
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = checkHasReact;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const checkHasTailwindcss = () => {
|
|
5
|
-
const possibleConfigFiles = [
|
|
6
|
-
'tailwind.config.js',
|
|
7
|
-
'tailwind.config.cjs',
|
|
8
|
-
'tailwind.config.mjs',
|
|
9
|
-
'tailwind.config.ts',
|
|
10
|
-
'tailwind.config.mts',
|
|
11
|
-
];
|
|
12
|
-
const configFileExists = possibleConfigFiles.some(file =>
|
|
13
|
-
fs.existsSync(path.join(process.cwd(), file))
|
|
14
|
-
);
|
|
15
|
-
return configFileExists;
|
|
16
|
-
}
|
|
17
|
-
module.exports = checkHasTailwindcss;
|