Skip to content

Commit db1f9e0

Browse files
committed
ci: setup typescript-eslint
1 parent 3a1b5e5 commit db1f9e0

File tree

6 files changed

+70
-50
lines changed

6 files changed

+70
-50
lines changed

docs/.vitepress/config.mts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,10 @@ export default async () => {
8787
)
8888
return !exists
8989
})
90-
.map(({ ruleId, name }) => {
91-
return {
92-
text: ruleId,
93-
link: `/rules/${name}`
94-
}
95-
})
90+
.map(({ ruleId, name }) => ({
91+
text: ruleId,
92+
link: `/rules/${name}`
93+
}))
9694

9795
if (children.length === 0) {
9896
continue

docs/.vitepress/theme/index.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
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
1311
import type { Theme } from 'vitepress'
1412
// @ts-expect-error -- Cannot change `module` option
1513
import DefaultTheme from 'vitepress/theme'
16-
// @ts-expect-error -- ignore
1714
import Layout from './Layout.vue'
18-
// @ts-expect-error -- ignore
1915
import ESLintCodeBlock from './components/eslint-code-block.vue'
20-
// @ts-expect-error -- ignore
2116
import RulesTable from './components/rules-table.vue'
2217

2318
const theme: Theme = {

docs/.vitepress/vite-plugin.mts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ 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+
console.error(`Transform error. base code:\n${base}`, error)
3939
}
4040
return undefined
4141
}
@@ -57,27 +57,23 @@ function transformRequire(code: string) {
5757
return match
5858
}
5959

60-
let id =
61-
'__' +
62-
moduleString.replace(/[^a-zA-Z0-9_$]+/gu, '_') +
63-
Math.random().toString(32).substring(2)
60+
let id = `__${moduleString.replace(
61+
/[^a-zA-Z0-9_$]+/gu,
62+
'_'
63+
)}${Math.random().toString(32).slice(2)}`
6464
while (code.includes(id) || modules.has(id)) {
65-
id += Math.random().toString(32).substring(2)
65+
id += Math.random().toString(32).slice(2)
6666
}
6767
modules.set(id, moduleString)
68-
return id + '()'
68+
return `${id}()`
6969
}
7070
)
7171

72-
return (
73-
[...modules]
74-
.map(([id, moduleString]) => {
75-
return `import * as __temp_${id} from ${moduleString};
72+
return `${[...modules]
73+
.map(
74+
([id, moduleString]) => `import * as __temp_${id} from ${moduleString};
7675
const ${id} = () => __temp_${id}.default || __temp_${id};
7776
`
78-
})
79-
.join('') +
80-
';\n' +
81-
replaced
82-
)
77+
)
78+
.join('')};\n${replaced}`
8379
}

eslint.config.mjs

Lines changed: 40 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'
@@ -46,10 +48,13 @@ const MD_LINKS_FOR_DOCS = {
4648
...MD_BASE_LINKS
4749
}
4850

51+
const GLOB_TS = '**/*.?([cm])ts'
52+
4953
export default typegen([
5054
{
5155
ignores: [
5256
'.nyc_output',
57+
'eslint-typegen.d.ts',
5358
'coverage',
5459
'node_modules',
5560
'.changeset/**/*.md',
@@ -78,7 +83,7 @@ export default typegen([
7883
}
7984
},
8085
...defineConfig({
81-
files: ['**/*.js'],
86+
files: ['**/*.?([cm])[jt]s'],
8287
extends: [
8388
eslintPluginEslintPlugin,
8489
eslintPluginUnicorn.configs['flat/recommended']
@@ -105,7 +110,21 @@ export default typegen([
105110
}),
106111

107112
{
108-
files: ['**/*.js'],
113+
name: 'typescript/setup',
114+
files: [GLOB_TS],
115+
languageOptions: {
116+
parser: tsEslintParser,
117+
parserOptions: {
118+
sourceType: 'module'
119+
}
120+
},
121+
plugins: {
122+
ts: eslintPluginTs
123+
}
124+
},
125+
126+
{
127+
files: ['**/*.?([cm])[jt]s'],
109128
languageOptions: {
110129
ecmaVersion: 'latest',
111130
sourceType: 'commonjs',
@@ -249,6 +268,25 @@ export default typegen([
249268
'internal/require-eslint-community': ['error']
250269
}
251270
},
271+
272+
{
273+
files: ['**/*.mjs'],
274+
languageOptions: {
275+
sourceType: 'module'
276+
}
277+
},
278+
279+
{
280+
files: [GLOB_TS],
281+
rules: {
282+
'no-undef': 'off', // https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
283+
'no-unused-vars': 'off',
284+
'ts/no-unused-vars': 'error',
285+
'no-redeclare': 'off',
286+
'ts/no-redeclare': 'error'
287+
}
288+
},
289+
252290
{
253291
files: ['./**/*.vue'],
254292
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",

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)