From: 三咲智子 Kevin Deng Date: Sat, 20 Jan 2024 16:14:23 +0000 (+0800) Subject: chore: restrict duplicated imports, support Vue SFC for eslint X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f3725bd1ba1b8a40e7ce3ad038ad46e886f5691;p=thirdparty%2Fvuejs%2Fcore.git chore: restrict duplicated imports, support Vue SFC for eslint --- diff --git a/eslint.config.js b/eslint.config.js index 334787fd98..2969bd1823 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,6 +2,7 @@ import importX from 'eslint-plugin-import-x' import tseslint from 'typescript-eslint' import vitest from 'eslint-plugin-vitest' import { builtinModules } from 'node:module' +import vueParser from 'vue-eslint-parser' const DOMGlobals = ['window', 'document'] const NodeGlobals = ['module', 'require'] @@ -14,7 +15,7 @@ const banConstEnum = { export default tseslint.config( { - files: ['**/*.js', '**/*.ts', '**/*.tsx'], + files: ['**/*.js', '**/*.ts', '**/*.tsx', '**/*.vue'], extends: [tseslint.configs.base], plugins: { 'import-x': importX, @@ -54,6 +55,7 @@ export default tseslint.config( ], 'sort-imports': ['error', { ignoreDeclarationSort: true }], + 'import-x/no-duplicates': 'error', 'import-x/no-nodejs-modules': [ 'error', { allow: builtinModules.map(mod => `node:${mod}`) }, @@ -74,6 +76,16 @@ export default tseslint.config( }, }, + { + files: ['**/*.vue'], + languageOptions: { + parser: vueParser, + parserOptions: { + parser: '@typescript-eslint/parser', + }, + }, + }, + // tests, no restrictions (runs in Node / Vitest with jsdom) { files: ['**/__tests__/**', 'packages/dts-test/**'], diff --git a/package.json b/package.json index c89e2ff282..aee9b37dd4 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,8 @@ "typescript": "~5.4.5", "typescript-eslint": "^7.10.0", "vite": "^5.2.12", - "vitest": "^1.5.2" + "vitest": "^1.5.2", + "vue-eslint-parser": "^9.4.2" }, "pnpm": { "peerDependencyRules": { diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index d2a39be262..617182fc44 100644 --- a/packages/dts-test/defineComponent.test-d.tsx +++ b/packages/dts-test/defineComponent.test-d.tsx @@ -1,12 +1,19 @@ import { + type AllowedComponentProps, type Component, + type ComponentCustomProps, type ComponentOptions, + type ComponentOptionsMixin, type ComponentPublicInstance, + type DefineComponent, + type EmitsOptions, + type ExtractPropTypes, type PropType, type SetupContext, type Slots, type SlotsType, type VNode, + type VNodeProps, createApp, defineComponent, h, @@ -1505,16 +1512,6 @@ describe('withKeys and withModifiers as pro', () => { ; }) -import type { - AllowedComponentProps, - ComponentCustomProps, - ComponentOptionsMixin, - DefineComponent, - EmitsOptions, - ExtractPropTypes, - VNodeProps, -} from 'vue' - // code generated by tsc / vue-tsc, make sure this continues to work // so we don't accidentally change the args order of DefineComponent declare const MyButton: DefineComponent< diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index bab9e0764f..5cd6e5c0fa 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -38,8 +38,11 @@ import { } from './errorHandling' import { queuePostRenderEffect } from './renderer' import { warn } from './warning' -import { DeprecationTypes } from './compat/compatConfig' -import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig' +import { + DeprecationTypes, + checkCompatEnabled, + isCompatEnabled, +} from './compat/compatConfig' import type { ObjectWatchOptionItem } from './componentOptions' import { useSSRContext } from './helpers/useSsrContext' diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 65b952b0b5..a4b19f2d2a 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -18,7 +18,13 @@ import { isPromise, isString, } from '@vue/shared' -import { type Ref, isRef } from '@vue/reactivity' +import { + type ComputedGetter, + type Ref, + type WritableComputedOptions, + isRef, + reactive, +} from '@vue/reactivity' import { computed } from './apiComputed' import { type WatchCallback, @@ -43,11 +49,6 @@ import { onUnmounted, onUpdated, } from './apiLifecycle' -import { - type ComputedGetter, - type WritableComputedOptions, - reactive, -} from '@vue/reactivity' import type { ComponentObjectPropsOptions, ComponentPropsOptions, diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 5a4292b6f3..1b6fc2e74e 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -35,8 +35,11 @@ import { import { isEmitListener } from './componentEmits' import type { AppContext } from './apiCreateApp' import { createPropsDefaultThis } from './compat/props' -import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig' -import { DeprecationTypes } from './compat/compatConfig' +import { + DeprecationTypes, + isCompatEnabled, + softAssertCompatEnabled, +} from './compat/compatConfig' import { shouldSkipAttr } from './compat/attrsFallthrough' import { createInternalObject } from './internalObject' diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 94b2985040..1e58ffae20 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -384,17 +384,17 @@ export const ssrUtils = (__SSR__ ? _ssrUtils : null) as typeof _ssrUtils // 2.x COMPAT ------------------------------------------------------------------ -import { DeprecationTypes as _DeprecationTypes } from './compat/compatConfig' -export type { CompatVue } from './compat/global' -export type { LegacyConfig } from './compat/globalConfig' - -import { warnDeprecation } from './compat/compatConfig' -import { createCompatVue } from './compat/global' import { + DeprecationTypes as _DeprecationTypes, checkCompatEnabled, isCompatEnabled, softAssertCompatEnabled, + warnDeprecation, } from './compat/compatConfig' +export type { CompatVue } from './compat/global' +export type { LegacyConfig } from './compat/globalConfig' + +import { createCompatVue } from './compat/global' import { resolveFilter as _resolveFilter } from './helpers/resolveAssets' import { NOOP } from '@vue/shared' diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index 542341b13e..9a79b00721 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -70,8 +70,7 @@ import { } from './devtools' import { initFeatureFlags } from './featureFlags' import { isAsyncWrapper } from './apiAsyncComponent' -import { isCompatEnabled } from './compat/compatConfig' -import { DeprecationTypes } from './compat/compatConfig' +import { DeprecationTypes, isCompatEnabled } from './compat/compatConfig' import type { TransitionHooks } from './components/BaseTransition' export interface Renderer { diff --git a/packages/server-renderer/src/helpers/ssrRenderAttrs.ts b/packages/server-renderer/src/helpers/ssrRenderAttrs.ts index 5a7baaac3a..94070f3168 100644 --- a/packages/server-renderer/src/helpers/ssrRenderAttrs.ts +++ b/packages/server-renderer/src/helpers/ssrRenderAttrs.ts @@ -1,19 +1,17 @@ import { escapeHtml, - isRenderableAttrValue, - isSVGTag, - stringifyStyle, -} from '@vue/shared' -import { includeBooleanAttr, isBooleanAttr, isOn, + isRenderableAttrValue, isSSRSafeAttrName, + isSVGTag, isString, makeMap, normalizeClass, normalizeStyle, propsToAttrMap, + stringifyStyle, } from '@vue/shared' // leading comma for empty string "" diff --git a/packages/sfc-playground/src/App.vue b/packages/sfc-playground/src/App.vue index 4b62519ce6..83eae6d599 100644 --- a/packages/sfc-playground/src/App.vue +++ b/packages/sfc-playground/src/App.vue @@ -1,8 +1,8 @@