From 9dcbe246dac6624acbb9e1dac0c3449819a66737 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Fri, 2 Jul 2021 17:18:12 +0900 Subject: [PATCH] Update `vue/no-mutating-props` rule to support ` ` + }, + { + filename: 'test.vue', + code: ` + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` } ], @@ -698,6 +725,65 @@ ruleTester.run('no-mutating-props', rule, { `, errors: ['Unexpected mutation of "[a]" prop.'] + }, + + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: 'Unexpected mutation of "value" prop.', + line: 3 + }, + { + message: 'Unexpected mutation of "props" prop.', + line: 4 + } + ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + message: 'Unexpected mutation of "value" prop.', + line: 6 + } + ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + message: 'Unexpected mutation of "value" prop.', + line: 6 + } + ] } ] }) diff --git a/typings/eslint-plugin-vue/util-types/utils.ts b/typings/eslint-plugin-vue/util-types/utils.ts index 6888e9a41..e1633eb5d 100644 --- a/typings/eslint-plugin-vue/util-types/utils.ts +++ b/typings/eslint-plugin-vue/util-types/utils.ts @@ -27,3 +27,60 @@ export interface VueVisitor extends VueVisitorBase { | ((node: VAST.ParamNode, obj: VueObjectData) => void) | undefined } + +type ScriptSetupVisitorBase = { + [T in keyof NodeListenerMap]?: (node: NodeListenerMap[T]) => void +} +export interface ScriptSetupVisitor extends ScriptSetupVisitorBase { + onDefinePropsEnter?( + node: CallExpression, + props: (ComponentArrayProp | ComponentObjectProp)[] + ): void + onDefinePropsExit?( + node: CallExpression, + props: (ComponentArrayProp | ComponentObjectProp)[] + ): void + [query: string]: + | ((node: VAST.ParamNode) => void) + | (( + node: CallExpression, + props: (ComponentArrayProp | ComponentObjectProp)[] + ) => void) + | undefined +} + +type ComponentArrayPropDetectName = { + type: 'array' + key: Literal | TemplateLiteral + propName: string + value: null + node: Expression | SpreadElement +} +type ComponentArrayPropUnknownName = { + type: 'array' + key: null + propName: null + value: null + node: Expression | SpreadElement +} +export type ComponentArrayProp = + | ComponentArrayPropDetectName + | ComponentArrayPropUnknownName + +type ComponentObjectPropDetectName = { + type: 'object' + key: Expression + propName: string + value: Expression + node: Property +} +type ComponentObjectPropUnknownName = { + type: 'object' + key: null + propName: null + value: Expression + node: Property +} +export type ComponentObjectProp = + | ComponentObjectPropDetectName + | ComponentObjectPropUnknownName