From b94645f4e8dc8ea6c55c5520964516416fa8c280 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 3 Jul 2021 16:23:26 +0900 Subject: [PATCH] Update `vue/return-in-emits-validator` rule to support ` ` + }, + { + filename: 'test.vue', + code: ` + + ` } ], @@ -307,6 +319,24 @@ ruleTester.run('return-in-emits-validator', rule, { line: 5 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + message: + 'Expected to return a boolean value in "foo" emits validator.', + line: 4 + } + ] } ] }) diff --git a/typings/eslint-plugin-vue/global.d.ts b/typings/eslint-plugin-vue/global.d.ts index 543eed56c..96ceee311 100644 --- a/typings/eslint-plugin-vue/global.d.ts +++ b/typings/eslint-plugin-vue/global.d.ts @@ -155,6 +155,9 @@ declare global { type TSTypeParameterInstantiation = VAST.TSTypeParameterInstantiation type TSPropertySignature = VAST.TSPropertySignature type TSMethodSignature = VAST.TSMethodSignature + type TSLiteralType = VAST.TSLiteralType + type TSCallSignatureDeclaration = VAST.TSCallSignatureDeclaration + type TSFunctionType = VAST.TSFunctionType // ---- JSX Nodes ---- diff --git a/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts b/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts index ef68b4514..a79d457f4 100644 --- a/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts @@ -9,6 +9,9 @@ export type TSNode = | TSTypeParameterInstantiation | TSPropertySignature | TSMethodSignatureBase + | TSLiteralType + | TSCallSignatureDeclaration + | TSFunctionType export interface TSAsExpression extends HasParentNode { type: 'TSAsExpression' @@ -70,3 +73,20 @@ interface TSMethodSignatureNonComputedName extends TSMethodSignatureBase { key: TSESTree.PropertyNameNonComputed computed: false } + +export interface TSLiteralType extends HasParentNode { + type: 'TSLiteralType' + literal: ES.Literal | ES.UnaryExpression | ES.UpdateExpression +} + +interface TSFunctionSignatureBase extends HasParentNode { + params: TSESTree.Parameter[] + returnType?: TSESTree.TSTypeAnnotation + typeParameters?: TSESTree.TSTypeParameterDeclaration +} +export interface TSCallSignatureDeclaration extends TSFunctionSignatureBase { + type: 'TSCallSignatureDeclaration' +} +export interface TSFunctionType extends TSFunctionSignatureBase { + type: 'TSFunctionType' +} diff --git a/typings/eslint-plugin-vue/util-types/utils.ts b/typings/eslint-plugin-vue/util-types/utils.ts index adece39a9..7258cb673 100644 --- a/typings/eslint-plugin-vue/util-types/utils.ts +++ b/typings/eslint-plugin-vue/util-types/utils.ts @@ -44,11 +44,23 @@ export interface ScriptSetupVisitor extends ScriptSetupVisitorBase { node: CallExpression, props: (ComponentArrayProp | ComponentObjectProp | ComponentTypeProp)[] ): void + onDefineEmitsEnter?( + node: CallExpression, + props: (ComponentArrayEmit | ComponentObjectEmit | ComponentTypeEmit)[] + ): void + onDefineEmitsExit?( + node: CallExpression, + props: (ComponentArrayEmit | ComponentObjectEmit | ComponentTypeEmit)[] + ): void [query: string]: | ((node: VAST.ParamNode) => void) | (( node: CallExpression, - props: (ComponentArrayProp | ComponentObjectProp)[] + props: (ComponentArrayProp | ComponentObjectProp | ComponentTypeProp)[] + ) => void) + | (( + node: CallExpression, + props: (ComponentArrayEmit | ComponentObjectEmit | ComponentTypeEmit)[] ) => void) | undefined } @@ -99,3 +111,46 @@ export type ComponentTypeProp = { required: boolean types: string[] } + +type ComponentArrayEmitDetectName = { + type: 'array' + key: Literal | TemplateLiteral + emitName: string + value: null + node: Expression | SpreadElement +} +type ComponentArrayEmitUnknownName = { + type: 'array' + key: null + emitName: null + value: null + node: Expression | SpreadElement +} +export type ComponentArrayEmit = + | ComponentArrayEmitDetectName + | ComponentArrayEmitUnknownName +type ComponentObjectEmitDetectName = { + type: 'object' + key: Expression + emitName: string + value: Expression + node: Property +} +type ComponentObjectEmitUnknownName = { + type: 'object' + key: null + emitName: null + value: Expression + node: Property +} +export type ComponentObjectEmit = + | ComponentObjectEmitDetectName + | ComponentObjectEmitUnknownName + +export type ComponentTypeEmit = { + type: 'type' + key: TSLiteralType + emitName: string + value: null + node: TSCallSignatureDeclaration | TSFunctionType +}