From b2be242fe80b9d1125ff9b8f8ea5fda44efc4aa2 Mon Sep 17 00:00:00 2001 From: maddocnc Date: Thu, 5 Mar 2020 14:02:12 +0300 Subject: [PATCH 1/4] Fix iterateProperties to support arrow functions --- lib/utils/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/utils/index.js b/lib/utils/index.js index 011ec6571..c341eef5b 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -693,6 +693,8 @@ module.exports = { yield * this.iterateObjectExpression(item.value, name) } else if (item.value.type === 'FunctionExpression') { yield * this.iterateFunctionExpression(item.value, name) + } else if (item.value.type === 'ArrowFunctionExpression') { + yield * this.iterateArrowFunctionExpression(item.value, name) } } }, @@ -745,6 +747,24 @@ module.exports = { } }, + /** + * Return generator with all elements inside ArrowFunctionExpression + * @param {ASTNode} node Node to check + * @param {string} groupName Name of parent group + */ + * iterateArrowFunctionExpression (node, groupName) { + assert(node.type === 'ArrowFunctionExpression') + if (node.body.type === 'BlockStatement') { + for (const item of node.body.body) { + if (item.type === 'ReturnStatement' && item.argument && item.argument.type === 'ObjectExpression') { + yield * this.iterateObjectExpression(item.argument, groupName) + } + } + } else if (node.body.type === 'ObjectExpression') { + yield * this.iterateObjectExpression(node.body, groupName) + } + }, + /** * Find all functions which do not always return values * @param {boolean} treatUndefinedAsUnspecified From 29f6cb18c5492364c0ec5c0349b56d3ce6321bb9 Mon Sep 17 00:00:00 2001 From: maddocnc Date: Thu, 5 Mar 2020 14:11:45 +0300 Subject: [PATCH 2/4] indent mistake --- lib/utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index c341eef5b..418ab2f9c 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -752,7 +752,7 @@ module.exports = { * @param {ASTNode} node Node to check * @param {string} groupName Name of parent group */ - * iterateArrowFunctionExpression (node, groupName) { + * iterateArrowFunctionExpression (node, groupName) { assert(node.type === 'ArrowFunctionExpression') if (node.body.type === 'BlockStatement') { for (const item of node.body.body) { From 160b6ef070568b218eac7b9e5c90448ddf70f677 Mon Sep 17 00:00:00 2001 From: maddocnc Date: Fri, 6 Mar 2020 16:43:09 +0300 Subject: [PATCH 3/4] add no-dupe-keys test cases using arrow function --- tests/lib/rules/no-dupe-keys.js | 186 ++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/tests/lib/rules/no-dupe-keys.js b/tests/lib/rules/no-dupe-keys.js index 1abb67642..f1a35568a 100644 --- a/tests/lib/rules/no-dupe-keys.js +++ b/tests/lib/rules/no-dupe-keys.js @@ -45,6 +45,58 @@ ruleTester.run('no-dupe-keys', rule, { parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + filename: 'test.vue', + code: ` + export default { + props: ['foo'], + computed: { + bar () { + } + }, + data: () => { + return { + dat: null + } + }, + data: () => { + return + }, + methods: { + _foo () {}, + test () { + } + } + } + `, + parserOptions: { ecmaVersion: 6, sourceType: 'module' } + }, + + { + filename: 'test.vue', + code: ` + export default { + props: ['foo'], + computed: { + bar () { + } + }, + data: () => ({ + dat: null + }), + data: () => { + return + }, + methods: { + _foo () {}, + test () { + } + } + } + `, + parserOptions: { ecmaVersion: 6, sourceType: 'module' } + }, + { filename: 'test.vue', code: ` @@ -82,6 +134,78 @@ ruleTester.run('no-dupe-keys', rule, { parserOptions: { ecmaVersion: 2018, sourceType: 'module' } }, + { + filename: 'test.vue', + code: ` + export default { + ...foo(), + props: { + ...foo(), + foo: String + }, + computed: { + ...mapGetters({ + test: 'getTest' + }), + bar: { + get () { + } + } + }, + data: { + ...foo(), + dat: null + }, + methods: { + ...foo(), + test () { + } + }, + data: () => { + return { + ...dat + } + }, + } + `, + parserOptions: { ecmaVersion: 2018, sourceType: 'module' } + }, + + { + filename: 'test.vue', + code: ` + export default { + ...foo(), + props: { + ...foo(), + foo: String + }, + computed: { + ...mapGetters({ + test: 'getTest' + }), + bar: { + get () { + } + } + }, + data: { + ...foo(), + dat: null + }, + methods: { + ...foo(), + test () { + } + }, + data: () => ({ + ...dat + }), + } + `, + parserOptions: { ecmaVersion: 2018, sourceType: 'module' } + }, + { filename: 'test.js', code: ` @@ -136,6 +260,68 @@ ruleTester.run('no-dupe-keys', rule, { line: 14 }] }, + { + filename: 'test.vue', + code: ` + export default { + props: ['foo'], + computed: { + foo () { + } + }, + data: () => { + return { + foo: null + } + }, + methods: { + foo () { + } + } + } + `, + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: [{ + message: 'Duplicated key \'foo\'.', + line: 5 + }, { + message: 'Duplicated key \'foo\'.', + line: 10 + }, { + message: 'Duplicated key \'foo\'.', + line: 14 + }] + }, + { + filename: 'test.vue', + code: ` + export default { + props: ['foo'], + computed: { + foo () { + } + }, + data: () => ({ + foo: null + }), + methods: { + foo () { + } + } + } + `, + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: [{ + message: 'Duplicated key \'foo\'.', + line: 5 + }, { + message: 'Duplicated key \'foo\'.', + line: 9 + }, { + message: 'Duplicated key \'foo\'.', + line: 12 + }] + }, { filename: 'test.vue', code: ` From 64ca05d9d82205f529acb6fd4ad17e93e956c141 Mon Sep 17 00:00:00 2001 From: maddocnc Date: Fri, 6 Mar 2020 16:54:48 +0300 Subject: [PATCH 4/4] add no-reserved-keys no-template-shadow test cases using arrow function --- tests/lib/rules/no-reserved-keys.js | 76 +++++++++++++++++ tests/lib/rules/no-template-shadow.js | 116 ++++++++++++++++++++++++++ 2 files changed, 192 insertions(+) diff --git a/tests/lib/rules/no-reserved-keys.js b/tests/lib/rules/no-reserved-keys.js index 08c7f244c..05836bc47 100644 --- a/tests/lib/rules/no-reserved-keys.js +++ b/tests/lib/rules/no-reserved-keys.js @@ -45,6 +45,50 @@ ruleTester.run('no-reserved-keys', rule, { } `, parserOptions + }, + { + filename: 'test.vue', + code: ` + export default { + props: ['foo'], + computed: { + bar () { + } + }, + data: () => { + return { + dat: null + } + }, + methods: { + _foo () {}, + test () { + } + } + } + `, + parserOptions + }, + { + filename: 'test.vue', + code: ` + export default { + props: ['foo'], + computed: { + bar () { + } + }, + data: () => ({ + dat: null + }), + methods: { + _foo () {}, + test () { + } + } + } + `, + parserOptions } ], @@ -79,6 +123,38 @@ ruleTester.run('no-reserved-keys', rule, { line: 4 }] }, + { + filename: 'test.js', + code: ` + new Vue({ + data: () => { + return { + _foo: String + } + } + }) + `, + parserOptions: { ecmaVersion: 6 }, + errors: [{ + message: "Keys starting with with '_' are reserved in '_foo' group.", + line: 5 + }] + }, + { + filename: 'test.js', + code: ` + new Vue({ + data: () => ({ + _foo: String + }) + }) + `, + parserOptions: { ecmaVersion: 6 }, + errors: [{ + message: "Keys starting with with '_' are reserved in '_foo' group.", + line: 4 + }] + }, { filename: 'test.js', code: ` diff --git a/tests/lib/rules/no-template-shadow.js b/tests/lib/rules/no-template-shadow.js index 68fefce0e..08e0e03b6 100644 --- a/tests/lib/rules/no-template-shadow.js +++ b/tests/lib/rules/no-template-shadow.js @@ -70,6 +70,52 @@ ruleTester.run('no-template-shadow', rule, { } } ` + }, + { + filename: 'test.vue', + code: ` + ` + }, + { + filename: 'test.vue', + code: ` + ` } ], @@ -208,6 +254,76 @@ ruleTester.run('no-template-shadow', rule, { type: 'Identifier', line: 7 }] + }, + { + filename: 'test.vue', + code: ` + `, + errors: [{ + message: "Variable 'e' is already declared in the upper scope.", + type: 'Identifier', + line: 6 + }, { + message: "Variable 'f' is already declared in the upper scope.", + type: 'Identifier', + line: 7 + }] + }, + { + filename: 'test.vue', + code: ` + `, + errors: [{ + message: "Variable 'e' is already declared in the upper scope.", + type: 'Identifier', + line: 6 + }, { + message: "Variable 'f' is already declared in the upper scope.", + type: 'Identifier', + line: 7 + }] } ] })