Skip to content

Commit 43a58dd

Browse files
authored
chore(lint): sort for imports (#8113)
1 parent edf6fe0 commit 43a58dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+488
-371
lines changed

.eslintrc.cjs

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = defineConfig({
88
'plugin:node/recommended',
99
'plugin:@typescript-eslint/recommended'
1010
],
11+
plugins: ['import'],
1112
parser: '@typescript-eslint/parser',
1213
parserOptions: {
1314
sourceType: 'module',
@@ -86,6 +87,18 @@ module.exports = defineConfig({
8687
'@typescript-eslint/consistent-type-imports': [
8788
'error',
8889
{ prefer: 'type-imports' }
90+
],
91+
92+
'import/order': 'error',
93+
'sort-imports': [
94+
'error',
95+
{
96+
ignoreCase: false,
97+
ignoreDeclarationSort: true,
98+
ignoreMemberSort: false,
99+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
100+
allowSeparatedGroups: false
101+
}
89102
]
90103
},
91104
overrides: [

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"scripts": {
1616
"preinstall": "npx only-allow pnpm",
1717
"format": "prettier --write .",
18-
"lint": "eslint packages/*/{src,types}/**",
18+
"lint": "eslint packages/*/{src,types}/** playground/**/__tests__/**/*.*",
1919
"test": "run-s test-unit test-serve test-build",
2020
"test-serve": "vitest run -c vitest.config.e2e.ts",
2121
"test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
@@ -48,6 +48,7 @@
4848
"esbuild": "^0.14.38",
4949
"eslint": "^8.15.0",
5050
"eslint-define-config": "^1.4.0",
51+
"eslint-plugin-import": "^2.26.0",
5152
"eslint-plugin-node": "^11.1.0",
5253
"execa": "^5.1.1",
5354
"fs-extra": "^10.1.0",
@@ -80,10 +81,13 @@
8081
"prettier --write --ignore-unknown"
8182
],
8283
"packages/*/{src,types}/**/*.ts": [
83-
"eslint --ext .ts"
84+
"eslint --fix"
8485
],
8586
"packages/**/*.d.ts": [
86-
"eslint --ext .ts"
87+
"eslint --fix"
88+
],
89+
"playground/**/__tests__/**/*.ts": [
90+
"eslint --fix"
8791
]
8892
},
8993
"packageManager": "[email protected]",

packages/plugin-react/src/fast-refresh.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { types as t } from '@babel/core'
21
import fs from 'fs'
32
import path from 'path'
3+
import type { types as t } from '@babel/core'
44

55
export const runtimePublicPath = '/@react-refresh'
66

packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as babelCore from '@babel/core'
2-
import type { types as t, Visitor } from '@babel/core'
2+
import type { Visitor, types as t } from '@babel/core'
33

44
/**
55
* Replace this:

packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import babelRestoreJSX from './babel-restore-jsx'
21
import * as babel from '@babel/core'
3-
import { describe, it, expect } from 'vitest'
2+
import { describe, expect, it } from 'vitest'
3+
import babelRestoreJSX from './babel-restore-jsx'
44

55
function jsx(code: string) {
66
return babel.transform(code, {

packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { restoreJSX } from './restore-jsx'
21
import * as babel from '@babel/core'
3-
import { describe, it, expect } from 'vitest'
2+
import { describe, expect, it } from 'vitest'
3+
import { restoreJSX } from './restore-jsx'
44

55
async function jsx(sourceCode: string) {
66
const [ast] = await restoreJSX(babel, sourceCode, 'test.js')

packages/plugin-vue/src/handleHotUpdate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import _debug from 'debug'
22
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
3+
import type { HmrContext, ModuleNode } from 'vite'
34
import {
45
createDescriptor,
56
getDescriptor,
67
setPrevDescriptor
78
} from './utils/descriptorCache'
89
import { getResolvedScript, setResolvedScript } from './script'
9-
import type { ModuleNode, HmrContext } from 'vite'
1010
import type { ResolvedOptions } from '.'
1111

1212
const debug = _debug('vite:hmr')

packages/plugin-vue/src/main.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import path from 'path'
22
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
3-
import type { ResolvedOptions } from '.'
3+
import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
4+
import { normalizePath } from '@rollup/pluginutils'
5+
import type { RawSourceMap } from 'source-map'
6+
import { SourceMapConsumer, SourceMapGenerator } from 'source-map'
7+
import { transformWithEsbuild } from 'vite'
48
import {
59
createDescriptor,
610
getPrevDescriptor,
711
setSrcDescriptor
812
} from './utils/descriptorCache'
9-
import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
10-
import { normalizePath } from '@rollup/pluginutils'
11-
import { resolveScript, isUseInlineTemplate } from './script'
13+
import { isUseInlineTemplate, resolveScript } from './script'
1214
import { transformTemplateInMain } from './template'
13-
import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate'
14-
import type { RawSourceMap } from 'source-map'
15-
import { SourceMapConsumer, SourceMapGenerator } from 'source-map'
15+
import { isEqualBlock, isOnlyTemplateChanged } from './handleHotUpdate'
1616
import { createRollupError } from './utils/error'
17-
import { transformWithEsbuild } from 'vite'
1817
import { EXPORT_HELPER_ID } from './helper'
18+
import type { ResolvedOptions } from '.'
1919

2020
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
2121
export async function transformMain(

packages/plugin-vue/src/script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'
2-
import type { ResolvedOptions } from '.'
32
import { resolveTemplateCompilerOptions } from './template'
3+
import type { ResolvedOptions } from '.'
44

55
// ssr and non ssr builds would output different script content
66
const clientCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()

packages/plugin-vue/src/style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { SFCDescriptor } from 'vue/compiler-sfc'
22
import type { ExistingRawSourceMap, TransformPluginContext } from 'rollup'
3-
import type { ResolvedOptions } from '.'
43
import type { RawSourceMap } from 'source-map'
54
import { formatPostcssSourceMap } from 'vite'
5+
import type { ResolvedOptions } from '.'
66

77
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
88
export async function transformStyle(

packages/plugin-vue/src/template.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import path from 'path'
22
import slash from 'slash'
33
import type {
4+
CompilerOptions,
45
SFCDescriptor,
56
SFCTemplateCompileOptions,
6-
SFCTemplateCompileResults,
7-
CompilerOptions
7+
SFCTemplateCompileResults
88
} from 'vue/compiler-sfc'
99
import type { PluginContext, TransformPluginContext } from 'rollup'
10-
import type { ResolvedOptions } from '.'
1110
import { getResolvedScript } from './script'
1211
import { createRollupError } from './utils/error'
12+
import type { ResolvedOptions } from '.'
1313

1414
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1515
export async function transformTemplateAsModule(

packages/vite/src/node/__tests__/asset.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import { assetFileNamesToFileName, getAssetHash } from '../plugins/asset'
33

44
describe('getAssetHash', () => {

packages/vite/src/node/__tests__/build.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { resolve } from 'path'
2+
import { describe, expect, test } from 'vitest'
13
import type { LibraryFormats, LibraryOptions } from '../build'
24
import { resolveLibFilename } from '../build'
3-
import { resolve } from 'path'
4-
import { describe, test, expect } from 'vitest'
55

66
type FormatsToFileNames = [LibraryFormats, string][]
77
const baseLibOptions: LibraryOptions = {

packages/vite/src/node/__tests__/config.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { describe, expect, test } from 'vitest'
12
import type { InlineConfig } from '..'
2-
import type { UserConfigExport, UserConfig } from '../config'
3+
import type { UserConfig, UserConfigExport } from '../config'
34
import { mergeConfig, resolveConfig, resolveEnvPrefix } from '../config'
4-
import { describe, test, expect } from 'vitest'
55

66
describe('mergeConfig', () => {
77
test('handles configs with different alias schemas', () => {

packages/vite/src/node/__tests__/dev.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { describe, expect, test } from 'vitest'
12
import { resolveConfig } from '..'
2-
import { describe, test, expect } from 'vitest'
33

44
describe('resolveBuildOptions in dev', () => {
55
test('build.rollupOptions should not have input in lib', async () => {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { cssUrlRE, cssPlugin, hoistAtRules } from '../../plugins/css'
2-
import { resolveConfig } from '../../config'
31
import fs from 'fs'
42
import path from 'path'
5-
import { describe, vi, test, expect } from 'vitest'
3+
import { describe, expect, test, vi } from 'vitest'
4+
import { resolveConfig } from '../../config'
5+
import { cssPlugin, cssUrlRE, hoistAtRules } from '../../plugins/css'
66

77
describe('search css url function', () => {
88
test('some spaces before it', () => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import { definePlugin } from '../../plugins/define'
33
import { resolveConfig } from '../../config'
44

packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { resolve } from 'path'
12
import { describe, expect, it } from 'vitest'
23
import { transformDynamicImport } from '../../../plugins/dynamicImportVars'
3-
import { resolve } from 'path'
44

55
async function run(input: string) {
66
const { glob, rawPattern } = await transformDynamicImport(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import { transformCjsImport } from '../../plugins/importAnalysis'
33

44
describe('transformCjsImport', () => {

packages/vite/src/node/__tests__/scan.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { scriptRE, commentRE, importsRE } from '../optimizer/scan'
1+
import { describe, expect, test } from 'vitest'
2+
import { commentRE, importsRE, scriptRE } from '../optimizer/scan'
23
import { multilineCommentsRE, singlelineCommentsRE } from '../utils'
3-
import { describe, test, expect } from 'vitest'
44

55
describe('optimizer-scan:script-test', () => {
66
const scriptContent = `import { defineComponent } from 'vue'

packages/vite/src/node/__tests__/utils.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { describe, expect, test } from 'vitest'
12
import {
23
getPotentialTsSrcPaths,
34
injectQuery,
45
isWindows,
56
resolveHostname
67
} from '../utils'
7-
import { describe, test, expect } from 'vitest'
88

99
describe('injectQuery', () => {
1010
if (isWindows) {

packages/vite/src/node/build.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
import fs from 'fs'
22
import path from 'path'
33
import colors from 'picocolors'
4-
import type { InlineConfig, ResolvedConfig } from './config'
5-
import { resolveConfig } from './config'
64
import type {
5+
ExternalOption,
6+
ModuleFormat,
7+
OutputOptions,
78
Plugin,
89
RollupBuild,
10+
RollupError,
911
RollupOptions,
10-
RollupWarning,
11-
WarningHandler,
12-
OutputOptions,
1312
RollupOutput,
14-
ExternalOption,
15-
WatcherOptions,
13+
RollupWarning,
1614
RollupWatcher,
17-
RollupError,
18-
ModuleFormat
15+
WarningHandler,
16+
WatcherOptions
1917
} from 'rollup'
2018
import type Rollup from 'rollup'
19+
import type { Terser } from 'types/terser'
20+
import commonjsPlugin from '@rollup/plugin-commonjs'
21+
import type { RollupCommonJSOptions } from 'types/commonjs'
22+
import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
23+
import type { TransformOptions } from 'esbuild'
24+
import type { InlineConfig, ResolvedConfig } from './config'
25+
import { resolveConfig } from './config'
2126
import { buildReporterPlugin } from './plugins/reporter'
2227
import { buildEsbuildPlugin } from './plugins/esbuild'
2328
import { terserPlugin } from './plugins/terser'
24-
import type { Terser } from 'types/terser'
2529
import { copyDir, emptyDir, lookupFile, normalizePath } from './utils'
2630
import { manifestPlugin } from './plugins/manifest'
27-
import commonjsPlugin from '@rollup/plugin-commonjs'
28-
import type { RollupCommonJSOptions } from 'types/commonjs'
29-
import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
3031
import type { Logger } from './logger'
31-
import type { TransformOptions } from 'esbuild'
3232
import { dataURIPlugin } from './plugins/dataUri'
3333
import { buildImportAnalysisPlugin } from './plugins/importAnalysisBuild'
3434
import { resolveSSRExternal, shouldExternalizeForSSR } from './ssr/ssrExternal'
3535
import { ssrManifestPlugin } from './ssr/ssrManifestPlugin'
3636
import type { DepOptimizationMetadata } from './optimizer'
37-
import { getDepsCacheDir, findKnownImports } from './optimizer'
37+
import { findKnownImports, getDepsCacheDir } from './optimizer'
3838
import { assetImportMetaUrlPlugin } from './plugins/assetImportMetaUrl'
3939
import { loadFallbackPlugin } from './plugins/loadFallback'
4040
import type { PackageData } from './packages'

packages/vite/src/node/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { performance } from 'perf_hooks'
12
import { cac } from 'cac'
23
import colors from 'picocolors'
3-
import { performance } from 'perf_hooks'
44
import type { BuildOptions } from './build'
55
import type { ServerOptions } from './server'
66
import type { LogLevel } from './logger'

packages/vite/src/node/config.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
import fs from 'fs'
22
import path from 'path'
3+
import { parse as parseUrl, pathToFileURL } from 'url'
4+
import { performance } from 'perf_hooks'
5+
import colors from 'picocolors'
6+
import dotenv from 'dotenv'
7+
import dotenvExpand from 'dotenv-expand'
8+
import type { Alias, AliasOptions } from 'types/alias'
9+
import { createFilter } from '@rollup/pluginutils'
10+
import aliasPlugin from '@rollup/plugin-alias'
11+
import { build } from 'esbuild'
12+
import type { RollupOptions } from 'rollup'
313
import type { Plugin } from './plugin'
414
import type { BuildOptions } from './build'
515
import { resolveBuildOptions } from './build'
616
import type { ResolvedServerOptions, ServerOptions } from './server'
717
import { resolveServerOptions } from './server'
8-
import type { ResolvedPreviewOptions, PreviewOptions } from './preview'
18+
import type { PreviewOptions, ResolvedPreviewOptions } from './preview'
919
import { resolvePreviewOptions } from './preview'
1020
import type { CSSOptions } from './plugins/css'
1121
import {
1222
arraify,
1323
createDebugger,
24+
dynamicImport,
1425
isExternalUrl,
1526
isObject,
1627
lookupFile,
17-
normalizePath,
18-
dynamicImport
28+
normalizePath
1929
} from './utils'
2030
import { resolvePlugins } from './plugins'
21-
import colors from 'picocolors'
2231
import type { ESBuildOptions } from './plugins/esbuild'
23-
import dotenv from 'dotenv'
24-
import dotenvExpand from 'dotenv-expand'
25-
import type { Alias, AliasOptions } from 'types/alias'
26-
import { CLIENT_ENTRY, ENV_ENTRY, DEFAULT_ASSETS_RE } from './constants'
32+
import { CLIENT_ENTRY, DEFAULT_ASSETS_RE, ENV_ENTRY } from './constants'
2733
import type { InternalResolveOptions, ResolveOptions } from './plugins/resolve'
2834
import { resolvePlugin } from './plugins/resolve'
29-
import type { Logger, LogLevel } from './logger'
35+
import type { LogLevel, Logger } from './logger'
3036
import { createLogger } from './logger'
3137
import type { DepOptimizationOptions } from './optimizer'
32-
import { createFilter } from '@rollup/pluginutils'
33-
import type { ResolvedBuildOptions } from '.'
34-
import { parse as parseUrl, pathToFileURL } from 'url'
3538
import type { JsonOptions } from './plugins/json'
3639
import type { PluginContainer } from './server/pluginContainer'
3740
import { createPluginContainer } from './server/pluginContainer'
38-
import aliasPlugin from '@rollup/plugin-alias'
39-
import { build } from 'esbuild'
40-
import { performance } from 'perf_hooks'
4141
import type { PackageCache } from './packages'
42-
import type { RollupOptions } from 'rollup'
42+
import type { ResolvedBuildOptions } from '.'
4343

4444
const debug = createDebugger('vite:config')
4545

0 commit comments

Comments
 (0)