Skip to content

Commit

Permalink
chore(lint): sort for imports (#8113)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 11, 2022
1 parent 1c2aef0 commit 4bd1531
Show file tree
Hide file tree
Showing 68 changed files with 589 additions and 360 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = defineConfig({
'plugin:node/recommended',
'plugin:@typescript-eslint/recommended'
],
plugins: ['import'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
Expand Down Expand Up @@ -93,6 +94,18 @@ module.exports = defineConfig({
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' }
],

'import/order': 'error',
'sort-imports': [
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: false
}
]
},
overrides: [
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"esbuild": "^0.14.27",
"eslint": "^8.14.0",
"eslint-define-config": "^1.4.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"execa": "^5.1.1",
"fs-extra": "^10.1.0",
Expand Down Expand Up @@ -79,10 +80,13 @@
"prettier --write --ignore-unknown"
],
"packages/*/{src,types}/**/*.ts": [
"eslint --ext .ts"
"eslint --fix"
],
"packages/**/*.d.ts": [
"eslint --ext .ts"
"eslint --fix"
],
"playground/**/__tests__/**/*.ts": [
"eslint --fix"
]
},
"packageManager": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react/src/fast-refresh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { types as t } from '@babel/core'
import fs from 'fs'
import path from 'path'
import type { types as t } from '@babel/core'

export const runtimePublicPath = '/@react-refresh'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as babelCore from '@babel/core'
import type { types as t, Visitor } from '@babel/core'
import type { Visitor, types as t } from '@babel/core'

/**
* Replace this:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import babelRestoreJSX from './babel-restore-jsx'
import * as babel from '@babel/core'
import babelRestoreJSX from './babel-restore-jsx'

function jsx(code: string) {
return babel.transform(code, {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { restoreJSX } from './restore-jsx'
import * as babel from '@babel/core'
import { restoreJSX } from './restore-jsx'

async function jsx(sourceCode: string) {
const [ast] = await restoreJSX(babel, sourceCode, 'test.js')
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import _debug from 'debug'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { HmrContext, ModuleNode } from 'vite'
import {
createDescriptor,
getDescriptor,
setPrevDescriptor
} from './utils/descriptorCache'
import { getResolvedScript, setResolvedScript } from './script'
import type { ModuleNode, HmrContext } from 'vite'
import type { ResolvedOptions } from '.'

const debug = _debug('vite:hmr')
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import path from 'path'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { ResolvedOptions } from '.'
import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
import { normalizePath } from '@rollup/pluginutils'
import type { RawSourceMap } from 'source-map'
import { SourceMapConsumer, SourceMapGenerator } from 'source-map'
import { transformWithEsbuild } from 'vite'
import {
createDescriptor,
getPrevDescriptor,
setSrcDescriptor
} from './utils/descriptorCache'
import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
import { normalizePath } from '@rollup/pluginutils'
import { resolveScript, isUseInlineTemplate } from './script'
import { isUseInlineTemplate, resolveScript } from './script'
import { transformTemplateInMain } from './template'
import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate'
import type { RawSourceMap } from 'source-map'
import { SourceMapConsumer, SourceMapGenerator } from 'source-map'
import { isEqualBlock, isOnlyTemplateChanged } from './handleHotUpdate'
import { createRollupError } from './utils/error'
import { transformWithEsbuild } from 'vite'
import { EXPORT_HELPER_ID } from './helper'
import type { ResolvedOptions } from '.'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function transformMain(
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'
import type { ResolvedOptions } from '.'
import { resolveTemplateCompilerOptions } from './template'
import type { ResolvedOptions } from '.'

// ssr and non ssr builds would output different script content
const clientCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/style.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SFCDescriptor } from 'vue/compiler-sfc'
import type { ExistingRawSourceMap, TransformPluginContext } from 'rollup'
import type { ResolvedOptions } from '.'
import type { RawSourceMap } from 'source-map'
import { formatPostcssSourceMap } from 'vite'
import type { ResolvedOptions } from '.'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function transformStyle(
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import path from 'path'
import slash from 'slash'
import type {
CompilerOptions,
SFCDescriptor,
SFCTemplateCompileOptions,
SFCTemplateCompileResults,
CompilerOptions
SFCTemplateCompileResults
} from 'vue/compiler-sfc'
import type { PluginContext, TransformPluginContext } from 'rollup'
import type { ResolvedOptions } from '.'
import { getResolvedScript } from './script'
import { createRollupError } from './utils/error'
import type { ResolvedOptions } from '.'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function transformTemplateAsModule(
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolveLibFilename } from '../build'
import { resolve } from 'path'
import { resolveLibFilename } from '../build'

describe('resolveLibFilename', () => {
test('custom filename function', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InlineConfig } from '..'
import type { UserConfigExport, UserConfig } from '../config'
import type { UserConfig, UserConfigExport } from '../config'
import { mergeConfig, resolveConfig, resolveEnvPrefix } from '../config'

describe('mergeConfig', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/plugins/css.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cssUrlRE, cssPlugin, hoistAtRules } from '../../plugins/css'
import { resolveConfig } from '../../config'
import fs from 'fs'
import path from 'path'
import { cssPlugin, cssUrlRE, hoistAtRules } from '../../plugins/css'
import { resolveConfig } from '../../config'

describe('search css url function', () => {
test('some spaces before it', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/scan.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { scriptRE, commentRE, importsRE } from '../optimizer/scan'
import { commentRE, importsRE, scriptRE } from '../optimizer/scan'
import { multilineCommentsRE, singlelineCommentsRE } from '../utils'

describe('optimizer-scan:script-test', () => {
Expand Down
32 changes: 16 additions & 16 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import fs from 'fs'
import path from 'path'
import colors from 'picocolors'
import type { InlineConfig, ResolvedConfig } from './config'
import { resolveConfig } from './config'
import type {
ExternalOption,
ModuleFormat,
OutputOptions,
Plugin,
RollupBuild,
RollupError,
RollupOptions,
RollupWarning,
WarningHandler,
OutputOptions,
RollupOutput,
ExternalOption,
WatcherOptions,
RollupWarning,
RollupWatcher,
RollupError,
ModuleFormat
WarningHandler,
WatcherOptions
} from 'rollup'
import type Rollup from 'rollup'
import { buildReporterPlugin } from './plugins/reporter'
import { buildEsbuildPlugin } from './plugins/esbuild'
import { terserPlugin } from './plugins/terser'
import type { Terser } from 'types/terser'
import { copyDir, emptyDir, lookupFile, normalizePath } from './utils'
import { manifestPlugin } from './plugins/manifest'
import commonjsPlugin from '@rollup/plugin-commonjs'
import type { RollupCommonJSOptions } from 'types/commonjs'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
import type { Logger } from './logger'
import type { TransformOptions } from 'esbuild'
import type { InlineConfig, ResolvedConfig } from './config'
import { resolveConfig } from './config'
import { buildReporterPlugin } from './plugins/reporter'
import { buildEsbuildPlugin } from './plugins/esbuild'
import { terserPlugin } from './plugins/terser'
import { copyDir, emptyDir, lookupFile, normalizePath } from './utils'
import { manifestPlugin } from './plugins/manifest'
import type { Logger } from './logger'
import { dataURIPlugin } from './plugins/dataUri'
import { buildImportAnalysisPlugin } from './plugins/importAnalysisBuild'
import { resolveSSRExternal, shouldExternalizeForSSR } from './ssr/ssrExternal'
import { ssrManifestPlugin } from './ssr/ssrManifestPlugin'
import type { DepOptimizationMetadata } from './optimizer'
import { getDepsCacheDir, findKnownImports } from './optimizer'
import { findKnownImports, getDepsCacheDir } from './optimizer'
import { assetImportMetaUrlPlugin } from './plugins/assetImportMetaUrl'
import { loadFallbackPlugin } from './plugins/loadFallback'
import { watchPackageDataPlugin } from './packages'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { performance } from 'perf_hooks'
import { cac } from 'cac'
import colors from 'picocolors'
import { performance } from 'perf_hooks'
import type { BuildOptions } from './build'
import type { ServerOptions } from './server'
import type { LogLevel } from './logger'
Expand Down
32 changes: 16 additions & 16 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import fs from 'fs'
import path from 'path'
import { parse as parseUrl, pathToFileURL } from 'url'
import { performance } from 'perf_hooks'
import colors from 'picocolors'
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'
import type { Alias, AliasOptions } from 'types/alias'
import { createFilter } from '@rollup/pluginutils'
import aliasPlugin from '@rollup/plugin-alias'
import { build } from 'esbuild'
import type { RollupOptions } from 'rollup'
import type { Plugin } from './plugin'
import type { BuildOptions } from './build'
import { resolveBuildOptions } from './build'
import type { ResolvedServerOptions, ServerOptions } from './server'
import { resolveServerOptions } from './server'
import type { ResolvedPreviewOptions, PreviewOptions } from './preview'
import type { PreviewOptions, ResolvedPreviewOptions } from './preview'
import { resolvePreviewOptions } from './preview'
import type { CSSOptions } from './plugins/css'
import {
arraify,
createDebugger,
dynamicImport,
isExternalUrl,
isObject,
lookupFile,
normalizePath,
dynamicImport
normalizePath
} from './utils'
import { resolvePlugins } from './plugins'
import colors from 'picocolors'
import type { ESBuildOptions } from './plugins/esbuild'
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'
import type { Alias, AliasOptions } from 'types/alias'
import { CLIENT_ENTRY, ENV_ENTRY, DEFAULT_ASSETS_RE } from './constants'
import { CLIENT_ENTRY, DEFAULT_ASSETS_RE, ENV_ENTRY } from './constants'
import type { InternalResolveOptions, ResolveOptions } from './plugins/resolve'
import { resolvePlugin } from './plugins/resolve'
import type { Logger, LogLevel } from './logger'
import type { LogLevel, Logger } from './logger'
import { createLogger } from './logger'
import type { DepOptimizationOptions } from './optimizer'
import { createFilter } from '@rollup/pluginutils'
import type { ResolvedBuildOptions } from '.'
import { parse as parseUrl, pathToFileURL } from 'url'
import type { JsonOptions } from './plugins/json'
import type { PluginContainer } from './server/pluginContainer'
import { createPluginContainer } from './server/pluginContainer'
import aliasPlugin from '@rollup/plugin-alias'
import { build } from 'esbuild'
import { performance } from 'perf_hooks'
import type { PackageCache } from './packages'
import type { RollupOptions } from 'rollup'
import type { ResolvedBuildOptions } from '.'

const debug = createDebugger('vite:config')

Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/http.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs, { promises as fsp } from 'fs'
import path from 'path'
import type {
OutgoingHttpHeaders as HttpServerHeaders,
Server as HttpServer
Server as HttpServer,
OutgoingHttpHeaders as HttpServerHeaders
} from 'http'
import type { ServerOptions as HttpsServerOptions } from 'https'
import type { Connect } from 'types/connect'
import { isObject } from './utils'
import type { ProxyOptions } from './server/middlewares/proxy'
import type { Connect } from 'types/connect'
import type { Logger } from './logger'

export interface CommonServerOptions {
Expand Down
14 changes: 7 additions & 7 deletions packages/vite/src/node/importGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import path from 'path'
import { promises as fsp } from 'fs'
import glob from 'fast-glob'
import JSON5 from 'json5'
import type { RollupError } from 'rollup'
import colors from 'picocolors'
import {
isModernFlag,
preloadMethod,
preloadMarker
preloadMarker,
preloadMethod
} from './plugins/importAnalysisBuild'
import { isCSSRequest } from './plugins/css'
import {
blankReplacer,
cleanUrl,
singlelineCommentsRE,
multilineCommentsRE,
blankReplacer,
normalizePath
normalizePath,
singlelineCommentsRE
} from './utils'
import type { RollupError } from 'rollup'
import type { Logger } from '.'
import colors from 'picocolors'

interface GlobParams {
base: string
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/logger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint no-console: 0 */

import colors from 'picocolors'
import type { AddressInfo, Server } from 'net'
import os from 'os'
import readline from 'readline'
import colors from 'picocolors'
import type { RollupError } from 'rollup'
import type { ResolvedConfig } from '.'
import type { CommonServerOptions } from './http'
import type { Hostname } from './utils'
import { resolveHostname } from './utils'
import type { ResolvedConfig } from '.'

export type LogType = 'error' | 'warn' | 'info'
export type LogLevel = LogType | 'silent'
Expand Down
Loading

0 comments on commit 4bd1531

Please sign in to comment.