Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable @typescript-eslint/explicit-module-boundary-types #8372

Merged
merged 2 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ module.exports = defineConfig({

'@typescript-eslint/ban-ts-comment': 'off', // TODO: we should turn this on in a new PR
'@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR
'@typescript-eslint/explicit-module-boundary-types': [
'error',
{ allowArgumentsExplicitlyTypedAsAny: true }
],
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['arrowFunctions'] }
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export async function detectPolyfills(
code: string,
targets: any,
list: Set<string>
) {
): Promise<void> {
const babel = await loadBabel()
const { ast } = babel.transform(code, {
ast: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ async function loadConfigFromBundledFile(
return config
}

export function isDepsOptimizerEnabled(config: ResolvedConfig) {
export function isDepsOptimizerEnabled(config: ResolvedConfig): boolean {
const { command, optimizeDeps } = config
const { disabled } = optimizeDeps
return !(
Expand Down
18 changes: 13 additions & 5 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,19 +595,22 @@ export function newDepOptimizationProcessing(): DepOptimizationProcessing {
// Convert to { id: src }
export function depsFromOptimizedDepInfo(
depsInfo: Record<string, OptimizedDepInfo>
) {
): Record<string, string> {
return Object.fromEntries(
Object.entries(depsInfo).map((d) => [d[0], d[1].src!])
)
}

export function getOptimizedDepPath(id: string, config: ResolvedConfig) {
export function getOptimizedDepPath(
id: string,
config: ResolvedConfig
): string {
return normalizePath(
path.resolve(getDepsCacheDir(config), flattenId(id) + '.js')
)
}

export function getDepsCacheDir(config: ResolvedConfig) {
export function getDepsCacheDir(config: ResolvedConfig): string {
const dirName = config.command === 'build' ? 'depsBuild' : 'deps'
return normalizePath(path.resolve(config.cacheDir, dirName))
}
Expand All @@ -617,11 +620,16 @@ function getProcessingDepsCacheDir(config: ResolvedConfig) {
return normalizePath(path.resolve(config.cacheDir, dirName))
}

export function isOptimizedDepFile(id: string, config: ResolvedConfig) {
export function isOptimizedDepFile(
id: string,
config: ResolvedConfig
): boolean {
return id.startsWith(getDepsCacheDir(config))
}

export function createIsOptimizedDepUrl(config: ResolvedConfig) {
export function createIsOptimizedDepUrl(
config: ResolvedConfig
): (url: string) => boolean {
const { root } = config
const depsCacheDir = getDepsCacheDir(config)

Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/optimizer/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const debounceMs = 100

const depsOptimizerMap = new WeakMap<ResolvedConfig, DepsOptimizer>()

export function getDepsOptimizer(config: ResolvedConfig) {
export function getDepsOptimizer(
config: ResolvedConfig
): DepsOptimizer | undefined {
// Workers compilation shares the DepsOptimizer from the main build
return depsOptimizerMap.get(config.mainConfig || config)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ async function minifyCSS(css: string, config: ResolvedConfig) {
}
}

export async function hoistAtRules(css: string) {
export async function hoistAtRules(css: string): Promise<string> {
const s = new MagicString(css)
const cleanCss = emptyCssComments(css)
let match: RegExpExecArray | null
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const debug = createDebugger('vite:import-analysis')
const clientDir = normalizePath(CLIENT_DIR)

const skipRE = /\.(map|json)$/
export const canSkipImportAnalysis = (id: string) =>
export const canSkipImportAnalysis = (id: string): boolean =>
skipRE.test(id) || isDirectCSSRequest(id)

const optimizedDepChunkRE = /\/chunk-[A-Z0-9]{8}\.js/
Expand Down
7 changes: 5 additions & 2 deletions packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export interface ParsedImportGlob {
end: number
}

export function getAffectedGlobModules(file: string, server: ViteDevServer) {
export function getAffectedGlobModules(
file: string,
server: ViteDevServer
): ModuleNode[] {
const modules: ModuleNode[] = []
for (const [id, allGlobs] of server._importGlobMap!) {
if (allGlobs.some((glob) => isMatch(file, glob)))
Expand Down Expand Up @@ -501,7 +504,7 @@ export function getCommonBase(globsResolved: string[]): null | string {
return commonAncestor
}

export function isVirtualModule(id: string) {
export function isVirtualModule(id: string): boolean {
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
return id.startsWith('virtual:') || id.startsWith('\0') || !id.includes('/')
}
7 changes: 5 additions & 2 deletions packages/vite/src/node/plugins/optimizedDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function getRunProcessingInfo(config: ResolvedConfig): RunProcessingInfo {
)
}

export function registerWorkersSource(config: ResolvedConfig, id: string) {
export function registerWorkersSource(
config: ResolvedConfig,
id: string
): void {
const info = getRunProcessingInfo(config)
info.workersSources.add(id)
if (info.waitingOn === id) {
Expand All @@ -55,7 +58,7 @@ export function delayDepsOptimizerUntil(
config: ResolvedConfig,
id: string,
done: () => Promise<any>
) {
): void {
const info = getRunProcessingInfo(config)
if (
!getDepsOptimizer(config)?.isOptimizedDepFile(id) &&
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/splitVendorChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SplitVendorChunkCache {
constructor() {
this.cache = new Map<string, boolean>()
}
reset() {
reset(): void {
this.cache = new Map<string, boolean>()
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface HmrContext {
server: ViteDevServer
}

export function getShortName(file: string, root: string) {
export function getShortName(file: string, root: string): string {
return file.startsWith(root + '/') ? path.posix.relative(root, file) : file
}

Expand Down Expand Up @@ -130,7 +130,7 @@ export function updateModules(
modules: ModuleNode[],
timestamp: number,
{ config, ws }: ViteDevServer
) {
): void {
const updates: Update[] = []
const invalidatedModules = new Set<ModuleNode>()
let needFullReload = false
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function injectSourcesContent(
}
}

export function genSourceMapUrl(map: SourceMap | string | undefined) {
export function genSourceMapUrl(map: SourceMap | string | undefined): string {
if (typeof map !== 'string') {
map = JSON.stringify(map)
}
Expand All @@ -70,7 +70,7 @@ export function getCodeWithSourcemap(
type: 'js' | 'css',
code: string,
map: SourceMap | null
) {
): string {
if (isDebug) {
code += `\n/*${JSON.stringify(map, null, 2).replace(/\*\//g, '*\\/')}*/\n`
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const debug = createDebugger('vite:ssr-external')
/**
* Converts "parent > child" syntax to just "child"
*/
export function stripNesting(packages: string[]) {
export function stripNesting(packages: string[]): string[] {
return packages.map((s) => {
const arr = s.split('>')
return arr[arr.length - 1].trim()
Expand Down
10 changes: 5 additions & 5 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ export const isJSRequest = (url: string): boolean => {

const knownTsRE = /\.(ts|mts|cts|tsx)$/
const knownTsOutputRE = /\.(js|mjs|cjs|jsx)$/
export const isTsRequest = (url: string) => knownTsRE.test(url)
export const isPossibleTsOutput = (url: string) =>
export const isTsRequest = (url: string): boolean => knownTsRE.test(url)
export const isPossibleTsOutput = (url: string): boolean =>
knownTsOutputRE.test(cleanUrl(url))
export function getPotentialTsSrcPaths(filePath: string) {
export function getPotentialTsSrcPaths(filePath: string): string[] {
const [name, type, query = ''] = filePath.split(/(\.(?:[cm]?js|jsx))(\?.*)?$/)
const paths = [name + type.replace('js', 'ts') + query]
if (!type.endsWith('x')) {
Expand Down Expand Up @@ -781,7 +781,7 @@ export function parseRequest(id: string): Record<string, string> | null {
return Object.fromEntries(new URLSearchParams(search))
}

export const blankReplacer = (match: string) => ' '.repeat(match.length)
export const blankReplacer = (match: string): string => ' '.repeat(match.length)

export function getHash(text: Buffer | string): string {
return createHash('sha256').update(text).digest('hex').substring(0, 8)
Expand Down Expand Up @@ -856,7 +856,7 @@ function gracefulRemoveDir(
})
}

export function emptyCssComments(raw: string) {
export function emptyCssComments(raw: string): string {
return raw.replace(multilineCommentsRE, (s) => ' '.repeat(s.length))
}

Expand Down
2 changes: 1 addition & 1 deletion playground/legacy/__tests__/ssr/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ports, rootDir } from '~utils'

export const port = ports['legacy/ssr']

export async function serve() {
export async function serve(): Promise<{ close(): Promise<void> }> {
const { build } = await import('vite')
await build({
root: rootDir,
Expand Down
41 changes: 26 additions & 15 deletions scripts/releaseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { existsSync, readdirSync, writeFileSync } from 'fs'
import path from 'path'
import colors from 'picocolors'
import type { Options as ExecaOptions } from 'execa'
import type { Options as ExecaOptions, ExecaReturnValue } from 'execa'
import execa from 'execa'
import type { ReleaseType } from 'semver'
import semver from 'semver'
Expand Down Expand Up @@ -39,19 +39,26 @@ export const versionIncrements: ReleaseType[] = [
// 'prerelease'
]

export function getPackageInfo(pkgName: string) {
interface Pkg {
name: string
version: string
private?: boolean
}
export function getPackageInfo(pkgName: string): {
pkg: Pkg
pkgName: string
pkgDir: string
pkgPath: string
currentVersion: string
} {
const pkgDir = path.resolve(__dirname, '../packages/' + pkgName)

if (!existsSync(pkgDir)) {
throw new Error(`Package ${pkgName} not found`)
}

const pkgPath = path.resolve(pkgDir, 'package.json')
const pkg: {
name: string
version: string
private?: boolean
} = require(pkgPath)
const pkg: Pkg = require(pkgPath)
const currentVersion = pkg.version

if (pkg.private) {
Expand All @@ -71,15 +78,15 @@ export async function run(
bin: string,
args: string[],
opts: ExecaOptions<string> = {}
) {
): Promise<ExecaReturnValue<string>> {
return execa(bin, args, { stdio: 'inherit', ...opts })
}

export async function dryRun(
bin: string,
args: string[],
opts?: ExecaOptions<string>
) {
): Promise<void> {
return console.log(
colors.blue(`[dryrun] ${bin} ${args.join(' ')}`),
opts || ''
Expand All @@ -88,11 +95,15 @@ export async function dryRun(

export const runIfNotDry = isDryRun ? dryRun : run

export function step(msg: string) {
export function step(msg: string): void {
return console.log(colors.cyan(msg))
}

export function getVersionChoices(currentVersion: string) {
interface VersionChoice {
title: string
value: string
}
export function getVersionChoices(currentVersion: string): VersionChoice[] {
const currentBeta = currentVersion.includes('beta')
const currentAlpha = currentVersion.includes('alpha')
const isStable = !currentBeta && !currentAlpha
Expand All @@ -101,7 +112,7 @@ export function getVersionChoices(currentVersion: string) {
return semver.inc(currentVersion, i, tag)!
}

let versionChoices = [
let versionChoices: VersionChoice[] = [
{
title: 'next',
value: inc(isStable ? 'patch' : 'prerelease')
Expand Down Expand Up @@ -175,7 +186,7 @@ export async function publishPackage(
})
}

export async function getLatestTag(pkgName: string) {
export async function getLatestTag(pkgName: string): Promise<string> {
const tags = (await run('git', ['tag'], { stdio: 'pipe' })).stdout
.split(/\n/)
.filter(Boolean)
Expand All @@ -186,7 +197,7 @@ export async function getLatestTag(pkgName: string) {
.reverse()[0]
}

export async function logRecentCommits(pkgName: string) {
export async function logRecentCommits(pkgName: string): Promise<void> {
const tag = await getLatestTag(pkgName)
if (!tag) return
const sha = await run('git', ['rev-list', '-n', '1', tag], {
Expand Down Expand Up @@ -214,7 +225,7 @@ export async function logRecentCommits(pkgName: string) {
console.log()
}

export async function updateTemplateVersions() {
export async function updateTemplateVersions(): Promise<void> {
const viteVersion = (await fs.readJSON('../packages/vite/package.json'))
.version
if (/beta|alpha|rc/.test(viteVersion)) return
Expand Down