Skip to content

Commit 0e6ecd0

Browse files
committed
feat: more work on the configs
Signed-off-by: prisis <[email protected]>
1 parent 2c8b8e2 commit 0e6ecd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2250
-2146
lines changed

packages/eslint-config/src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { hasDependency, hasDevDependency, hasFile, resolvePackage } from "@anolilab/package-json-utils";
1+
import {
2+
hasDependency,
3+
hasDevDependency,
4+
hasFile,
5+
resolvePackage,
6+
} from "@anolilab/package-json-utils";
27

38
import type { PackageRules } from "./types";
49
import anolilabEslintConfig from "./utils/eslint-config";
@@ -495,7 +500,6 @@ const loadedPlugins: string[] = [...internalPluginConfig];
495500
const possiblePlugins: Record<string, Record<string, boolean>> = {};
496501

497502
if (loadedPlugins.length === internalPluginConfig.length) {
498-
// eslint-disable-next-line sonarjs/cognitive-complexity
499503
pluginConfig.forEach((plugin) => {
500504
const { configName, dependencies } = plugin;
501505

packages/eslint-config/src/config/best-practices.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
import { createConfig, getFilesGlobs } from "../utils/create-config";
2-
import type { OptionsFiles } from "../types";
31
import { Linter } from "eslint";
42

5-
export const bestPracticesRules: Partial<Linter.RulesRecord> = {
6-
// Disallow non-null assertions using the ! postfix operator.
7-
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md
8-
"no-return-await": "off",
9-
10-
// Disallow calling a value with type any.
11-
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
12-
"no-unused-expressions": "off",
13-
14-
// Disallow type assertions that do not change the type of expression.
15-
// Disable the "no-throw-literal" rule, as it can report incorrect errors on TypeScript code
16-
"no-throw-literal": "off",
17-
18-
// Disallow empty exports that don't change anything in a module file.
19-
// Breaks @typescript-eslint/parser
20-
strict: "off",
3+
import type { OptionsFiles } from "../types";
4+
import { createConfig, getFilesGlobs } from "../utils/create-config";
215

6+
export const bestPracticesRules: Partial<Linter.RulesRecord> = {
227
// Disable the "dot-notation" rule, as it can report incorrect errors on TypeScript code
238
"dot-notation": "off",
249

@@ -29,7 +14,6 @@ export const bestPracticesRules: Partial<Linter.RulesRecord> = {
2914
// Disallow using to delete operator on computed key expressions.
3015
// Disable the "no-implied-eval" and "no-new-func" rule, as it can report incorrect errors on TypeScript code
3116
"no-implied-eval": "off",
32-
"no-new-func": "off",
3317

3418
// Disallow extra non-null assertions.
3519
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-loop-func.md
@@ -39,18 +23,35 @@ export const bestPracticesRules: Partial<Linter.RulesRecord> = {
3923
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-magic-numbers.md
4024
"no-magic-numbers": "off",
4125

26+
"no-new-func": "off",
27+
4228
// Disallow non-null assertions after an optional chain expression.
4329
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-redeclare.md
4430
"no-redeclare": "off",
31+
// Disallow non-null assertions using the ! postfix operator.
32+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md
33+
"no-return-await": "off",
34+
35+
// Disallow type assertions that do not change the type of expression.
36+
// Disable the "no-throw-literal" rule, as it can report incorrect errors on TypeScript code
37+
"no-throw-literal": "off",
38+
39+
// Disallow calling a value with type any.
40+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
41+
"no-unused-expressions": "off",
42+
43+
// Disallow empty exports that don't change anything in a module file.
44+
// Breaks @typescript-eslint/parser
45+
strict: "off",
4546
};
4647

4748
export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
4849
const { files = oFiles } = config;
4950

5051
return [
5152
{
52-
name: "anolilab/best-practices/rules",
5353
files,
54+
name: "anolilab/best-practices/rules",
5455
rules: {
5556
// enforces getter/setter pairs in objects
5657
"accessor-pairs": "off",
@@ -497,8 +498,8 @@ export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
497498
},
498499
},
499500
{
500-
name: "anolilab/best-practices/ts-rules",
501501
files: getFilesGlobs("ts"),
502+
name: "anolilab/best-practices/ts-rules",
502503
rules: bestPracticesRules,
503504
},
504505
];

packages/eslint-config/src/config/errors.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { createConfig, getFilesGlobs } from "../utils/create-config";
2-
import type { OptionsFiles } from "../types";
31
import { Linter } from "eslint";
42

3+
import type { OptionsFiles } from "../types";
4+
import { createConfig, getFilesGlobs } from "../utils/create-config";
5+
56
export const errorsRules: Partial<Linter.RulesRecord> = {
67
// Enforce “for” loop update clause moving the counter in the right direction
78
// https://eslint.org/docs/rules/for-direction
@@ -65,24 +66,6 @@ export const errorsRules: Partial<Linter.RulesRecord> = {
6566
// https://eslint.org/docs/rules/no-extra-boolean-cast
6667
"no-extra-boolean-cast": "error",
6768

68-
// disallow unnecessary parentheses
69-
// https://eslint.org/docs/rules/no-extra-parens
70-
"no-extra-parens": [
71-
"error",
72-
"all",
73-
{
74-
conditionalAssign: true,
75-
enforceForArrowConditionals: false,
76-
ignoreJSX: "all", // delegate to eslint-plugin-react
77-
nestedBinaryExpressions: false,
78-
returnAssign: false,
79-
},
80-
],
81-
82-
// Disallow non-null assertion in locations that may be confusing.
83-
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-semi.md
84-
"no-extra-semi": "error",
85-
8669
// disallow overwriting functions written as function declarations
8770
"no-func-assign": "error",
8871

@@ -110,14 +93,14 @@ export const errorsRules: Partial<Linter.RulesRecord> = {
11093
// deprecated in favor of no-unsafe-negation
11194
"no-negated-in-lhs": "off",
11295

113-
// Disallow returning values from Promise executor functions
114-
// disallow the use of object properties of the global object (Math and JSON) as functions
115-
"no-obj-calls": "error",
116-
11796
// Disallow new operators with global non-constructor functions
11897
// https://eslint.org/docs/latest/rules/no-new-native-nonconstructor
11998
"no-new-native-nonconstructor": "error",
12099

100+
// Disallow returning values from Promise executor functions
101+
// disallow the use of object properties of the global object (Math and JSON) as functions
102+
"no-obj-calls": "error",
103+
121104
// disallow use of Object.prototypes builtins directly
122105
// https://eslint.org/docs/rules/no-promise-executor-return
123106
"no-promise-executor-return": "error",
@@ -189,15 +172,15 @@ export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
189172

190173
return [
191174
{
192-
name: "anolilab/errors/rules",
193175
files,
176+
name: "anolilab/errors/rules",
194177
rules: errorsRules,
195178
},
196179
// The following rules are enabled in config, but are already checked (more thoroughly) by the TypeScript compiler
197180
// Some rules also fail in TypeScript files, for example: https://github.com/typescript-eslint/typescript-eslint/issues/662#issuecomment-507081586
198181
{
199-
name: "anolilab/errors/ts-rules",
200182
files: getFilesGlobs("ts"),
183+
name: "anolilab/errors/ts-rules",
201184
rules: {
202185
"getter-return": "off",
203186

@@ -211,6 +194,8 @@ export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
211194
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-parens.md
212195
"no-extra-parens": "off",
213196

197+
"no-extra-semi": "off",
198+
214199
// Disallow duplicate enum member values.
215200
"no-func-assign": "off",
216201

@@ -228,8 +213,6 @@ export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
228213
"space-infix-ops": "off",
229214

230215
"valid-typeof": "off",
231-
232-
"no-extra-semi": "off",
233216
},
234217
},
235218
];

packages/eslint-config/src/config/es6.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { createConfig, getFilesGlobs } from "../utils/create-config";
2-
import type { OptionsFiles } from "../types";
31
import { Linter } from "eslint";
42

3+
import type { OptionsFiles } from "../types";
4+
import { createConfig, getFilesGlobs } from "../utils/create-config";
5+
56
export const eS6Rules: Partial<Linter.RulesRecord> = {
67
// enforces no braces where they can be omitted
78
// https://eslint.org/docs/rules/arrow-body-style
@@ -118,7 +119,7 @@ export const eS6Rules: Partial<Linter.RulesRecord> = {
118119
name: "sys",
119120
},
120121
{
121-
message: 'Is legacy, npm version got deprecated, migrate to URLSearchParams as recommended or try "qs" as a package',
122+
message: "Is legacy, npm version got deprecated, migrate to URLSearchParams as recommended or try \"qs\" as a package",
122123
name: "querystring",
123124
},
124125
{
@@ -130,7 +131,7 @@ export const eS6Rules: Partial<Linter.RulesRecord> = {
130131
name: "mkdirp",
131132
},
132133
{
133-
message: 'Please use "@faker-js/faker" as a replacement',
134+
message: "Please use \"@faker-js/faker\" as a replacement",
134135
name: "faker",
135136
},
136137
{
@@ -150,23 +151,23 @@ export const eS6Rules: Partial<Linter.RulesRecord> = {
150151
name: "rimraf",
151152
},
152153
{
153-
message: 'just use "".padStart() and "".padEnd()',
154+
message: "just use \"\".padStart() and \"\".padEnd()",
154155
name: "pad-left",
155156
},
156157
{
157-
message: 'just use "".padStart() and "".padEnd()',
158+
message: "just use \"\".padStart() and \"\".padEnd()",
158159
name: "pad-right",
159160
},
160161
{
161-
message: 'just use "".padStart() and "".padEnd()',
162+
message: "just use \"\".padStart() and \"\".padEnd()",
162163
name: "left-pad",
163164
},
164165
{
165-
message: 'just use "".padStart() and "".padEnd()',
166+
message: "just use \"\".padStart() and \"\".padEnd()",
166167
name: "right-pad",
167168
},
168169
{
169-
message: 'just use "".padStart() and "".padEnd()',
170+
message: "just use \"\".padStart() and \"\".padEnd()",
170171
name: "pad",
171172
},
172173
{
@@ -341,8 +342,8 @@ export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
341342

342343
return [
343344
{
344-
name: "anolilab/es6/rules",
345345
files,
346+
name: "anolilab/es6/rules",
346347
parserOptions: {
347348
ecmaFeatures: {
348349
generators: false,
@@ -356,27 +357,27 @@ export default createConfig<OptionsFiles>("all", async (config, oFiles) => {
356357
// The following rules are enabled in config, but are already checked (more thoroughly) by the TypeScript compiler
357358
// Some rules also fail in TypeScript files, for example: https://github.com/typescript-eslint/typescript-eslint/issues/662#issuecomment-507081586
358359
{
359-
name: "anolilab/es6/ts-rules",
360360
files: getFilesGlobs("ts"),
361+
name: "anolilab/es6/ts-rules",
361362
rules: {
362363
"constructor-super": "off",
363364

364-
// Disallow returning a value with type any from a function.
365-
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
366-
"no-useless-constructor": "off",
365+
// Enforce constituents of a type union/intersection to be sorted alphabetically.
366+
"no-const-assign": "off",
367367

368368
// Enforce specifying generic type arguments on constructor name of a constructor call.
369369
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
370370
"no-dupe-class-members": "off",
371371

372-
// Enforce constituents of a type union/intersection to be sorted alphabetically.
373-
"no-const-assign": "off",
374-
375372
// Disallow TypeScript namespaces.
376373
"no-new-symbol": "off",
377374

378375
// Disallow aliasing this.
379376
"no-this-before-super": "off",
377+
378+
// Disallow returning a value with type any from a function.
379+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
380+
"no-useless-constructor": "off",
380381
},
381382
},
382383
];

packages/eslint-config/src/config/ignores.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ const ignores = async (userIgnores: string[] = []): Promise<TypedFlatConfigItem[
4343
name: "anolilab/ignores",
4444
},
4545
];
46-
}
46+
};
4747

4848
export default ignores;

packages/eslint-config/src/config/plugins/antfu.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
import { createConfig } from "../../utils/create-config";
1+
import { hasPackageJsonAnyDependency } from "@visulima/package";
2+
23
import type { OptionsFiles, OptionsOverrides, OptionsPackageJson } from "../../types";
4+
import { createConfig } from "../../utils/create-config";
35
import interopDefault from "../../utils/interop-default";
4-
import { hasPackageJsonAnyDependency } from "@visulima/package";
56

67
export default createConfig<
8+
OptionsFiles &
79
OptionsOverrides &
8-
OptionsFiles &
9-
OptionsPackageJson & {
10-
lessOpinionated?: boolean;
11-
}
10+
OptionsPackageJson & {
11+
lessOpinionated?: boolean;
12+
}
1213
>("all", async (config, oFiles) => {
13-
const { files = oFiles, overrides, packageJson, lessOpinionated = false } = config;
14+
const {
15+
files = oFiles,
16+
lessOpinionated = false,
17+
overrides,
18+
packageJson,
19+
} = config;
1420

1521
const antfuPlugin = await interopDefault(import("eslint-plugin-antfu"));
1622

@@ -22,28 +28,27 @@ export default createConfig<
2228
antfu: antfuPlugin,
2329
},
2430
rules: {
31+
"antfu/consistent-chaining": "error",
32+
"antfu/consistent-list-newline": "error",
33+
"antfu/if-newline": "error",
34+
2535
"antfu/import-dedupe": "error",
36+
2637
"antfu/no-import-dist": "error",
2738
"antfu/no-import-node-modules-by-path": "error",
28-
2939
"antfu/no-ts-export-equal": hasPackageJsonAnyDependency(packageJson, ["typescript"]) ? "error" : "off",
3040

31-
"antfu/if-newline": "error",
3241
"antfu/prefer-inline-type-import": "off",
3342
"antfu/top-level-function": "off",
3443

35-
"antfu/consistent-chaining": "error",
36-
"antfu/consistent-list-newline": "error",
37-
38-
...(lessOpinionated
44+
...lessOpinionated
3945
? {
40-
curly: ["error", "all"],
41-
}
46+
curly: ["error", "all"],
47+
}
4248
: {
43-
"antfu/curly": "error",
44-
"antfu/if-newline": "error",
45-
"antfu/top-level-function": "error",
46-
}),
49+
"antfu/curly": "error",
50+
"antfu/if-newline": "error",
51+
},
4752

4853
...overrides,
4954
},

packages/eslint-config/src/config/plugins/array-func.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import type { OptionsFiles, OptionsOverrides } from "../../types";
12
import { createConfig } from "../../utils/create-config";
23
import interopDefault from "../../utils/interop-default";
3-
import type { OptionsFiles, OptionsOverrides } from "../../types";
44

5-
export default createConfig<OptionsOverrides & OptionsFiles>("all", async (config, oFiles) => {
6-
const { overrides, files = oFiles } = config;
5+
export default createConfig<OptionsFiles & OptionsOverrides>("all", async (config, oFiles) => {
6+
const { files = oFiles, overrides } = config;
77

88
const arrayFuncPlugin = await interopDefault(import("eslint-plugin-array-func"));
99

1010
return [
1111
{
1212
files,
13-
name: "anolilab/array-func/rules",
1413
languageOptions: {
1514
ecmaVersion: 2018,
1615
},
16+
name: "anolilab/array-func/rules",
1717
plugins: {
1818
"array-func": arrayFuncPlugin,
1919
},

0 commit comments

Comments
 (0)