Skip to content

Commit da00a44

Browse files
authored
chore(lint): setup typescript-eslint (#2960)
1 parent 3a1b5e5 commit da00a44

File tree

8 files changed

+79
-47
lines changed

8 files changed

+79
-47
lines changed

docs/.eslintrc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/.vitepress/config.mts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import './build-system/build.mjs'
1010

1111
const dirname = path.dirname(fileURLToPath(import.meta.url))
1212

13+
// eslint-disable-next-line unicorn/no-anonymous-default-export
1314
export default async () => {
1415
const rulesPath = '../../tools/lib/rules.js' // Avoid bundle
1516
const rules: typeof import('../../tools/lib/rules.js') = await import(
@@ -87,12 +88,10 @@ export default async () => {
8788
)
8889
return !exists
8990
})
90-
.map(({ ruleId, name }) => {
91-
return {
92-
text: ruleId,
93-
link: `/rules/${name}`
94-
}
95-
})
91+
.map(({ ruleId, name }) => ({
92+
text: ruleId,
93+
link: `/rules/${name}`
94+
}))
9695

9796
if (children.length === 0) {
9897
continue

docs/.vitepress/theme/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// @ts-expect-error -- Browser
2-
if (typeof window !== 'undefined') {
3-
if (typeof require === 'undefined') {
4-
// @ts-expect-error -- Browser
5-
;(window as any).require = () => {
6-
const e = new Error('require is not defined')
7-
;(e as any).code = 'MODULE_NOT_FOUND'
8-
throw e
9-
}
2+
if (typeof window !== 'undefined' && typeof require === 'undefined') {
3+
// @ts-expect-error -- Browser
4+
;(window as any).require = () => {
5+
const e = new Error('require is not defined')
6+
;(e as any).code = 'MODULE_NOT_FOUND'
7+
throw e
108
}
119
}
1210
// @ts-expect-error -- Cannot change `module` option

docs/.vitepress/vite-plugin.mts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const libRoot = path.join(fileURLToPath(import.meta.url), '../../../lib')
1111
export function vitePluginRequireResolve(): Plugin {
1212
return {
1313
name: 'vite-plugin-require.resolve',
14-
transform(code, id, _options) {
14+
transform(code, id) {
1515
if (id.startsWith(libRoot)) {
1616
return code.replace(/require\.resolve/gu, '(function(){return 0})')
1717
}
@@ -34,8 +34,9 @@ export function viteCommonjs(): Plugin {
3434
format: 'esm'
3535
})
3636
return transformed.code
37-
} catch (e) {
38-
console.error('Transform error. base code:\n' + base, e)
37+
} catch (error) {
38+
// eslint-disable-next-line no-console
39+
console.error(`Transform error. base code:\n${base}`, error)
3940
}
4041
return undefined
4142
}
@@ -58,24 +59,26 @@ function transformRequire(code: string) {
5859
}
5960

6061
let id =
62+
// eslint-disable-next-line prefer-template
6163
'__' +
6264
moduleString.replace(/[^a-zA-Z0-9_$]+/gu, '_') +
63-
Math.random().toString(32).substring(2)
65+
Math.random().toString(32).slice(2)
6466
while (code.includes(id) || modules.has(id)) {
65-
id += Math.random().toString(32).substring(2)
67+
id += Math.random().toString(32).slice(2)
6668
}
6769
modules.set(id, moduleString)
68-
return id + '()'
70+
return `${id}()`
6971
}
7072
)
7173

7274
return (
75+
// eslint-disable-next-line prefer-template
7376
[...modules]
74-
.map(([id, moduleString]) => {
75-
return `import * as __temp_${id} from ${moduleString};
77+
.map(
78+
([id, moduleString]) => `import * as __temp_${id} from ${moduleString};
7679
const ${id} = () => __temp_${id}.default || __temp_${id};
7780
`
78-
})
81+
)
7982
.join('') +
8083
';\n' +
8184
replaced

eslint.config.mjs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
77
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
88
import eslintMarkdown from '@eslint/markdown'
99
import eslintPluginMarkdownPreferences from 'eslint-plugin-markdown-preferences'
10+
import eslintPluginTs from '@typescript-eslint/eslint-plugin'
11+
import tsEslintParser from '@typescript-eslint/parser'
1012
import vueEslintParser from 'vue-eslint-parser'
1113
import noInvalidMeta from './eslint-internal-rules/no-invalid-meta.js'
1214
import noInvalidMetaDocsCategories from './eslint-internal-rules/no-invalid-meta-docs-categories.js'
@@ -50,6 +52,7 @@ export default typegen([
5052
{
5153
ignores: [
5254
'.nyc_output',
55+
'eslint-typegen.d.ts',
5356
'coverage',
5457
'node_modules',
5558
'.changeset/**/*.md',
@@ -78,7 +81,7 @@ export default typegen([
7881
}
7982
},
8083
...defineConfig({
81-
files: ['**/*.js'],
84+
files: ['**/*.{js,mjs,ts,mts}'],
8285
extends: [
8386
eslintPluginEslintPlugin,
8487
eslintPluginUnicorn.configs['flat/recommended']
@@ -105,7 +108,21 @@ export default typegen([
105108
}),
106109

107110
{
108-
files: ['**/*.js'],
111+
name: 'typescript/setup',
112+
files: ['**/*.{ts,mts}'],
113+
languageOptions: {
114+
parser: tsEslintParser,
115+
parserOptions: {
116+
sourceType: 'module'
117+
}
118+
},
119+
plugins: {
120+
'@typescript-eslint': eslintPluginTs
121+
}
122+
},
123+
124+
{
125+
files: ['**/*.{js,mjs,ts,mts}'],
109126
languageOptions: {
110127
ecmaVersion: 'latest',
111128
sourceType: 'commonjs',
@@ -249,6 +266,35 @@ export default typegen([
249266
'internal/require-eslint-community': ['error']
250267
}
251268
},
269+
270+
{
271+
files: ['**/*.{mjs,ts,mts}'],
272+
languageOptions: {
273+
sourceType: 'module'
274+
}
275+
},
276+
277+
{
278+
files: ['**/*.{ts,mts}'],
279+
rules: {
280+
...eslintPluginTs.configs.strict.rules,
281+
...eslintPluginTs.configs['flat/eslint-recommended'].rules,
282+
'no-redeclare': 'off',
283+
'@typescript-eslint/no-redeclare': 'error',
284+
'@typescript-eslint/no-explicit-any': 'off',
285+
'@typescript-eslint/no-empty-object-type': 'off',
286+
'@typescript-eslint/no-namespace': 'off',
287+
'@typescript-eslint/triple-slash-reference': 'off',
288+
'@typescript-eslint/unified-signatures': 'off',
289+
'@typescript-eslint/ban-ts-comment': [
290+
'error',
291+
{
292+
minimumDescriptionLength: 3
293+
}
294+
]
295+
}
296+
},
297+
252298
{
253299
files: ['./**/*.vue'],
254300
languageOptions: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"@types/node": "^24.0.8",
9191
"@types/semver": "^7.5.8",
9292
"@types/xml-name-validator": "^4.0.3",
93+
"@typescript-eslint/eslint-plugin": "^8.35.1",
9394
"@typescript-eslint/parser": "^8.35.1",
9495
"@typescript-eslint/types": "^8.35.1",
9596
"@vitest/coverage-v8": "^3.2.4",

typings/eslint-plugin-vue/util-types/ast/es-ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export interface PrivateIdentifier extends HasParentNode {
351351
}
352352
export interface Literal extends HasParentNode {
353353
type: 'Literal'
354-
value: string | boolean | null | number | RegExp | BigInt
354+
value: string | boolean | null | number | RegExp | bigint
355355
raw: string
356356
regex?: {
357357
pattern: string

vitest.config.mts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
import { defineConfig } from 'vitest/config'
12

2-
import { defineConfig } from 'vitest/config';
33
export default defineConfig({
44
test: {
5-
include: [
6-
'tests/lib/**/*.js',
7-
'tests/integrations/**/*.js'
8-
],
5+
include: ['tests/lib/**/*.js', 'tests/integrations/**/*.js'],
96
exclude: [
107
'**/node_modules/**',
118
'**/dist/**',
@@ -18,15 +15,10 @@ export default defineConfig({
1815
coverage: {
1916
provider: 'v8',
2017
include: ['lib/**/*.js'],
21-
exclude: [
22-
'tests/**',
23-
'dist/**',
24-
'tools/**',
25-
'node_modules/**'
26-
],
18+
exclude: ['tests/**', 'dist/**', 'tools/**', 'node_modules/**'],
2719
reporter: ['text', 'lcov', 'json-summary', 'html'],
2820
all: true,
2921
reportsDirectory: './coverage'
30-
},
31-
},
32-
});
22+
}
23+
}
24+
})

0 commit comments

Comments
 (0)