Skip to content

Commit

Permalink
chore: restrict duplicated imports, support Vue SFC for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jun 4, 2024
1 parent 3b0a56a commit 0f3725b
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 38 deletions.
14 changes: 13 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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,
Expand Down Expand Up @@ -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}`) },
Expand All @@ -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/**'],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 7 additions & 10 deletions packages/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -1505,16 +1512,6 @@ describe('withKeys and withModifiers as pro', () => {
;<input onKeydown={onKeydown} onClick={onClick} />
})

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<
Expand Down
7 changes: 5 additions & 2 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
13 changes: 7 additions & 6 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,11 +49,6 @@ import {
onUnmounted,
onUpdated,
} from './apiLifecycle'
import {
type ComputedGetter,
type WritableComputedOptions,
reactive,
} from '@vue/reactivity'
import type {
ComponentObjectPropsOptions,
ComponentPropsOptions,
Expand Down
7 changes: 5 additions & 2 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
12 changes: 6 additions & 6 deletions packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostElement = RendererElement> {
Expand Down
8 changes: 3 additions & 5 deletions packages/server-renderer/src/helpers/ssrRenderAttrs.ts
Original file line number Diff line number Diff line change
@@ -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 ""
Expand Down
4 changes: 2 additions & 2 deletions packages/sfc-playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import Header from './Header.vue'
import { Repl, useStore, SFCOptions, useVueImportMap } from '@vue/repl'
import { Repl, type SFCOptions, useStore, useVueImportMap } from '@vue/repl'
import Monaco from '@vue/repl/monaco-editor'
import { ref, watchEffect, onMounted, computed } from 'vue'
import { computed, onMounted, ref, watchEffect } from 'vue'
const replRef = ref<InstanceType<typeof Repl>>()
Expand Down
43 changes: 42 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f3725b

Please sign in to comment.