Skip to content

Commit

Permalink
chore: enable import/no-duplicates eslint rule (#8199)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored May 17, 2022
1 parent 8d478df commit 11243de
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = defineConfig({
{ prefer: 'type-imports' }
],

'import/no-duplicates': 'error',
'import/order': 'error',
'sort-imports': [
'error',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as babelCore from '@babel/core'
import type { Visitor, types as t } from '@babel/core'

/**
* Replace this:
Expand All @@ -11,13 +10,13 @@ import type { Visitor, types as t } from '@babel/core'
* var _jsx = require("react/jsx-runtime").jsx
*/
export function babelImportToRequire({ types: t }: typeof babelCore): {
visitor: Visitor
visitor: babelCore.Visitor
} {
return {
visitor: {
ImportDeclaration(path) {
const decl = path.node
const spec = decl.specifiers[0] as t.ImportSpecifier
const spec = decl.specifiers[0] as babelCore.types.ImportSpecifier

path.replaceWith(
t.variableDeclaration('var', [
Expand Down
8 changes: 5 additions & 3 deletions packages/plugin-react/src/jsx-runtime/restore-jsx.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type * as babelCore from '@babel/core'
import type { PluginItem, types as t } from '@babel/core'

type RestoredJSX = [result: t.File | null | undefined, isCommonJS: boolean]
type RestoredJSX = [
result: babelCore.types.File | null | undefined,
isCommonJS: boolean
]

let babelRestoreJSX: Promise<PluginItem> | undefined
let babelRestoreJSX: Promise<babelCore.PluginItem> | undefined

const jsxNotFound: RestoredJSX = [null, false]

Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fs from 'fs'
import type { Plugin, ViteDevServer } from 'vite'
import { createFilter } from '@rollup/pluginutils'
/* eslint-disable import/no-duplicates */
import type {
SFCBlock,
SFCScriptCompileOptions,
SFCStyleCompileOptions,
SFCTemplateCompileOptions
} from 'vue/compiler-sfc'
import type * as _compiler from 'vue/compiler-sfc'
/* eslint-enable import/no-duplicates */
import { resolveCompiler } from './compiler'
import { parseVueRequest } from './utils/query'
import { getDescriptor, getSrcDescriptor } from './utils/descriptorCache'
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type { OutputOptions, PluginContext } from 'rollup'
import MagicString from 'magic-string'
import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '../config'
import { cleanUrl } from '../utils'
import { cleanUrl, getHash, normalizePath } from '../utils'
import { FS_PREFIX } from '../constants'
import { getHash, normalizePath } from '../utils'

export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g

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 @@ -32,6 +32,7 @@ import {
asyncReplace,
cleanUrl,
combineSourcemaps,
emptyCssComments,
generateCodeFrame,
getHash,
isDataUrl,
Expand All @@ -41,7 +42,6 @@ import {
parseRequest,
processSrcSet
} from '../utils'
import { emptyCssComments } from '../utils'
import type { Logger } from '../logger'
import { addToHTMLProxyTransformResult } from './html'
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import type { SourceMap } from 'rollup'
import { createFilter } from '@rollup/pluginutils'
import type { TSConfckParseOptions, TSConfckParseResult } from 'tsconfck'
import { TSConfckParseError, findAll, parse } from 'tsconfck'
import { combineSourcemaps } from '../utils'
import type { ResolvedConfig, ViteDevServer } from '..'
import {
cleanUrl,
combineSourcemaps,
createDebugger,
ensureWatchedFile,
generateCodeFrame,
toUpperCaseDriveLetter
} from '../utils'
import type { ResolvedConfig, ViteDevServer } from '..'
import type { Plugin } from '../plugin'
import { searchForWorkspaceRoot } from '..'

Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/plugins/workerImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { RollupError } from 'rollup'
import { stripLiteral } from 'strip-literal'
import type { ResolvedConfig } from '../config'
import type { Plugin } from '../plugin'
import { cleanUrl, injectQuery } from '../utils'
import { parseRequest } from '../utils'
import { cleanUrl, injectQuery, parseRequest } from '../utils'
import { ENV_ENTRY, ENV_PUBLIC_PATH } from '../constants'
import type { ViteDevServer } from '..'
import { workerFileToUrl } from './worker'
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path'
import type { Server } from 'http'
import type * as http from 'http'
import sirv from 'sirv'
import connect from 'connect'
Expand Down Expand Up @@ -47,7 +46,7 @@ export interface PreviewServer {
/**
* native Node http server instance
*/
httpServer: Server
httpServer: http.Server
/**
* Print server urls
*/
Expand Down
6 changes: 2 additions & 4 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs'
import path from 'path'
import type * as net from 'net'
import type * as http from 'http'
import type { AddressInfo } from 'net'
import { performance } from 'perf_hooks'
import connect from 'connect'
import corsMiddleware from 'cors'
Expand All @@ -16,7 +15,7 @@ import type { CommonServerOptions } from '../http'
import { httpServerStart, resolveHttpServer, resolveHttpsConfig } from '../http'
import type { InlineConfig, ResolvedConfig } from '../config'
import { mergeConfig, resolveConfig } from '../config'
import { isParentDirectory, normalizePath } from '../utils'
import { isParentDirectory, normalizePath, resolveHostname } from '../utils'
import { ssrLoadModule } from '../ssr/ssrModuleLoader'
import { resolveSSRExternal } from '../ssr/ssrExternal'
import {
Expand All @@ -26,7 +25,6 @@ import {
import { ssrTransform } from '../ssr/ssrTransform'
import { createOptimizedDeps } from '../optimizer/registerMissing'
import type { OptimizedDeps } from '../optimizer'
import { resolveHostname } from '../utils'
import { CLIENT_DIR } from '../constants'
import type { Logger } from '../logger'
import { printCommonServerUrls } from '../logger'
Expand Down Expand Up @@ -452,7 +450,7 @@ export async function createServer(
if (!middlewareMode && httpServer) {
httpServer.once('listening', () => {
// update actual port since this may be different from initial value
serverConfig.port = (httpServer.address() as AddressInfo).port
serverConfig.port = (httpServer.address() as net.AddressInfo).port
})
}

Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ import type { FSWatcher } from 'chokidar'
import colors from 'picocolors'
import type * as postcss from 'postcss'
import type { Plugin } from '../plugin'
import { cleanUrl, combineSourcemaps } from '../utils'
import {
cleanUrl,
combineSourcemaps,
createDebugger,
ensureWatchedFile,
generateCodeFrame,
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/server/searchRoot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs'
import { dirname } from 'path'
import { join } from 'path'
import { dirname, join } from 'path'
import { isFileReadable } from '../utils'

// https://github.com/vitejs/vite/issues/2820#issuecomment-812495079
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import os from 'os'
import path from 'path'
import { createHash } from 'crypto'
import { promisify } from 'util'
import { URL, pathToFileURL } from 'url'
import { URL, URLSearchParams, pathToFileURL } from 'url'
import { builtinModules } from 'module'
import { performance } from 'perf_hooks'
import { URLSearchParams } from 'url'
import resolve from 'resolve'
import type { FSWatcher } from 'chokidar'
import remapping from '@ampproject/remapping'
Expand Down

0 comments on commit 11243de

Please sign in to comment.