Skip to content

Commit ce8c357

Browse files
committed
chore: enable isolatedDeclarations
1 parent f772f1a commit ce8c357

File tree

8 files changed

+33
-52
lines changed

8 files changed

+33
-52
lines changed

src/cli/constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import c from 'picocolors'
22
import { devDependencies, version } from '../../package.json'
33

4-
export const ARROW = c.cyan('→')
5-
export const CHECK = c.green('✔')
6-
export const CROSS = c.red('✘')
7-
export const WARN = c.yellow('ℹ')
4+
export const ARROW: string = c.cyan('→')
5+
export const CHECK: string = c.green('✔')
6+
export const CROSS: string = c.red('✘')
7+
export const WARN: string = c.yellow('ℹ')
88

9-
export const eslintVersion = devDependencies.eslint
9+
export const eslintVersion: string = devDependencies.eslint
1010
export { version }
1111

1212
export const vscodeSettingsString = `

src/cli/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface RuleOptions {
2424
yes?: boolean
2525
}
2626

27-
export async function run(options: RuleOptions = {}) {
27+
export async function run(options: RuleOptions = {}): Promise<void> {
2828
const SKIP_PROMPT = !!process.env.SKIP_PROMPT || options.yes
2929
const SKIP_GIT_CHECK = !!process.env.SKIP_GIT_CHECK
3030

src/cli/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execSync } from 'node:child_process'
22

3-
export function isGitClean() {
3+
export function isGitClean(): boolean {
44
try {
55
execSync('git diff-index --quiet HEAD --')
66
return true

src/constants/glob.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ export const GLOB_YAML = '**/*.y?(a)ml'
3131
export const GLOB_TOML = '**/*.toml'
3232
export const GLOB_GRAPHQL = '**/*.{g,graph}ql'
3333

34-
export const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`
34+
export const GLOB_MARKDOWN_CODE: string = `${GLOB_MARKDOWN}/${GLOB_SRC}`
3535

3636
export const GLOB_TS_CONFIG = '**/tsconfig.json'
3737
export const GLOB_TS_OTHER_CONFIG = '**/tsconfig.*.json'
3838

39-
export const GLOB_TESTS = [
39+
export const GLOB_TESTS: string[] = [
4040
`**/__tests__/**/*.${GLOB_SRC_EXT}`,
4141
`**/*.spec.${GLOB_SRC_EXT}`,
4242
`**/*.test.${GLOB_SRC_EXT}`,
4343
`**/*.bench.${GLOB_SRC_EXT}`,
4444
`**/*.benchmark.${GLOB_SRC_EXT}`,
4545
]
4646

47-
export const GLOB_ALL_SRC = [
47+
export const GLOB_ALL_SRC: string[] = [
4848
GLOB_SRC,
4949
GLOB_STYLE,
5050
GLOB_JSON,
@@ -55,7 +55,7 @@ export const GLOB_ALL_SRC = [
5555
GLOB_HTML,
5656
]
5757

58-
export const GLOB_EXCLUDE = [
58+
export const GLOB_EXCLUDE: string[] = [
5959
'**/node_modules',
6060
'**/dist',
6161
'**/package-lock.json',

src/env.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import process from 'node:process'
22
import { isPackageExists } from 'local-pkg'
33

4-
export const isInEditor = !!(
4+
export const isInEditor: boolean = !!(
55
(process.env.VSCODE_PID ||
66
process.env.VSCODE_CWD ||
77
process.env.JETBRAINS_IDE ||
88
process.env.VIM ||
99
process.env.NVIM) &&
1010
!process.env.CI
1111
)
12-
export const hasTypeScript = isPackageExists('typescript')
1312

1413
const VueJsPackages = ['vue', 'nuxt', 'vitepress', '@slidev/cli']
1514

16-
export const hasVue = hasPackages(VueJsPackages)
17-
1815
const RemixPackages = [
1916
'@remix-run/node',
2017
'@remix-run/react',
@@ -34,11 +31,13 @@ const NextJsPackages = ['next']
3431
// react refresh
3532
const ReactRefreshAllowConstantExportPackages = ['vite']
3633

34+
export const isUsingTypeScript: boolean = isPackageExists('typescript')
35+
export const isUsingVue: boolean = hasPackages(VueJsPackages)
3736
// export const hasReact = hasPackages(['react', ...RemixPackages, ...NextJsPackages])
38-
export const isUsingRemix = hasPackages(RemixPackages)
39-
export const isUsingReactRouter = hasPackages(ReactRouterPackages)
40-
export const isUsingNext = hasPackages(NextJsPackages)
41-
export const isAllowConstantExport = hasPackages(
37+
export const isUsingRemix: boolean = hasPackages(RemixPackages)
38+
export const isUsingReactRouter: boolean = hasPackages(ReactRouterPackages)
39+
export const isUsingNext: boolean = hasPackages(NextJsPackages)
40+
export const isAllowConstantExport: boolean = hasPackages(
4241
ReactRefreshAllowConstantExportPackages,
4342
)
4443

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
unocss,
2424
vue,
2525
} from './configs'
26-
import { hasTypeScript, hasVue } from './env'
26+
import { isUsingTypeScript, isUsingVue } from './env'
2727
import {
2828
combine,
2929
getOverrides,
@@ -81,9 +81,9 @@ export async function defineConfig(
8181
regexp: enableRegexp = true,
8282
svelte: enableSvelte = false,
8383
tailwindcss: enableTailwindCSS = false,
84-
typescript: enableTypeScript = hasTypeScript,
84+
typescript: enableTypeScript = isUsingTypeScript,
8585
unocss: enableUnoCSS = false,
86-
vue: enableVue = hasVue,
86+
vue: enableVue = isUsingVue,
8787
} = options
8888

8989
let isInEditor = options.isInEditor

src/shared/index.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
import process from 'node:process'
22
import { fileURLToPath } from 'node:url'
33
import { getPackageInfoSync, isPackageExists } from 'local-pkg'
4+
import type { Linter } from 'eslint'
45
import type {
56
Awaitable,
67
OptionsConfig,
78
ResolvedOptions,
89
TypedFlatConfigItem,
910
} from '../types'
11+
import type { RuleOptions } from '../types/typegen'
1012

1113
const scopeUrl = fileURLToPath(new URL('.', import.meta.url))
1214
const isCwdInScope = isPackageExists('@coderwyd/eslint-config')
1315

14-
export const parserPlain = {
15-
meta: {
16-
name: 'parser-plain',
17-
},
18-
parseForESLint: (code: string) => ({
19-
ast: {
20-
body: [],
21-
comments: [],
22-
loc: { end: code.length, start: 0 },
23-
range: [0, code.length],
24-
tokens: [],
25-
type: 'Program',
26-
},
27-
scopeManager: null,
28-
services: { isPlain: true },
29-
visitorKeys: {
30-
Program: [],
31-
},
32-
}),
33-
}
34-
3516
/**
3617
* Combine array and non-array configs into a single array.
3718
*/
@@ -63,7 +44,7 @@ export async function combine(
6344
export function renameRules(
6445
rules: Record<string, any>,
6546
map: Record<string, string>,
66-
) {
47+
): Record<string, any> {
6748
return Object.fromEntries(
6849
Object.entries(rules).map(([key, value]) => {
6950
for (const [from, to] of Object.entries(map)) {
@@ -108,7 +89,7 @@ export function renamePluginInConfigs(
10889
})
10990
}
11091

111-
export function getVueVersion() {
92+
export function getVueVersion(): number {
11293
const pkg = getPackageInfoSync('vue', { paths: [process.cwd()] })
11394
if (pkg && typeof pkg.version === 'string' && !Number.isNaN(+pkg.version[0]))
11495
return +pkg.version[0]
@@ -131,7 +112,7 @@ export function isPackageInScope(name: string): boolean {
131112
return isPackageExists(name, { paths: [scopeUrl] })
132113
}
133114

134-
export async function ensurePackages(packages: string[]) {
115+
export async function ensurePackages(packages: string[]): Promise<void> {
135116
if (
136117
process.env.CI ||
137118
process.stdout.isTTY === false ||
@@ -169,7 +150,7 @@ export function resolveSubOptions<K extends keyof OptionsConfig>(
169150
export function getOverrides<K extends keyof OptionsConfig>(
170151
options: OptionsConfig,
171152
key: K,
172-
) {
153+
): Partial<Linter.RulesRecord & RuleOptions> {
173154
const sub = resolveSubOptions(options, key)
174155
return {
175156
...('overrides' in sub ? sub.overrides || {} : {}),

tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44
"jsx": "preserve",
55
"jsxImportSource": "react",
66
"lib": ["DOM", "ESNext"],
7+
"moduleDetection": "force",
78
"baseUrl": ".",
8-
"module": "ESNext",
9+
"module": "preserve",
910
"moduleResolution": "Bundler",
10-
"paths": {
11-
"@/*": ["./src/*"]
12-
},
1311
"resolveJsonModule": true,
1412
"types": ["node"],
1513
"strict": true,
1614
"strictNullChecks": true,
1715
"noUnusedLocals": true,
16+
"declaration": true,
1817
"outDir": "./dist",
1918
"allowSyntheticDefaultImports": true,
2019
"esModuleInterop": true,
2120
"forceConsistentCasingInFileNames": true,
21+
"isolatedDeclarations": true,
2222
"isolatedModules": true,
23+
"verbatimModuleSyntax": true,
2324
"skipLibCheck": true
2425
},
25-
"include": ["./**/*"],
26+
"include": ["src"],
2627
"exclude": ["node_modules", "dist"]
2728
}

0 commit comments

Comments
 (0)