@ocavue/eslint-config 2.21.0 → 3.0.1

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/dist/index.d.ts CHANGED
@@ -1,10 +1,4 @@
1
1
  import { type ESLintConfigOptions } from './options.js';
2
2
  import type { Config } from './types.js';
3
- export * from './basic.js';
4
- export * from './markdown.js';
5
- export * from './prettier.js';
6
- export * from './react.js';
7
- export * from './typescript.js';
8
- export * from './vue.js';
9
3
  export type { Config, ESLintConfigOptions };
10
4
  export declare function defineESLintConfig(options?: ESLintConfigOptions, ...userConfigs: Config[]): Promise<Config[]>;
package/dist/index.js CHANGED
@@ -1,11 +1,6 @@
1
1
  import { defineConfig } from 'eslint/config';
2
2
  import { resolveOptions } from './options.js';
3
- export * from './basic.js';
4
- export * from './markdown.js';
5
- export * from './prettier.js';
6
- export * from './react.js';
7
- export * from './typescript.js';
8
- export * from './vue.js';
3
+ import { trueToUndefined } from './shared.js';
9
4
  export async function defineESLintConfig(options, ...userConfigs) {
10
5
  const resolvedOptions = resolveOptions(options);
11
6
  const configs = [];
@@ -68,6 +63,3 @@ export async function defineESLintConfig(options, ...userConfigs) {
68
63
  configs.push(...userConfigs);
69
64
  return defineConfig(configs);
70
65
  }
71
- function trueToUndefined(value) {
72
- return value === true ? undefined : value;
73
- }
package/dist/markdown.js CHANGED
@@ -1,41 +1,27 @@
1
1
  import markdownPlugin from '@eslint/markdown';
2
+ import tseslint from 'typescript-eslint';
2
3
  import { GLOB_MARKDOWN, GLOB_SRC, GLOB_VUE } from './shared.js';
3
4
  export function markdown() {
4
- const recommended = markdownPlugin.configs.processor;
5
- const extra = {
5
+ const processor = markdownPlugin.configs.processor;
6
+ // @ts-expect-error: unmatched type: https://github.com/typescript-eslint/typescript-eslint/issues/10899
7
+ const disableTypeCheckedBase = tseslint.configs.disableTypeChecked;
8
+ const disableTypeChecked = {
9
+ ...disableTypeCheckedBase,
10
+ name: 'ocavue/markdown/disable-type-checked',
11
+ files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`],
12
+ };
13
+ const disableExtra = {
14
+ name: 'ocavue/markdown/disable-rules',
6
15
  files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`],
7
- languageOptions: {
8
- parserOptions: {
9
- projectService: null,
10
- },
11
- },
12
16
  rules: {
13
- // Disable type-aware TypeScript rules, because the code blocks are not
14
- // part of a compilable `tsconfig.json` project.
15
- '@typescript-eslint/no-redeclare': 'off',
16
- '@typescript-eslint/no-unused-vars': 'off',
17
- '@typescript-eslint/no-use-before-define': 'off',
18
- '@typescript-eslint/no-var-requires': 'off',
19
- '@typescript-eslint/restrict-plus-operands': 'off',
20
- '@typescript-eslint/no-unsafe-call': 'off',
21
- '@typescript-eslint/no-unsafe-return': 'off',
22
- '@typescript-eslint/no-unsafe-argument': 'off',
23
- '@typescript-eslint/no-unsafe-member-access': 'off',
24
- '@typescript-eslint/no-unsafe-assignment': 'off',
25
- '@typescript-eslint/no-floating-promises': 'off',
26
- '@typescript-eslint/no-misused-promises': 'off',
27
- '@typescript-eslint/await-thenable': 'off',
28
- '@typescript-eslint/unbound-method': 'off',
29
- '@typescript-eslint/require-await': 'off',
30
- '@typescript-eslint/no-unnecessary-type-assertion': 'off',
31
17
  // Disable some import rules because they are not working well with
32
18
  // twoslash ---cut--- imports.
33
19
  'import/first': 'off',
34
20
  'import/order': 'off',
35
21
  'no-alert': 'off',
36
22
  'no-console': 'off',
37
- 'no-restricted-imports': 'off',
23
+ '@typescript-eslint/no-unused-vars': 'off',
38
24
  },
39
25
  };
40
- return [...recommended, extra];
26
+ return [...processor, disableTypeChecked, disableExtra];
41
27
  }
package/dist/shared.d.ts CHANGED
@@ -21,3 +21,7 @@ export declare const GLOB_NODE_MODULES: "**/node_modules";
21
21
  export declare const GLOB_LOCKFILE: readonly ["**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml"];
22
22
  export declare const GLOB_EXCLUDE: readonly ["**/node_modules", "**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/fixtures", "**/.changeset", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__", "**/.tsup"];
23
23
  export declare const EXTENSIONS: string[];
24
+ export declare function findConfigByName<T extends {
25
+ name?: string;
26
+ }>(configs: T[], name: string): T | undefined;
27
+ export declare function trueToUndefined<T>(value: T | true): T | undefined;
package/dist/shared.js CHANGED
@@ -47,3 +47,13 @@ export const EXTENSIONS = ['ts', 'js']
47
47
  .flatMap((ext) => [ext, ext + 'x'])
48
48
  .flatMap((ext) => [ext, 'm' + ext, 'c' + ext])
49
49
  .flatMap((ext) => [ext, 'd.' + ext]);
50
+ export function findConfigByName(configs, name) {
51
+ const config = configs.find((c) => c.name === name);
52
+ if (!config) {
53
+ console.error(`[@ocavue/eslint-config] Unable to find config with name ${name}`);
54
+ }
55
+ return config;
56
+ }
57
+ export function trueToUndefined(value) {
58
+ return value === true ? undefined : value;
59
+ }
package/dist/types.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { Linter } from 'eslint';
2
2
  export type Config = Linter.Config;
3
+ export type Rules = Partial<Linter.RulesRecord>;
@@ -1,112 +1,142 @@
1
- import eslint from '@eslint/js';
2
1
  import tseslint from 'typescript-eslint';
3
- import { GLOB_JS, GLOB_JSX, GLOB_TEST, GLOB_TS, GLOB_TSX } from './shared.js';
2
+ import { findConfigByName, GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX, } from './shared.js';
4
3
  export { tseslint };
5
- export function typescript() {
6
- const rules = [...tseslint.configs.recommended, ...tseslint.configs.stylistic]
7
- .map((config) => config.rules || {})
8
- .reduce((acc, cur) => ({ ...acc, ...cur }), {});
9
- const config = [
10
- eslint.configs.recommended,
11
- {
12
- name: 'typescript',
13
- files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
14
- languageOptions: {
15
- parser: tseslint.parser,
16
- parserOptions: {
17
- projectService: true,
18
- sourceType: 'module',
19
- ecmaVersion: 'latest',
20
- },
4
+ function eslintRecommendedRules() {
5
+ return tseslint.configs.eslintRecommended.rules || {};
6
+ }
7
+ function recommendedRules() {
8
+ const configs = [...tseslint.configs.recommended];
9
+ const config = findConfigByName(configs, 'typescript-eslint/recommended');
10
+ // https://github.com/typescript-eslint/typescript-eslint/blob/v8.32.1/packages/eslint-plugin/src/configs/flat/recommended.ts#L25
11
+ const rules = config?.rules || {};
12
+ // @keep-sorted
13
+ return {
14
+ ...rules,
15
+ // `type T1 = T0` and `interface T2 extends T0 {}` have the same meaning
16
+ // but different behavior in TypeScript type checking. `T1` and `T0` are
17
+ // the same type, while `T2` is different than `T0`. We allow `interface
18
+ // T2 extends T0 {}` explicitly.
19
+ '@typescript-eslint/no-empty-object-type': [
20
+ 'error',
21
+ {
22
+ allowInterfaces: 'with-single-extends',
21
23
  },
22
- plugins: {
23
- '@typescript-eslint': tseslint.plugin,
24
+ ],
25
+ '@typescript-eslint/no-explicit-any': 'off',
26
+ '@typescript-eslint/no-unused-vars': [
27
+ 'error',
28
+ {
29
+ argsIgnorePattern: '^_',
30
+ varsIgnorePattern: '^_',
31
+ caughtErrorsIgnorePattern: '^_',
24
32
  },
25
- rules: {
26
- ...rules,
27
- '@typescript-eslint/consistent-type-definitions': 'off',
28
- '@typescript-eslint/prefer-optional-chain': 'off',
29
- '@typescript-eslint/prefer-nullish-coalescing': 'off',
30
- '@typescript-eslint/consistent-indexed-object-style': 'off',
31
- '@typescript-eslint/array-type': 'off',
32
- '@typescript-eslint/dot-notation': 'off',
33
- '@typescript-eslint/triple-slash-reference': 'off',
34
- '@typescript-eslint/consistent-type-imports': [
35
- 'warn',
36
- {
37
- // Allow type imports in type annotations (e.g. `type T = import('Foo').Foo`)
38
- disallowTypeAnnotations: false,
39
- },
40
- ],
41
- '@typescript-eslint/no-import-type-side-effects': 'warn',
42
- '@typescript-eslint/no-unnecessary-type-assertion': 'warn',
43
- '@typescript-eslint/no-unnecessary-parameter-property-assignment': 'warn',
44
- '@typescript-eslint/restrict-plus-operands': 'warn',
45
- '@typescript-eslint/no-unsafe-call': 'warn',
46
- '@typescript-eslint/no-unsafe-return': 'warn',
47
- '@typescript-eslint/no-unsafe-argument': 'warn',
48
- '@typescript-eslint/no-unsafe-member-access': 'warn',
49
- '@typescript-eslint/no-unsafe-assignment': 'warn',
50
- '@typescript-eslint/no-floating-promises': 'warn',
51
- '@typescript-eslint/no-explicit-any': 'warn',
52
- '@typescript-eslint/explicit-module-boundary-types': 'off',
53
- '@typescript-eslint/no-non-null-assertion': 'off',
54
- '@typescript-eslint/restrict-template-expressions': 'off',
55
- '@typescript-eslint/no-unused-vars': [
56
- 'error',
57
- {
58
- argsIgnorePattern: '^_',
59
- varsIgnorePattern: '^_',
60
- caughtErrorsIgnorePattern: '^_',
61
- },
62
- ],
63
- '@typescript-eslint/no-extra-semi': 'off',
64
- '@typescript-eslint/prefer-function-type': 'warn',
65
- '@typescript-eslint/no-misused-promises': [
66
- 'error',
67
- { checksVoidReturn: false },
68
- ],
69
- '@typescript-eslint/await-thenable': 'error',
70
- '@typescript-eslint/unbound-method': 'error',
71
- // `type T1 = T0` and `interface T2 extends T0 {}` have the same meaning
72
- // but different behavior in TypeScript type checking. `T1` and `T0` are
73
- // the same type, while `T2` is different than `T0`. We allow `interface
74
- // T2 extends T0 {}` explicitly.
75
- '@typescript-eslint/no-empty-object-type': [
76
- 'error',
77
- {
78
- allowInterfaces: 'with-single-extends',
79
- },
80
- ],
81
- // Turn off this rule because it's incompatible with the `--isolatedDeclarations` compiler option.
82
- '@typescript-eslint/no-inferrable-types': 'off',
83
- // TODO: We should set the rule below to error in the future
84
- '@typescript-eslint/require-await': 'warn',
33
+ ],
34
+ '@typescript-eslint/triple-slash-reference': 'off',
35
+ };
36
+ }
37
+ function recommendedTypeCheckedOnlyRules() {
38
+ const configs = [...tseslint.configs.recommendedTypeCheckedOnly];
39
+ const config = findConfigByName(configs, 'typescript-eslint/recommended-type-checked-only');
40
+ // https://github.com/typescript-eslint/typescript-eslint/blob/v8.32.1/packages/eslint-plugin/src/configs/flat/recommended-type-checked-only.ts#L25
41
+ const rules = config?.rules || {};
42
+ // @keep-sorted
43
+ return {
44
+ ...rules,
45
+ '@typescript-eslint/no-floating-promises': 'warn',
46
+ '@typescript-eslint/no-misused-promises': [
47
+ 'error',
48
+ { checksVoidReturn: false },
49
+ ],
50
+ '@typescript-eslint/no-unnecessary-type-assertion': 'warn',
51
+ '@typescript-eslint/no-unsafe-argument': 'warn',
52
+ '@typescript-eslint/no-unsafe-assignment': 'warn',
53
+ '@typescript-eslint/no-unsafe-call': 'warn',
54
+ '@typescript-eslint/no-unsafe-member-access': 'warn',
55
+ '@typescript-eslint/no-unsafe-return': 'warn',
56
+ '@typescript-eslint/restrict-template-expressions': 'off',
57
+ };
58
+ }
59
+ function stylisticRules() {
60
+ const configs = [...tseslint.configs.stylistic];
61
+ const config = findConfigByName(configs, 'typescript-eslint/stylistic');
62
+ // https://github.com/typescript-eslint/typescript-eslint/blob/v8.32.1/packages/eslint-plugin/src/configs/flat/stylistic.ts#L25
63
+ const rules = config?.rules || {};
64
+ // @keep-sorted
65
+ return {
66
+ ...rules,
67
+ '@typescript-eslint/array-type': 'off',
68
+ '@typescript-eslint/consistent-indexed-object-style': 'off',
69
+ '@typescript-eslint/consistent-type-definitions': 'off',
70
+ '@typescript-eslint/no-empty-function': 'off',
71
+ // Turn off this rule because it's incompatible with the `--isolatedDeclarations` compiler option.
72
+ '@typescript-eslint/no-inferrable-types': 'off',
73
+ '@typescript-eslint/prefer-for-of': 'off',
74
+ '@typescript-eslint/prefer-function-type': 'warn',
75
+ };
76
+ }
77
+ function commonRules() {
78
+ return {
79
+ ...eslintRecommendedRules,
80
+ ...recommendedRules(),
81
+ };
82
+ }
83
+ function tsOnlyRules() {
84
+ // @keep-sorted
85
+ return {
86
+ ...recommendedTypeCheckedOnlyRules(),
87
+ ...stylisticRules(),
88
+ '@typescript-eslint/consistent-type-imports': [
89
+ 'warn',
90
+ {
91
+ // Allow type imports in type annotations (e.g. `type T = import('Foo').Foo`)
92
+ disallowTypeAnnotations: false,
85
93
  },
86
- },
87
- {
88
- name: 'typescript-js',
89
- files: [GLOB_JS, GLOB_JSX],
90
- rules: {
91
- '@typescript-eslint/no-require-imports': 'off',
92
- '@typescript-eslint/no-var-requires': 'off',
94
+ ],
95
+ '@typescript-eslint/no-import-type-side-effects': 'warn',
96
+ '@typescript-eslint/no-mixed-enums': 'error',
97
+ '@typescript-eslint/no-unnecessary-parameter-property-assignment': 'warn',
98
+ '@typescript-eslint/return-await': ['error', 'always'],
99
+ };
100
+ }
101
+ function jsOnlyRules() {
102
+ // @keep-sorted
103
+ return {
104
+ '@typescript-eslint/no-require-imports': 'off',
105
+ '@typescript-eslint/no-var-requires': 'off',
106
+ };
107
+ }
108
+ export function typescript() {
109
+ const base = {
110
+ name: 'ocavue/typescript/base',
111
+ files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
112
+ languageOptions: {
113
+ parser: tseslint.parser,
114
+ parserOptions: {
115
+ projectService: true,
116
+ warnOnUnsupportedTypeScriptVersion: false,
117
+ sourceType: 'module',
93
118
  },
94
119
  },
95
- {
96
- name: 'typescript-test',
97
- files: [GLOB_TEST],
98
- rules: {
99
- '@typescript-eslint/no-unsafe-call': 'warn',
100
- '@typescript-eslint/no-unsafe-return': 'warn',
101
- '@typescript-eslint/no-unsafe-argument': 'warn',
102
- '@typescript-eslint/no-unsafe-member-access': 'warn',
103
- '@typescript-eslint/no-unsafe-assignment': 'warn',
104
- '@typescript-eslint/no-explicit-any': 'off',
105
- '@typescript-eslint/no-empty-function': 'off',
106
- },
120
+ plugins: {
121
+ '@typescript-eslint': tseslint.plugin,
107
122
  },
108
- ];
123
+ };
124
+ const common = {
125
+ name: 'ocavue/typescript/rules',
126
+ files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
127
+ rules: commonRules(),
128
+ };
129
+ const ts = {
130
+ name: 'ocavue/typescript/ts-only-rules',
131
+ files: [GLOB_TS, GLOB_TSX],
132
+ rules: tsOnlyRules(),
133
+ };
134
+ const js = {
135
+ name: 'ocavue/typescript/js-only-rules',
136
+ files: [GLOB_JS, GLOB_JSX],
137
+ rules: jsOnlyRules(),
138
+ };
109
139
  // @ts-expect-error: unmatched type
110
- const configTyped = config;
111
- return configTyped;
140
+ const configs = [base, common, ts, js];
141
+ return configs;
112
142
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocavue/eslint-config",
3
3
  "type": "module",
4
- "version": "2.21.0",
4
+ "version": "3.0.1",
5
5
  "description": "",
6
6
  "author": "ocavue <ocavue@gmail.com>",
7
7
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@eslint/js": "^9.26.0",
31
+ "@eslint/js": "^9.27.0",
32
32
  "@eslint/markdown": "^6.4.0",
33
33
  "@unocss/eslint-config": "^66.1.2",
34
34
  "eslint-config-flat-gitignore": "^2.1.0",
@@ -51,7 +51,7 @@
51
51
  "@ocavue/tsconfig": "^0.3.7",
52
52
  "@types/node": "^20.17.9",
53
53
  "@typescript-eslint/utils": "^8.32.1",
54
- "eslint": "^9.26.0",
54
+ "eslint": "^9.27.0",
55
55
  "jiti": "^2.4.2",
56
56
  "pkg-pr-new": "^0.0.50",
57
57
  "prettier": "^3.5.3",
package/dist/basic.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Linter } from 'eslint';
2
- export declare function basic(): Linter.Config[];
package/dist/basic.js DELETED
@@ -1,22 +0,0 @@
1
- import { antfu } from './antfu.js';
2
- import { ignores } from './ignores.js';
3
- import { imports } from './imports.js';
4
- import { noOnlyTests } from './no-only-tests.js';
5
- import { packageJson } from './package-json.js';
6
- import { prettier } from './prettier.js';
7
- import { typescript } from './typescript.js';
8
- import { unicorn } from './unicorn.js';
9
- import { gitignore } from './gitignore.js';
10
- export function basic() {
11
- return [
12
- ...ignores(),
13
- ...gitignore(),
14
- ...typescript(),
15
- ...imports(),
16
- ...packageJson(),
17
- ...unicorn(),
18
- ...antfu(),
19
- ...noOnlyTests(),
20
- ...prettier(),
21
- ];
22
- }