eslint-config-mgz 1.0.8 → 1.0.9

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.
Files changed (3) hide show
  1. package/flat-config.js +107 -73
  2. package/package.json +2 -2
  3. package/index.js +0 -27
package/flat-config.js CHANGED
@@ -1,80 +1,114 @@
1
1
  // eslint-config-mgz/flat-config.js
2
- import { configs as jsConfigs } from "@eslint/js";
3
- import tsPlugin from "@typescript-eslint/eslint-plugin";
4
- import tsParser from "@typescript-eslint/parser";
5
- import reactPlugin from "eslint-plugin-react";
6
- import reactHooksPlugin from "eslint-plugin-react-hooks";
7
- import importPlugin from "eslint-plugin-import";
8
- import jsxA11yPlugin from "eslint-plugin-jsx-a11y";
2
+ /**
3
+ * Universal ESLint config for projects using TypeScript + React
4
+ * Works with ESLint v7, v8 (FlatCompat) and ESLint v9+ (native flat config)
5
+ */
9
6
 
10
- export default [
11
- // Игнорируем лишние файлы
12
- {
13
- ignores: [
14
- "dist/**",
15
- "build/**",
16
- "node_modules/**",
17
- ".eslintrc.*",
18
- ".prettierrc.*",
19
- "eslint.config.*",
20
- ],
21
- },
7
+ function isEslintV9Plus() {
8
+ try {
9
+ require.resolve("@eslint/js"); // ESLint v9+ package
10
+ return true;
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
22
15
 
23
- // Базовые правила ESLint
24
- jsConfigs.recommended,
16
+ let config;
25
17
 
26
- // TypeScript rules
27
- {
28
- files: ["**/*.{ts,tsx}"],
29
- languageOptions: {
30
- parser: tsParser,
31
- parserOptions: {
32
- project: "./tsconfig.json",
33
- ecmaVersion: "latest",
34
- sourceType: "module",
35
- },
36
- },
37
- rules: {
38
- ...tsPlugin.configs.recommended.rules,
39
- "@typescript-eslint/no-unused-vars": "warn",
40
- "@typescript-eslint/no-explicit-any": "warn",
41
- "@typescript-eslint/prefer-const": "error",
42
- },
43
- },
18
+ if (isEslintV9Plus()) {
19
+ // ESLint v9+ flat config
20
+ const { flat } = require("@eslint/js");
21
+ const tseslint = require("typescript-eslint");
22
+ const reactPlugin = require("eslint-plugin-react");
23
+ const reactHooks = require("eslint-plugin-react-hooks");
24
+ const importPlugin = require("eslint-plugin-import");
25
+ const jsxA11y = require("eslint-plugin-jsx-a11y");
44
26
 
45
- // React rules
46
- {
47
- files: ["**/*.{jsx,tsx}"],
48
- plugins: {
49
- react: reactPlugin,
50
- "react-hooks": reactHooksPlugin,
51
- import: importPlugin,
52
- "jsx-a11y": jsxA11yPlugin,
53
- },
54
- rules: {
55
- "react/react-in-jsx-scope": "off",
56
- "react/prop-types": "off",
57
- "react/display-name": "off",
58
- "react/no-array-index-key": "warn",
59
- "react-hooks/rules-of-hooks": "error",
60
- "react-hooks/exhaustive-deps": "warn",
61
- "import/no-unresolved": "off",
62
- "import/named": "off",
63
- "jsx-a11y/no-autofocus": "off",
64
- "jsx-a11y/anchor-has-content": "off",
65
- "jsx-a11y/heading-has-content": "off",
66
- "no-alert": "error",
67
- "no-console": "error",
68
- "no-undef-init": "error",
69
- "no-undefined": "error",
70
- "no-var": "error",
71
- "no-inline-comments": "off",
72
- "no-use-before-define": "off",
73
- "no-duplicate-imports": "warn",
74
- "react/no-unknown-property": [
75
- "error",
76
- { ignore: ["cmdk-input-wrapper", "cmdk-empty"] },
27
+ config = [
28
+ {
29
+ ignores: [
30
+ "dist/**",
31
+ "build/**",
32
+ "node_modules/**",
33
+ ".eslintrc.*",
34
+ ".prettierrc.*",
35
+ "eslint.config.*",
77
36
  ],
78
37
  },
79
- },
80
- ];
38
+ flat.configs.recommended,
39
+ ...tseslint.configs.recommended,
40
+ {
41
+ files: ["**/*.{ts,tsx,js,jsx}"],
42
+ languageOptions: {
43
+ parser: tseslint.parser,
44
+ parserOptions: {
45
+ project: "./tsconfig.json",
46
+ ecmaVersion: "latest",
47
+ sourceType: "module",
48
+ },
49
+ },
50
+ plugins: {
51
+ "@typescript-eslint": tseslint.plugin,
52
+ react: reactPlugin,
53
+ "react-hooks": reactHooks,
54
+ import: importPlugin,
55
+ "jsx-a11y": jsxA11y,
56
+ },
57
+ rules: {
58
+ // General rules
59
+ "no-alert": "error",
60
+ "no-console": "error",
61
+ "no-undef-init": "error",
62
+ "no-undefined": "error",
63
+ "no-var": "error",
64
+ "no-inline-comments": "off",
65
+ "no-use-before-define": "off",
66
+ "no-duplicate-imports": "warn",
67
+
68
+ // TypeScript
69
+ "@typescript-eslint/no-unused-vars": "warn",
70
+ "@typescript-eslint/no-explicit-any": "warn",
71
+ "@typescript-eslint/prefer-const": "error",
72
+
73
+ // React
74
+ "react/react-in-jsx-scope": "off",
75
+ "react/display-name": "off",
76
+ "react/prop-types": "off",
77
+ "react/no-array-index-key": "warn",
78
+
79
+ // React Hooks
80
+ "react-hooks/rules-of-hooks": "error",
81
+ "react-hooks/exhaustive-deps": "warn",
82
+
83
+ // Import plugin
84
+ "import/no-unresolved": "off",
85
+ "import/named": "off",
86
+
87
+ // JSX A11y
88
+ "jsx-a11y/no-autofocus": "off",
89
+ "jsx-a11y/anchor-has-content": "off",
90
+ "jsx-a11y/heading-has-content": "off",
91
+
92
+ // Custom unknown props
93
+ "react/no-unknown-property": [
94
+ "error",
95
+ { ignore: ["cmdk-input-wrapper", "cmdk-empty"] },
96
+ ],
97
+ },
98
+ },
99
+ ];
100
+ } else {
101
+ // ESLint v7-8 - legacy config with FlatCompat
102
+ const { FlatCompat } = require("@eslint/eslintrc");
103
+ const baseConfig = require("./base");
104
+
105
+ const compat = new FlatCompat({
106
+ baseDirectory: __dirname,
107
+ recommendedConfig: require("eslint/conf/eslint-recommended"),
108
+ resolvePluginsRelativeTo: __dirname,
109
+ });
110
+
111
+ config = compat.config(baseConfig);
112
+ }
113
+
114
+ module.exports = config;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-config-mgz",
3
- "version": "1.0.8",
4
- "main": "index.js",
3
+ "version": "1.0.9",
4
+ "main": "flat-config.js",
5
5
  "type": "commonjs",
6
6
  "peerDependencies": {
7
7
  "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0",
package/index.js DELETED
@@ -1,27 +0,0 @@
1
- // eslint-config-mgz/index.js
2
- function isEslintV9Plus() {
3
- try {
4
- require.resolve("@eslint/js");
5
- return true;
6
- } catch {
7
- return false;
8
- }
9
- }
10
-
11
- let config;
12
-
13
- if (isEslintV9Plus()) {
14
- config = require("./flat-config").default;
15
- } else {
16
- const { FlatCompat } = require("@eslint/eslintrc");
17
- const baseConfig = require("./base");
18
-
19
- const compat = new FlatCompat({
20
- baseDirectory: __dirname,
21
- resolvePluginsRelativeTo: __dirname,
22
- });
23
-
24
- config = compat.config(baseConfig);
25
- }
26
-
27
- module.exports = config;