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 authored May 11, 2022
1 parent edf6fe0 commit 43a58dd
Show file tree
Hide file tree
Showing 81 changed files with 488 additions and 371 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 @@ -86,6 +87,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
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"format": "prettier --write .",
"lint": "eslint packages/*/{src,types}/**",
"lint": "eslint packages/*/{src,types}/** playground/**/__tests__/**/*.*",
"test": "run-s test-unit test-serve test-build",
"test-serve": "vitest run -c vitest.config.e2e.ts",
"test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
Expand Down Expand Up @@ -48,6 +48,7 @@
"esbuild": "^0.14.38",
"eslint": "^8.15.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 @@ -80,10 +81,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,6 +1,6 @@
import babelRestoreJSX from './babel-restore-jsx'
import * as babel from '@babel/core'
import { describe, it, expect } from 'vitest'
import { describe, expect, it } from 'vitest'
import babelRestoreJSX from './babel-restore-jsx'

function jsx(code: string) {
return babel.transform(code, {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { restoreJSX } from './restore-jsx'
import * as babel from '@babel/core'
import { describe, it, expect } from 'vitest'
import { describe, expect, it } from 'vitest'
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__/asset.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest'
import { describe, expect, test } from 'vitest'
import { assetFileNamesToFileName, getAssetHash } from '../plugins/asset'

describe('getAssetHash', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path'
import { describe, expect, test } from 'vitest'
import type { LibraryFormats, LibraryOptions } from '../build'
import { resolveLibFilename } from '../build'
import { resolve } from 'path'
import { describe, test, expect } from 'vitest'

type FormatsToFileNames = [LibraryFormats, string][]
const baseLibOptions: LibraryOptions = {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest'
import type { InlineConfig } from '..'
import type { UserConfigExport, UserConfig } from '../config'
import type { UserConfig, UserConfigExport } from '../config'
import { mergeConfig, resolveConfig, resolveEnvPrefix } from '../config'
import { describe, test, expect } from 'vitest'

describe('mergeConfig', () => {
test('handles configs with different alias schemas', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/dev.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest'
import { resolveConfig } from '..'
import { describe, test, expect } from 'vitest'

describe('resolveBuildOptions in dev', () => {
test('build.rollupOptions should not have input in lib', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/__tests__/plugins/css.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cssUrlRE, cssPlugin, hoistAtRules } from '../../plugins/css'
import { resolveConfig } from '../../config'
import fs from 'fs'
import path from 'path'
import { describe, vi, test, expect } from 'vitest'
import { describe, expect, test, vi } from 'vitest'
import { resolveConfig } from '../../config'
import { cssPlugin, cssUrlRE, hoistAtRules } from '../../plugins/css'

describe('search css url function', () => {
test('some spaces before it', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/plugins/define.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest'
import { describe, expect, test } from 'vitest'
import { definePlugin } from '../../plugins/define'
import { resolveConfig } from '../../config'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'path'
import { describe, expect, it } from 'vitest'
import { transformDynamicImport } from '../../../plugins/dynamicImportVars'
import { resolve } from 'path'

async function run(input: string) {
const { glob, rawPattern } = await transformDynamicImport(
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/plugins/import.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest'
import { describe, expect, test } from 'vitest'
import { transformCjsImport } from '../../plugins/importAnalysis'

describe('transformCjsImport', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/scan.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { scriptRE, commentRE, importsRE } from '../optimizer/scan'
import { describe, expect, test } from 'vitest'
import { commentRE, importsRE, scriptRE } from '../optimizer/scan'
import { multilineCommentsRE, singlelineCommentsRE } from '../utils'
import { describe, test, expect } from 'vitest'

describe('optimizer-scan:script-test', () => {
const scriptContent = `import { defineComponent } from 'vue'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, test } from 'vitest'
import {
getPotentialTsSrcPaths,
injectQuery,
isWindows,
resolveHostname
} from '../utils'
import { describe, test, expect } from 'vitest'

describe('injectQuery', () => {
if (isWindows) {
Expand Down
30 changes: 15 additions & 15 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
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 type { Terser } from 'types/terser'
import commonjsPlugin from '@rollup/plugin-commonjs'
import type { RollupCommonJSOptions } from 'types/commonjs'
import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
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 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 type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
import type { Logger } from './logger'
import type { TransformOptions } from 'esbuild'
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 type { PackageData } 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
Loading

0 comments on commit 43a58dd

Please sign in to comment.