Skip to content

Commit e58a4f0

Browse files
authored
chore: enable @typescript-eslint/ban-ts-comment (#11326)
1 parent dcc0004 commit e58a4f0

27 files changed

+74
-81
lines changed

.eslintrc.cjs

+11-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = defineConfig({
6161
'node/no-unpublished-require': 'off',
6262
'node/no-unsupported-features/es-syntax': 'off',
6363

64-
'@typescript-eslint/ban-ts-comment': 'off', // TODO: we should turn this on in a new PR
64+
'@typescript-eslint/ban-ts-comment': 'error',
6565
'@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR
6666
'@typescript-eslint/explicit-module-boundary-types': [
6767
'error',
@@ -185,6 +185,16 @@ module.exports = defineConfig({
185185
'@typescript-eslint/no-empty-function': 'off',
186186
},
187187
},
188+
{
189+
files: [
190+
'playground/tsconfig-json/**',
191+
'playground/tsconfig-json-load-error/**',
192+
],
193+
excludedFiles: '**/__tests__/**',
194+
rules: {
195+
'@typescript-eslint/ban-ts-comment': 'off',
196+
},
197+
},
188198
{
189199
files: ['*.js', '*.mjs', '*.cjs'],
190200
rules: {

packages/plugin-legacy/src/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import type {
1818
PreRenderedChunk,
1919
RenderedChunk,
2020
} from 'rollup'
21-
import type { PluginItem as BabelPlugin } from '@babel/core'
21+
import type {
22+
PluginItem as BabelPlugin,
23+
types as BabelTypes,
24+
} from '@babel/core'
2225
import colors from 'picocolors'
2326
import type { Options } from './types'
2427

@@ -387,23 +390,22 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
387390
return null
388391
}
389392

390-
// @ts-ignore avoid esbuild transform on legacy chunks since it produces
393+
// @ts-expect-error avoid esbuild transform on legacy chunks since it produces
391394
// legacy-unsafe code - e.g. rewriting object properties into shorthands
392395
opts.__vite_skip_esbuild__ = true
393396

394-
// @ts-ignore force terser for legacy chunks. This only takes effect if
397+
// @ts-expect-error force terser for legacy chunks. This only takes effect if
395398
// minification isn't disabled, because that leaves out the terser plugin
396399
// entirely.
397400
opts.__vite_force_terser__ = true
398401

399-
// @ts-ignore
400-
// In the `generateBundle` hook,
402+
// @ts-expect-error In the `generateBundle` hook,
401403
// we'll delete the assets from the legacy bundle to avoid emitting duplicate assets.
402404
// But that's still a waste of computing resource.
403405
// So we add this flag to avoid emitting the asset in the first place whenever possible.
404406
opts.__vite_skip_asset_emit__ = true
405407

406-
// @ts-ignore avoid emitting assets for legacy bundle
408+
// avoid emitting assets for legacy bundle
407409
const needPolyfills =
408410
options.polyfills !== false && !Array.isArray(options.polyfills)
409411

@@ -752,12 +754,11 @@ function isLegacyBundle(
752754
function recordAndRemovePolyfillBabelPlugin(
753755
polyfills: Set<string>,
754756
): BabelPlugin {
755-
return ({ types: t }): BabelPlugin => ({
757+
return ({ types: t }: { types: typeof BabelTypes }): BabelPlugin => ({
756758
name: 'vite-remove-polyfill-import',
757759
post({ path }) {
758760
path.get('body').forEach((p) => {
759-
if (t.isImportDeclaration(p)) {
760-
// @ts-expect-error
761+
if (t.isImportDeclaration(p.node)) {
761762
polyfills.add(p.node.source.value)
762763
p.remove()
763764
}

packages/vite/src/node/__tests__/plugins/css.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async function createCssPluginTransform(
209209
const config = await resolveConfig(inlineConfig, 'serve')
210210
const { transform, buildStart } = cssPlugin(config)
211211

212-
// @ts-expect-error
212+
// @ts-expect-error buildStart is function
213213
await buildStart.call({})
214214

215215
const mockFs = vi
@@ -221,7 +221,7 @@ async function createCssPluginTransform(
221221

222222
return {
223223
async transform(code: string, id: string) {
224-
// @ts-expect-error
224+
// @ts-expect-error transform is function
225225
return await transform.call(
226226
{
227227
addWatchFile() {

packages/vite/src/node/build.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ async function doBuild(
546546

547547
try {
548548
const buildOutputOptions = (output: OutputOptions = {}): OutputOptions => {
549-
// See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
550-
// @ts-ignore
549+
// @ts-expect-error See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
551550
if (output.output) {
552551
config.logger.warn(
553552
`You've set "rollupOptions.output.output" in your config. ` +

packages/vite/src/node/cli.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'node:path'
22
import fs from 'node:fs'
33
import { performance } from 'node:perf_hooks'
4-
import type { Session } from 'node:inspector'
54
import { cac } from 'cac'
65
import colors from 'picocolors'
76
import type { BuildOptions } from './build'
@@ -32,8 +31,7 @@ interface GlobalCLIOptions {
3231
force?: boolean
3332
}
3433

35-
// @ts-ignore
36-
let profileSession: Session | undefined = global.__vite_profile_session
34+
let profileSession = global.__vite_profile_session
3735
let profileCount = 0
3836

3937
export const stopProfiler = (
@@ -141,7 +139,6 @@ cli
141139

142140
const info = server.config.logger.info
143141

144-
// @ts-ignore
145142
const viteStartTime = global.__vite_start_time ?? false
146143
const startupDurationString = viteStartTime
147144
? colors.dim(

packages/vite/src/node/config.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -462,18 +462,13 @@ export async function resolveConfig(
462462
)
463463

464464
const clientAlias = [
465-
{ find: /^\/?@vite\/env/, replacement: () => ENV_ENTRY },
466-
{ find: /^\/?@vite\/client/, replacement: () => CLIENT_ENTRY },
465+
{ find: /^\/?@vite\/env/, replacement: ENV_ENTRY },
466+
{ find: /^\/?@vite\/client/, replacement: CLIENT_ENTRY },
467467
]
468468

469469
// resolve alias with internal client alias
470470
const resolvedAlias = normalizeAlias(
471-
mergeAlias(
472-
// @ts-ignore because @rollup/plugin-alias' type doesn't allow function
473-
// replacement, but its implementation does work with function values.
474-
clientAlias,
475-
config.resolve?.alias || [],
476-
),
471+
mergeAlias(clientAlias, config.resolve?.alias || []),
477472
)
478473

479474
const resolveOptions: ResolvedConfig['resolve'] = {

packages/vite/src/node/optimizer/optimizer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ async function createDepsOptimizer(
466466
}
467467

468468
currentlyProcessing = false
469-
// @ts-ignore
469+
// @ts-expect-error `enqueuedRerun` could exist because `debouncedProcessing` may run while awaited
470470
enqueuedRerun?.()
471471
}
472472

packages/vite/src/node/plugins/css.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
623623
},
624624

625625
async generateBundle(opts, bundle) {
626-
// @ts-ignore asset emits are skipped in legacy bundle
626+
// @ts-expect-error asset emits are skipped in legacy bundle
627627
if (opts.__vite_skip_asset_emit__) {
628628
return
629629
}
@@ -1149,7 +1149,6 @@ async function resolvePostcssConfig(
11491149
const searchPath =
11501150
typeof inlineOptions === 'string' ? inlineOptions : config.root
11511151
try {
1152-
// @ts-ignore
11531152
result = await postcssrc({}, searchPath)
11541153
} catch (e) {
11551154
if (!/No PostCSS Config found/.test(e.message)) {
@@ -1508,6 +1507,9 @@ function loadPreprocessor(
15081507
}
15091508
}
15101509

1510+
declare const window: unknown | undefined
1511+
declare const location: { href: string } | undefined
1512+
15111513
// in unix, scss might append `location.href` in environments that shim `location`
15121514
// see https://github.com/sass/dart-sass/issues/710
15131515
function cleanScssBugUrl(url: string) {
@@ -1533,12 +1535,10 @@ function fixScssBugImportValue(
15331535
typeof window !== 'undefined' &&
15341536
typeof location !== 'undefined' &&
15351537
data &&
1536-
// @ts-expect-error
1537-
data.file &&
1538-
// @ts-expect-error
1539-
data.contents == null
1538+
'file' in data &&
1539+
(!('contents' in data) || data.contents == null)
15401540
) {
1541-
// @ts-expect-error
1541+
// @ts-expect-error we need to preserve file property for HMR
15421542
data.contents = fs.readFileSync(data.file, 'utf-8')
15431543
}
15441544
return data

packages/vite/src/node/plugins/esbuild.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export async function transformWithEsbuild(
112112

113113
for (const field of meaningfulFields) {
114114
if (field in loadedCompilerOptions) {
115-
// @ts-ignore TypeScript can't tell they are of the same type
115+
// @ts-expect-error TypeScript can't tell they are of the same type
116116
compilerOptionsForFile[field] = loadedCompilerOptions[field]
117117
}
118118
}
@@ -297,7 +297,7 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {
297297
await initTSConfck(config)
298298
},
299299
async renderChunk(code, chunk, opts) {
300-
// @ts-ignore injected by @vitejs/plugin-legacy
300+
// @ts-expect-error injected by @vitejs/plugin-legacy
301301
if (opts.__vite_skip_esbuild__) {
302302
return null
303303
}

packages/vite/src/node/plugins/importAnalysisBuild.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,20 @@ function toRelativePath(filename: string, importer: string) {
5252
*/
5353

5454
function detectScriptRel() {
55-
// @ts-ignore
5655
const relList = document.createElement('link').relList
57-
// @ts-ignore
5856
return relList && relList.supports && relList.supports('modulepreload')
5957
? 'modulepreload'
6058
: 'preload'
6159
}
6260

6361
declare const scriptRel: string
62+
declare const seen: Record<string, boolean>
6463
function preload(
6564
baseModule: () => Promise<{}>,
6665
deps?: string[],
6766
importerUrl?: string,
6867
) {
69-
// @ts-ignore
68+
// @ts-expect-error __VITE_IS_MODERN__ will be replaced with boolean later
7069
if (!__VITE_IS_MODERN__ || !deps || deps.length === 0) {
7170
return baseModule()
7271
}
@@ -75,11 +74,9 @@ function preload(
7574

7675
return Promise.all(
7776
deps.map((dep) => {
78-
// @ts-ignore
77+
// @ts-expect-error assetsURL is declared before preload.toString()
7978
dep = assetsURL(dep, importerUrl)
80-
// @ts-ignore
8179
if (dep in seen) return
82-
// @ts-ignore
8380
seen[dep] = true
8481
const isCss = dep.endsWith('.css')
8582
const cssSelector = isCss ? '[rel="stylesheet"]' : ''
@@ -101,16 +98,13 @@ function preload(
10198
return
10299
}
103100

104-
// @ts-ignore
105101
const link = document.createElement('link')
106-
// @ts-ignore
107102
link.rel = isCss ? 'stylesheet' : scriptRel
108103
if (!isCss) {
109104
link.as = 'script'
110105
link.crossOrigin = ''
111106
}
112107
link.href = dep
113-
// @ts-ignore
114108
document.head.appendChild(link)
115109
if (isCss) {
116110
return new Promise((res, rej) => {

packages/vite/src/node/plugins/terser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
4949
// can use terser.
5050
if (
5151
config.build.minify !== 'terser' &&
52-
// @ts-ignore injected by @vitejs/plugin-legacy
52+
// @ts-expect-error injected by @vitejs/plugin-legacy
5353
!outputOptions.__vite_force_terser__
5454
) {
5555
return null

packages/vite/src/node/plugins/wasm.ts

-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const wasmHelper = async (opts = {}, url: string) => {
1212
if (typeof Buffer === 'function' && typeof Buffer.from === 'function') {
1313
bytes = Buffer.from(urlContent, 'base64')
1414
} else if (typeof atob === 'function') {
15-
// @ts-ignore
1615
const binaryString = atob(urlContent)
1716
bytes = new Uint8Array(binaryString.length)
1817
for (let i = 0; i < binaryString.length; i++) {
@@ -23,27 +22,22 @@ const wasmHelper = async (opts = {}, url: string) => {
2322
'Failed to decode base64-encoded data URL, Buffer and atob are not supported',
2423
)
2524
}
26-
// @ts-ignore
2725
result = await WebAssembly.instantiate(bytes, opts)
2826
} else {
2927
// https://github.com/mdn/webassembly-examples/issues/5
3028
// WebAssembly.instantiateStreaming requires the server to provide the
3129
// correct MIME type for .wasm files, which unfortunately doesn't work for
3230
// a lot of static file servers, so we just work around it by getting the
3331
// raw buffer.
34-
// @ts-ignore
3532
const response = await fetch(url)
3633
const contentType = response.headers.get('Content-Type') || ''
3734
if (
38-
// @ts-ignore
3935
'instantiateStreaming' in WebAssembly &&
4036
contentType.startsWith('application/wasm')
4137
) {
42-
// @ts-ignore
4338
result = await WebAssembly.instantiateStreaming(response, opts)
4439
} else {
4540
const buffer = await response.arrayBuffer()
46-
// @ts-ignore
4741
result = await WebAssembly.instantiate(buffer, opts)
4842
}
4943
}

packages/vite/src/node/plugins/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
387387
},
388388

389389
generateBundle(opts) {
390-
// @ts-ignore asset emits are skipped in legacy bundle
390+
// @ts-expect-error asset emits are skipped in legacy bundle
391391
if (opts.__vite_skip_asset_emit__ || isWorker) {
392392
return
393393
}

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ async function getPluginContainer(
157157
'serve',
158158
)
159159

160-
// @ts-ignore: This plugin requires a ViteDevServer instance.
160+
// @ts-expect-error This plugin requires a ViteDevServer instance.
161161
config.plugins = config.plugins.filter((p) => !/pre-alias/.test(p.name))
162162

163163
resolveId = (id) => container.resolveId(id)

packages/vite/src/node/server/index.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ export function resolveServerOptions(
772772
}
773773

774774
async function restartServer(server: ViteDevServer) {
775-
// @ts-ignore
776775
global.__vite_start_time = performance.now()
777776
const { port: prevPort, host: prevHost } = server.config.server
778777
const shortcutsOptions: BindShortcutsOptions = server._shortcutsOptions
@@ -798,16 +797,10 @@ async function restartServer(server: ViteDevServer) {
798797
return
799798
}
800799

801-
for (const key in newServer) {
802-
if (key === '_restartPromise') {
803-
// prevent new server `restart` function from calling
804-
// @ts-ignore
805-
newServer[key] = server[key]
806-
} else {
807-
// @ts-ignore
808-
server[key] = newServer[key]
809-
}
810-
}
800+
// prevent new server `restart` function from calling
801+
newServer._restartPromise = server._restartPromise
802+
803+
Object.assign(server, newServer)
811804

812805
const {
813806
logger,

packages/vite/src/node/server/middlewares/compression.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//@ts-nocheck
21
/* eslint-disable */
2+
//@ts-nocheck
33
//TODO: replace this code with https://github.com/lukeed/polka/pull/148 once it's released
44

55
// This is based on https://github.com/preactjs/wmr/blob/main/packages/wmr/src/lib/polkompress.js
@@ -44,7 +44,6 @@ export default function compression() {
4444

4545
function start() {
4646
started = true
47-
// @ts-ignore
4847
size = res.getHeader('Content-Length') | 0 || size
4948
const compressible = mimes.test(
5049
String(res.getHeader('Content-Type') || 'text/plain'),

packages/vite/src/node/server/middlewares/time.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ export function timeMiddleware(root: string): Connect.NextHandleFunction {
99
return function viteTimeMiddleware(req, res, next) {
1010
const start = performance.now()
1111
const end = res.end
12-
res.end = (...args: any[]) => {
12+
res.end = (...args: readonly [any, any?, any?]) => {
1313
logTime(`${timeFrom(start)} ${prettifyUrl(req.url!, root)}`)
14-
// @ts-ignore
1514
return end.call(res, ...args)
1615
}
1716
next()

0 commit comments

Comments
 (0)