Skip to content

Commit 05bee87

Browse files
fix: Correctly parse .ts files
1 parent f10fc0c commit 05bee87

File tree

7 files changed

+161
-167
lines changed

7 files changed

+161
-167
lines changed

docs/eslint.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ title: ESLint
1313
### eslint.config.js
1414

1515
```js
16-
import { rootConfig } from '@tanstack/config/eslint'
16+
import { tanstackConfig } from '@tanstack/config/eslint'
1717

1818
export default [
19-
...rootConfig,
19+
...tanstackConfig,
2020
{
2121
// Custom rules go here
2222
},

eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
22

3-
import { rootConfig } from './src/eslint/index.js'
3+
import { tanstackConfig } from './src/eslint/index.js'
44

5-
export default [...rootConfig]
5+
export default [...tanstackConfig]

src/eslint/import.js

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
// https://github.com/un-ts/eslint-plugin-import-x
22

3-
/** @type {import('eslint').Linter.FlatConfig} */
3+
/** @type {import('eslint').Linter.RulesRecord} */
44
export const importRules = {
5-
name: 'tanstack/import',
6-
rules: {
7-
/** Stylistic preference */
8-
'import/newline-after-import': 'error',
9-
/** No require() or module.exports */
10-
'import/no-commonjs': 'error',
11-
/** No import loops */
12-
'import/no-cycle': 'error',
13-
/** Reports if a resolved path is imported more than once */
14-
'import/no-duplicates': 'error',
15-
/** Default export name cannot match named export */
16-
'import/no-named-as-default': 'error',
17-
/** Don't access named imports from default export */
18-
'import/no-named-as-default-member': 'error',
19-
/** Stylistic preference */
20-
'import/order': [
21-
'error',
22-
{
23-
groups: [
24-
'builtin',
25-
'external',
26-
'internal',
27-
'parent',
28-
'sibling',
29-
'index',
30-
'object',
31-
'type',
32-
],
33-
},
34-
],
35-
},
5+
/** Stylistic preference */
6+
'import/newline-after-import': 'error',
7+
/** No require() or module.exports */
8+
'import/no-commonjs': 'error',
9+
/** No import loops */
10+
'import/no-cycle': 'error',
11+
/** Reports if a resolved path is imported more than once */
12+
'import/no-duplicates': 'error',
13+
/** Default export name cannot match named export */
14+
'import/no-named-as-default': 'error',
15+
/** Don't access named imports from default export */
16+
'import/no-named-as-default-member': 'error',
17+
/** Stylistic preference */
18+
'import/order': [
19+
'error',
20+
{
21+
groups: [
22+
'builtin',
23+
'external',
24+
'internal',
25+
'parent',
26+
'sibling',
27+
'index',
28+
'object',
29+
'type',
30+
],
31+
},
32+
],
3633
}

src/eslint/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import type { Linter } from 'eslint'
22

3-
export declare const rootConfig: Array<Linter.FlatConfig>
3+
export declare const tanstackConfig: Array<Linter.FlatConfig>

src/eslint/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { importRules } from './import.js'
66
import { typescriptRules } from './typescript.js'
77

88
/** @type {import('eslint').Linter.FlatConfig[]} */
9-
export const rootConfig = [
9+
export const tanstackConfig = [
1010
{
1111
name: 'tanstack/setup',
12+
files: ['**/*.{js,svelte,ts,tsx,vue}'],
1213
languageOptions: {
1314
sourceType: 'module',
1415
ecmaVersion: 2020,
@@ -29,8 +30,10 @@ export const rootConfig = [
2930
// @ts-expect-error
3031
ts: tseslint.plugin,
3132
},
33+
rules: {
34+
...javascriptRules,
35+
...importRules,
36+
...typescriptRules,
37+
},
3238
},
33-
javascriptRules,
34-
importRules,
35-
typescriptRules,
3639
]

src/eslint/javascript.js

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,74 @@
11
// https://eslint.org/docs/latest/rules/
22

3-
/** @type {import('eslint').Linter.FlatConfig} */
3+
/** @type {import('eslint').Linter.RulesRecord} */
44
export const javascriptRules = {
5-
name: 'tanstack/javascript',
6-
rules: {
7-
/** Constructors of derived classes must call super() */
8-
'constructor-super': 'error',
9-
/** TODO */
10-
'for-direction': 'error',
11-
'getter-return': 'error',
12-
'no-async-promise-executor': 'error',
13-
'no-case-declarations': 'error',
14-
'no-class-assign': 'error',
15-
'no-compare-neg-zero': 'error',
16-
'no-cond-assign': 'error',
17-
'no-const-assign': 'error',
18-
'no-constant-binary-expression': 'error',
19-
'no-constant-condition': 'error',
20-
'no-control-regex': 'error',
21-
'no-debugger': 'error',
22-
'no-delete-var': 'error',
23-
'no-dupe-args': 'error',
24-
'no-dupe-class-members': 'error',
25-
'no-dupe-else-if': 'error',
26-
'no-dupe-keys': 'error',
27-
'no-duplicate-case': 'error',
28-
'no-empty': 'error',
29-
'no-empty-character-class': 'error',
30-
'no-empty-pattern': 'error',
31-
'no-empty-static-block': 'error',
32-
'no-ex-assign': 'error',
33-
'no-extra-boolean-cast': 'error',
34-
'no-fallthrough': 'error',
35-
'no-func-assign': 'error',
36-
'no-global-assign': 'error',
37-
'no-import-assign': 'error',
38-
'no-invalid-regexp': 'error',
39-
'no-irregular-whitespace': 'error',
40-
'no-loss-of-precision': 'error',
41-
'no-misleading-character-class': 'error',
42-
'no-new-native-nonconstructor': 'error',
43-
'no-nonoctal-decimal-escape': 'error',
44-
'no-obj-calls': 'error',
45-
'no-octal': 'error',
46-
'no-prototype-builtins': 'error',
47-
'no-redeclare': 'error',
48-
'no-regex-spaces': 'error',
49-
'no-self-assign': 'error',
50-
'no-setter-return': 'error',
51-
'no-shadow': 'error',
52-
'no-shadow-restricted-names': 'error',
53-
'no-sparse-arrays': 'error',
54-
'no-this-before-super': 'error',
55-
'no-unreachable': 'error',
56-
'no-unsafe-finally': 'error',
57-
'no-unsafe-negation': 'error',
58-
'no-unsafe-optional-chaining': 'error',
59-
'no-unused-labels': 'error',
60-
'no-unused-private-class-members': 'error',
61-
'no-unused-vars': 'error',
62-
'no-useless-backreference': 'error',
63-
'no-useless-catch': 'error',
64-
'no-useless-escape': 'error',
65-
/** Prefer let and const */
66-
'no-var': 'error',
67-
'no-with': 'error',
68-
/** Prefer const if never re-assigned */
69-
'prefer-const': 'error',
70-
'require-yield': 'error',
71-
/** Stylistic consistency */
72-
'sort-imports': ['error', { ignoreDeclarationSort: true }],
73-
'use-isnan': 'error',
74-
/** Enforce comparing typeof against valid strings */
75-
'valid-typeof': 'error',
76-
},
5+
/** Constructors of derived classes must call super() */
6+
'constructor-super': 'error',
7+
/** TODO */
8+
'for-direction': 'error',
9+
'getter-return': 'error',
10+
'no-async-promise-executor': 'error',
11+
'no-case-declarations': 'error',
12+
'no-class-assign': 'error',
13+
'no-compare-neg-zero': 'error',
14+
'no-cond-assign': 'error',
15+
'no-const-assign': 'error',
16+
'no-constant-binary-expression': 'error',
17+
'no-constant-condition': 'error',
18+
'no-control-regex': 'error',
19+
'no-debugger': 'error',
20+
'no-delete-var': 'error',
21+
'no-dupe-args': 'error',
22+
'no-dupe-class-members': 'error',
23+
'no-dupe-else-if': 'error',
24+
'no-dupe-keys': 'error',
25+
'no-duplicate-case': 'error',
26+
'no-empty': 'error',
27+
'no-empty-character-class': 'error',
28+
'no-empty-pattern': 'error',
29+
'no-empty-static-block': 'error',
30+
'no-ex-assign': 'error',
31+
'no-extra-boolean-cast': 'error',
32+
'no-fallthrough': 'error',
33+
'no-func-assign': 'error',
34+
'no-global-assign': 'error',
35+
'no-import-assign': 'error',
36+
'no-invalid-regexp': 'error',
37+
'no-irregular-whitespace': 'error',
38+
'no-loss-of-precision': 'error',
39+
'no-misleading-character-class': 'error',
40+
'no-new-native-nonconstructor': 'error',
41+
'no-nonoctal-decimal-escape': 'error',
42+
'no-obj-calls': 'error',
43+
'no-octal': 'error',
44+
'no-prototype-builtins': 'error',
45+
'no-redeclare': 'error',
46+
'no-regex-spaces': 'error',
47+
'no-self-assign': 'error',
48+
'no-setter-return': 'error',
49+
'no-shadow': 'error',
50+
'no-shadow-restricted-names': 'error',
51+
'no-sparse-arrays': 'error',
52+
'no-this-before-super': 'error',
53+
'no-unreachable': 'error',
54+
'no-unsafe-finally': 'error',
55+
'no-unsafe-negation': 'error',
56+
'no-unsafe-optional-chaining': 'error',
57+
'no-unused-labels': 'error',
58+
'no-unused-private-class-members': 'error',
59+
'no-unused-vars': 'error',
60+
'no-useless-backreference': 'error',
61+
'no-useless-catch': 'error',
62+
'no-useless-escape': 'error',
63+
/** Prefer let and const */
64+
'no-var': 'error',
65+
'no-with': 'error',
66+
/** Prefer const if never re-assigned */
67+
'prefer-const': 'error',
68+
'require-yield': 'error',
69+
/** Stylistic consistency */
70+
'sort-imports': ['error', { ignoreDeclarationSort: true }],
71+
'use-isnan': 'error',
72+
/** Enforce comparing typeof against valid strings */
73+
'valid-typeof': 'error',
7774
}

src/eslint/typescript.js

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
11
// https://typescript-eslint.io/rules/
22

3-
/** @type {import('eslint').Linter.FlatConfig} */
3+
/** @type {import('eslint').Linter.RulesRecord} */
44
export const typescriptRules = {
5-
name: 'tanstack/typescript',
6-
rules: {
7-
/** Prefer Array<T> format */
8-
'ts/array-type': ['error', { default: 'generic', readonly: 'generic' }],
9-
/** Prevent @ts-ignore, allow @ts-expect-error */
10-
'ts/ban-ts-comment': ['error', { 'ts-expect-error': false }],
11-
/** Bans specific built-in types and can suggest alternatives */
12-
'ts/ban-types': 'error',
13-
/** Enforce import type { T } */
14-
'ts/consistent-type-imports': ['error', { prefer: 'type-imports' }],
15-
/** Shorthand method style is less strict */
16-
'ts/method-signature-style': ['error', 'property'],
17-
/** Enforces generic type convention */
18-
'ts/naming-convention': [
19-
'error',
20-
{
21-
selector: 'typeParameter',
22-
format: ['PascalCase'],
23-
leadingUnderscore: 'forbid',
24-
trailingUnderscore: 'forbid',
25-
custom: {
26-
regex: '^(T|T[A-Z][A-Za-z]+)$',
27-
match: true,
28-
},
5+
/** Prefer Array<T> format */
6+
'ts/array-type': ['error', { default: 'generic', readonly: 'generic' }],
7+
/** Prevent @ts-ignore, allow @ts-expect-error */
8+
'ts/ban-ts-comment': ['error', { 'ts-expect-error': false }],
9+
/** Bans specific built-in types and can suggest alternatives */
10+
'ts/ban-types': 'error',
11+
/** Enforce import type { T } */
12+
'ts/consistent-type-imports': ['error', { prefer: 'type-imports' }],
13+
/** Shorthand method style is less strict */
14+
'ts/method-signature-style': ['error', 'property'],
15+
/** Enforces generic type convention */
16+
'ts/naming-convention': [
17+
'error',
18+
{
19+
selector: 'typeParameter',
20+
format: ['PascalCase'],
21+
leadingUnderscore: 'forbid',
22+
trailingUnderscore: 'forbid',
23+
custom: {
24+
regex: '^(T|T[A-Z][A-Za-z]+)$',
25+
match: true,
2926
},
30-
],
31-
/** Duplicate values can lead to bugs that are hard to track down */
32-
'ts/no-duplicate-enum-values': 'error',
33-
/** Using the operator any more than once does nothing */
34-
'ts/no-extra-non-null-assertion': 'error',
35-
/** There are several potential bugs with this compared to other loops */
36-
'ts/no-for-in-array': 'error',
37-
/** Enforce valid definition of new and constructor */
38-
'ts/no-misused-new': 'error',
39-
/** Disallow TypeScript namespaces */
40-
'ts/no-namespace': 'error',
41-
/** Disallow non-null assertions after an optional chain expression */
42-
'ts/no-non-null-asserted-optional-chain': 'error',
43-
/** Detects conditionals which will always evaluate truthy or falsy */
44-
'ts/no-unnecessary-condition': 'error',
45-
/** Checks if the the explicit type is identical to the inferred type */
46-
'ts/no-unnecessary-type-assertion': 'error',
47-
/** Don't over-define types for simple things like strings */
48-
'ts/no-inferrable-types': ['error', { ignoreParameters: true }],
49-
/** Enforce the use of as const over literal type */
50-
'ts/prefer-as-const': 'error',
51-
/** From recommended preset */
52-
'ts/prefer-for-of': 'error',
53-
/** Disallow async functions which have no await expression */
54-
'ts/require-await': 'error',
55-
/** Prefer of ES6-style import declarations */
56-
'ts/triple-slash-reference': 'error',
57-
},
27+
},
28+
],
29+
/** Duplicate values can lead to bugs that are hard to track down */
30+
'ts/no-duplicate-enum-values': 'error',
31+
/** Using the operator any more than once does nothing */
32+
'ts/no-extra-non-null-assertion': 'error',
33+
/** There are several potential bugs with this compared to other loops */
34+
'ts/no-for-in-array': 'error',
35+
/** Enforce valid definition of new and constructor */
36+
'ts/no-misused-new': 'error',
37+
/** Disallow TypeScript namespaces */
38+
'ts/no-namespace': 'error',
39+
/** Disallow non-null assertions after an optional chain expression */
40+
'ts/no-non-null-asserted-optional-chain': 'error',
41+
/** Detects conditionals which will always evaluate truthy or falsy */
42+
'ts/no-unnecessary-condition': 'error',
43+
/** Checks if the the explicit type is identical to the inferred type */
44+
'ts/no-unnecessary-type-assertion': 'error',
45+
/** Don't over-define types for simple things like strings */
46+
'ts/no-inferrable-types': ['error', { ignoreParameters: true }],
47+
/** Enforce the use of as const over literal type */
48+
'ts/prefer-as-const': 'error',
49+
/** From recommended preset */
50+
'ts/prefer-for-of': 'error',
51+
/** Disallow async functions which have no await expression */
52+
'ts/require-await': 'error',
53+
/** Prefer of ES6-style import declarations */
54+
'ts/triple-slash-reference': 'error',
5855
}

0 commit comments

Comments
 (0)