Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 915c9c0

Browse files
committed
Enhance eslint config
1 parent 4aaf394 commit 915c9c0

File tree

11 files changed

+97
-23
lines changed

11 files changed

+97
-23
lines changed

.eslintrc.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,52 @@ module.exports = defineConfig({
3333
quotes: ['error', 'single', { avoidEscape: true }],
3434
semi: ['error', 'always'],
3535

36-
'@typescript-eslint/ban-ts-comment': 'off',
37-
'@typescript-eslint/explicit-function-return-type': [
36+
'@typescript-eslint/array-type': [
3837
'error',
39-
{ allowExpressions: true },
38+
{ default: 'array-simple', readonly: 'generic' },
4039
],
41-
'@typescript-eslint/interface-name-prefix': 'off',
42-
'@typescript-eslint/member-ordering': 'off',
43-
'@typescript-eslint/consistent-type-imports': [
40+
'@typescript-eslint/ban-ts-comment': 'error',
41+
'@typescript-eslint/consistent-type-imports': 'error',
42+
'@typescript-eslint/explicit-module-boundary-types': 'error',
43+
'@typescript-eslint/naming-convention': [
4444
'error',
45-
{ prefer: 'type-imports' },
45+
{
46+
format: ['PascalCase'],
47+
selector: ['class', 'interface', 'typeAlias', 'typeParameter'],
48+
leadingUnderscore: 'forbid',
49+
trailingUnderscore: 'forbid',
50+
},
4651
],
47-
'@typescript-eslint/no-explicit-any': 'off',
4852
'@typescript-eslint/no-inferrable-types': 'off',
49-
'@typescript-eslint/no-non-null-assertion': 'off',
50-
'@typescript-eslint/no-parameter-properties': 'off',
53+
'@typescript-eslint/no-unsafe-argument': 'error',
5154
'@typescript-eslint/no-unsafe-assignment': 'off',
52-
'@typescript-eslint/no-unused-vars': 'off',
55+
'@typescript-eslint/no-unsafe-call': 'off',
56+
'@typescript-eslint/no-unsafe-member-access': 'off',
57+
'@typescript-eslint/no-unsafe-return': 'error',
58+
'@typescript-eslint/padding-line-between-statements': [
59+
'error',
60+
{ blankLine: 'always', prev: 'block-like', next: '*' },
61+
],
5362
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
5463
'@typescript-eslint/prefer-optional-chain': 'warn',
55-
'@typescript-eslint/prefer-readonly': ['warn'],
56-
'@typescript-eslint/restrict-template-expressions': 'off',
64+
'@typescript-eslint/prefer-readonly': 'warn',
65+
'@typescript-eslint/restrict-template-expressions': [
66+
'error',
67+
{ allowNumber: true, allowBoolean: true },
68+
],
5769
'@typescript-eslint/typedef': [
5870
'warn',
5971
{ memberVariableDeclaration: true, variableDeclaration: true },
6072
],
6173
},
74+
overrides: [
75+
{
76+
// Rule files are generated by `generate:rules` script
77+
files: ['src/rules/**/*.d.ts'],
78+
rules: {
79+
'@typescript-eslint/array-type': 'off',
80+
'@typescript-eslint/no-explicit-any': 'off',
81+
},
82+
},
83+
],
6284
});

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"main": "src/index.js",
66
"module": "src/index.mjs",
77
"scripts": {
8-
"clean": "rm -Rf dist pnpm-lock.yaml node_modules",
8+
"clean": "rimraf .eslintcache dist pnpm-lock.yaml node_modules",
99
"check": "tsc",
10-
"format": "prettier --write .",
11-
"lint": "eslint .",
10+
"format": "prettier --cache --write .",
11+
"lint": "eslint --cache --cache-strategy content .",
1212
"typecheck": "vitest typecheck",
1313
"test": "vitest",
1414
"coverage": "vitest run --coverage",
@@ -87,6 +87,7 @@
8787
"json-schema-to-typescript": "~12.0.0",
8888
"prettier": "2.8.7",
8989
"prettier-plugin-organize-imports": "~3.2.2",
90+
"rimraf": "~5.0.0",
9091
"ts-dedent": "~2.2.0",
9192
"tsx": "~3.12.6",
9293
"typescript": "~5.0.4",

pnpm-lock.yaml

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-rule-files/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function generateRuleIndexFile(
6464
* Print a report after having generated rules files for a plugin.
6565
*/
6666
function printGenerationReport(
67-
rules: [string, Rule.RuleModule][],
67+
rules: Array<[string, Rule.RuleModule]>,
6868
failedRules: string[],
6969
): void {
7070
const msg: string = ` ✅ Generated ${
@@ -76,6 +76,7 @@ function printGenerationReport(
7676
if (failedRules.length) {
7777
logger.log(logger.colors.red(` ❌ Failed ${failedRules.length} rules`));
7878
}
79+
7980
logger.log('');
8081
}
8182

@@ -118,6 +119,7 @@ async function generateRulesFiles(
118119

119120
return { failedRules };
120121
}
122+
121123
/**
122124
* If it doesn't exist, create the directory that will contain the plugin's rule files.
123125
*/

scripts/generate-rule-files/src/js-doc-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class JsDocBuilder {
1212
if (line) {
1313
this.content.push(line);
1414
}
15+
1516
return this;
1617
}
1718

scripts/generate-rule-files/src/plugins-map.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
8484
} as const;
8585

8686
export async function loadPlugin(plugin: Plugin): Promise<Plugin> {
87+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8788
const mod: any = await import(plugin.module);
8889
const rules: PluginRules =
8990
plugin.module === 'eslint'

src/config/extends/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ export type KnownExtensions = LiteralUnion<
4545
*
4646
* @see [Extends](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files)
4747
*/
48-
export type Extends = KnownExtensions | Array<KnownExtensions>;
48+
export type Extends = KnownExtensions | KnownExtensions[];

src/config/overrides.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ export interface Override {
9393
/**
9494
* Overrides.
9595
*/
96-
export type Overrides = Array<Override>;
96+
export type Overrides = Override[];

src/flat-config/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface FlatESLintConfigItem {
6161
*
6262
* @see [Configuring shared settings](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuring-shared-settings)
6363
*/
64+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6465
settings?: Record<string, any>;
6566
}
6667

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function defineFlatConfig(config: FlatESLintConfig): FlatESLintConfig;
2828
* @returns Flat ESLint config.
2929
*/
3030
export function defineFlatConfig(
31-
config: readonly FlatESLintConfig[],
31+
config: ReadonlyArray<FlatESLintConfig>,
3232
): FlatESLintConfig[];
3333

3434
export * from './config';

0 commit comments

Comments
 (0)