@ethang/eslint-config 19.0.11 → 19.1.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 CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  [View Config](https://eslint-config-ethang.pages.dev/rules)
4
4
 
5
- Do **NOT** use this with Prettier! Styling rules are included.
5
+ > [!CAUTION]
6
+ > Do not use this with Prettier! Styling rules are included.
6
7
 
7
- - 873 errored rules.
8
+ - 882 errored rules.
8
9
  - 289 rules from [eslint-plugin-sonarjs](https://github.com/SonarSource/SonarJS/blob/master/packages/jsts/src/rules/README.md)
9
10
  - 144 rules from [@eslint/js](https://github.com/eslint/eslint/tree/main/packages/js)
10
11
  - 113 rules from [sindresorhus/eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn)
@@ -15,8 +16,10 @@ Do **NOT** use this with Prettier! Styling rules are included.
15
16
  - 20 rules from [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n)
16
17
  - 19 rules from [eslint-plugin-perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist)
17
18
  - 7 rules from [eslint-plugin-tailwindcss](https://github.com/francoismassart/eslint-plugin-tailwindcss)
19
+ - 7 rules from [@eslint/markdown](https://github.com/eslint/markdown)
18
20
  - 4 rules from [eslint-plugin-barrel-files](https://github.com/thepassle/eslint-plugin-barrel-files)
19
21
  - 4 rules from [@tanstack/eslint-plugin-query](https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query)
22
+ - 2 rules from [@eslint/json](https://github.com/eslint/json)
20
23
  - 1 rule from [eslint-plugin-depend](https://github.com/es-tooling/eslint-plugin-depend/tree/main)
21
24
  - 1 rule from [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat)
22
25
 
@@ -61,7 +64,7 @@ export default tseslint.config(...config, ...astroConfig, ...reactConfig, {
61
64
  });
62
65
  ```
63
66
 
64
- **Scripts**:
67
+ **Scripts**
65
68
 
66
69
  ```json
67
70
  "scripts": {
@@ -14,8 +14,22 @@ import { perfectionistRules } from "../setup/perfectionist.js";
14
14
  import { a11yRules } from "../setup/a11y.js";
15
15
  import { readFileSync, writeFileSync } from "node:fs";
16
16
  import { join } from "node:path";
17
+ import { MarkdownGenerator } from "@ethang/markdown-generator/markdown-generator.js";
18
+ import { markdownRules } from "../setup/markdown.js";
19
+ import { jsonRules } from "../setup/json.js";
17
20
 
18
21
  export const updateReadme = () => {
22
+ const md = new MarkdownGenerator();
23
+ md.header(1, "Opinionated, Strict, Brutal, Unforgiving");
24
+ md.newLine(2);
25
+ md.link("View Config", "https://eslint-config-ethang.pages.dev/rules");
26
+ md.newLine(2);
27
+ md.alert(
28
+ "CAUTION",
29
+ "Do not use this with Prettier! Styling rules are included.",
30
+ );
31
+ md.newLine(2);
32
+
19
33
  const getRuleCount = (rules) => {
20
34
  let count = 0;
21
35
  Object.values(rules).forEach((value) => {
@@ -98,6 +112,16 @@ export const updateReadme = () => {
98
112
  name: "jsx-a11y",
99
113
  url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y",
100
114
  },
115
+ {
116
+ list: markdownRules,
117
+ name: "@eslint/markdown",
118
+ url: "https://github.com/eslint/markdown",
119
+ },
120
+ {
121
+ list: jsonRules,
122
+ name: "@eslint/json",
123
+ url: "https://github.com/eslint/json",
124
+ },
101
125
  ];
102
126
 
103
127
  let total = 0;
@@ -110,43 +134,95 @@ export const updateReadme = () => {
110
134
  return b.count - a.count;
111
135
  });
112
136
 
113
- const ruleDocs = [`- ${total} errored rules.`];
137
+ const ruleDocs = [`${total} errored rules.`];
114
138
  for (const list of ruleList) {
115
139
  ruleDocs.push(
116
- `- ${list.count} ${list.count <= 1 ? "rule" : "rules"} from [${list.name}](${list.url})`,
140
+ `${list.count} ${list.count <= 1 ? "rule" : "rules"} from [${list.name}](${list.url})`,
117
141
  );
118
142
  }
119
143
 
120
- const readme = readFileSync(
121
- join(import.meta.dirname, "../README.md"),
122
- "utf8",
144
+ md.unorderedList(ruleDocs);
145
+ md.newLine();
146
+ md.header(1, "Add Even More!");
147
+ md.newLine(2);
148
+ md.unorderedList(["51 rules for **Astro**"]);
149
+ md.unorderedList(
150
+ [
151
+ '`import astroConfig from "@ethang/eslint-config/config.astro.js";`',
152
+ "51 rules from [eslint-plugin-astro](https://github.com/ota-meshi/eslint-plugin-astro)",
153
+ ],
154
+ 2,
123
155
  );
124
- let readmeLines = readme.split("\n");
125
-
126
- let start = 0;
127
- let end = 0;
128
- for (let index = 1; index < readmeLines.length; index++) {
129
- if (
130
- readmeLines[index] ===
131
- "Do **NOT** use this with Prettier! Styling rules are included."
132
- ) {
133
- start = index;
134
- }
135
-
136
- if (readmeLines[index] === "# Add Even More!") {
137
- end = index;
138
- }
139
-
140
- if (start !== 0 && end !== 0) {
141
- break;
142
- }
143
- }
156
+ md.unorderedList(["68 rules for **React**"]);
157
+ md.unorderedList(
158
+ [
159
+ '`import reactConfig from "@ethang/eslint-config/config.react.js";`',
160
+ "68 rules from [@eslint-react/eslint-plugin](https://eslint-react.xyz/)",
161
+ ],
162
+ 2,
163
+ );
164
+ md.unorderedList(["18 rules for **Solid**"]);
165
+ md.unorderedList(
166
+ [
167
+ '`import solidConfig from "@ethang/eslint-config/config.solid.js";`',
168
+ "18 rules from [eslint-plugin-solid](https://github.com/solidjs-community/eslint-plugin-solid)",
169
+ ],
170
+ 2,
171
+ );
172
+ md.newLine();
173
+ md.header(1, "Install");
174
+ md.newLine(2);
175
+ md.inlineCode("pnpm i -D eslint typescript-eslint @ethang/eslint-config");
176
+ md.newLine(2);
177
+ md.bold("Requires TypesScript and tsconfig.json at root directory.");
178
+ md.newLine(2);
179
+ md.header(1, "Config");
180
+ md.newLine(2);
181
+ md.text("In **eslint.config.js**");
182
+ md.newLine(2);
183
+ md.codeBlock(
184
+ `import config from "@ethang/eslint-config/eslint.config.js";
185
+ import tseslint from "typescript-eslint";
186
+ import astroConfig from "@ethang/eslint-config/config.astro.js"; // OPTIONAL
187
+ import reactConfig from "@ethang/eslint-config/config.react.js"; // OPTIONAL
144
188
 
145
- readmeLines = [
146
- ...readmeLines.splice(0, start + 2),
147
- ...ruleDocs,
148
- ...readmeLines.splice(end - 7),
149
- ].join("\n");
189
+ export default tseslint.config(...config, ...astroConfig, ...reactConfig, {
190
+ languageOptions: {
191
+ parserOptions: {
192
+ project: true,
193
+ tsconfigRootDir: import.meta.dirname,
194
+ },
195
+ },
196
+ rules: {
197
+ // your custom rules here
198
+ },
199
+ });`,
200
+ "js",
201
+ );
202
+ md.newLine(2);
203
+ md.bold("Scripts");
204
+ md.newLine(2);
205
+ md.codeBlock(
206
+ `"scripts": {
207
+ "lint": "eslint",
208
+ "lint:fix": "eslint . --fix",
209
+ }`,
210
+ "json",
211
+ );
212
+ md.newLine(2);
213
+ md.bold("Browserslist");
214
+ md.newLine(2);
215
+ md.text(
216
+ "This config will also lint for browserslist features. Make sure to set this in package.json. [More info.](https://github.com/browserslist/browserslist)",
217
+ );
218
+ md.newLine(2);
219
+ md.codeBlock(
220
+ `"browserslist": [
221
+ "defaults and fully supports es6-module",
222
+ "maintained node versions"
223
+ ]`,
224
+ "json",
225
+ );
150
226
 
151
- writeFileSync(join(import.meta.dirname, "../README.md"), readmeLines, "utf8");
227
+ writeFileSync(join(import.meta.dirname, "../README.md"), md.render(), "utf8");
152
228
  };
@@ -15,9 +15,13 @@ import { a11yRules } from "../setup/a11y.js";
15
15
  import { readFileSync, writeFileSync } from "node:fs";
16
16
  import { join } from "node:path";
17
17
  import { deprecatedRules } from "../setup/deprecated.js";
18
+ import { markdownRules } from "../setup/markdown.js";
19
+ import { jsonRules } from "../setup/json.js";
18
20
 
19
21
  export const updateRules = () => {
20
- const rules = {
22
+ let configFile = "";
23
+
24
+ const jsRules = {
21
25
  ...dependRules,
22
26
  ...barrelRules,
23
27
  ...compatRules,
@@ -35,38 +39,94 @@ export const updateRules = () => {
35
39
  ...deprecatedRules,
36
40
  };
37
41
 
38
- let jsonified = JSON.stringify(rules);
39
- jsonified = jsonified.slice(1, -1);
42
+ let jsRulesJon = JSON.stringify(jsRules);
43
+ jsRulesJon = jsRulesJon.slice(1, -1);
40
44
 
41
- const config = readFileSync(
42
- join(import.meta.dirname, "../eslint.config.js"),
43
- "utf8",
44
- );
45
- const lines = config.split("\n");
45
+ let markdownRulesJson = JSON.stringify(markdownRules);
46
+ markdownRulesJson = markdownRulesJson.slice(1, -1);
46
47
 
47
- let rulesStart = 0;
48
- let rulesEnd = 0;
49
- for (let index = 1; index < lines.length; index++) {
50
- if (lines[index].endsWith("rules: {")) {
51
- rulesStart = index;
52
- }
48
+ let jsonRulesJson = JSON.stringify(jsonRules);
49
+ jsonRulesJson = jsonRulesJson.slice(1, -1);
53
50
 
54
- if (0 !== rulesStart && lines[index].endsWith("},")) {
55
- rulesEnd = index;
56
- }
57
- }
51
+ const importList = [
52
+ 'import parser from "@typescript-eslint/parser";',
53
+ 'import a11y from "eslint-plugin-jsx-a11y/lib/index.js";',
54
+ 'import n from "eslint-plugin-n";',
55
+ 'import unicorn from "eslint-plugin-unicorn";',
56
+ 'import tseslint from "typescript-eslint";',
57
+ 'import sonar from "eslint-plugin-sonarjs";',
58
+ 'import tanstack from "@tanstack/eslint-plugin-query";',
59
+ 'import perfectionist from "eslint-plugin-perfectionist";',
60
+ 'import depend from "eslint-plugin-depend";',
61
+ 'import barrel from "eslint-plugin-barrel-files";',
62
+ 'import compat from "eslint-plugin-compat";',
63
+ 'import lodashConfig from "eslint-plugin-lodash";',
64
+ 'import tailwind from "eslint-plugin-tailwindcss";',
65
+ 'import stylistic from "@stylistic/eslint-plugin";',
66
+ 'import markdown from "@eslint/markdown";',
67
+ 'import json from "@eslint/json";',
68
+ 'import { ignores } from "./constants.js";',
69
+ ].sort((a, b) => {
70
+ return a.localeCompare(b);
71
+ });
72
+
73
+ importList.forEach((item) => {
74
+ configFile += `${item}\n`;
75
+ });
76
+
77
+ configFile += `\nexport const languageOptions = {
78
+ parser,
79
+ parserOptions: {
80
+ project: true,
81
+ tsconfigRootDir: import.meta.dirname,
82
+ },
83
+ };
58
84
 
59
- const updated = [
60
- ...lines.slice(0, rulesStart),
61
- "rules: {",
62
- jsonified,
63
- "},",
64
- ...lines.slice(rulesEnd + 1),
65
- ].join("\n");
85
+ export default tseslint.config(
86
+ {
87
+ files: ["**/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts}"],
88
+ ignores,
89
+ languageOptions,
90
+ plugins: {
91
+ "@tanstack/query": tanstack,
92
+ "@typescript-eslint": tseslint.plugin,
93
+ a11y,
94
+ barrel,
95
+ compat,
96
+ depend,
97
+ lodash: lodashConfig,
98
+ n,
99
+ perfectionist,
100
+ sonar,
101
+ stylistic,
102
+ tailwind,
103
+ unicorn,
104
+ },
105
+ rules: {
106
+ ${jsRulesJon}
107
+ },
108
+ },
109
+ {
110
+ files: ["**/*.md"],
111
+ plugins: {
112
+ markdown,
113
+ },
114
+ rules: {
115
+ ${markdownRulesJson}
116
+ },
117
+ },
118
+ {
119
+ files: ["**/*.{json,jsonc,json5}"],
120
+ plugins: { json },
121
+ rules: {
122
+ ${jsonRulesJson}
123
+ },
124
+ },
125
+ );\n`;
66
126
 
67
127
  writeFileSync(
68
128
  join(import.meta.dirname, "../eslint.config.js"),
69
- updated,
129
+ configFile,
70
130
  "utf8",
71
131
  );
72
132
  };