From 202b3e7b16cbb22aba42a33d6695d5379a375e2c Mon Sep 17 00:00:00 2001 From: Maxim Nazarjev Date: Thu, 1 Sep 2022 00:06:52 +0300 Subject: [PATCH 1/4] fix(order-in-components): allow autofix with typescript PropType helper --- lib/rules/order-in-components.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rules/order-in-components.js b/lib/rules/order-in-components.js index 1e0b517f8..1ecc49254 100644 --- a/lib/rules/order-in-components.js +++ b/lib/rules/order-in-components.js @@ -171,7 +171,9 @@ function isNotSideEffectsNode(node, visitorKeys) { node.type === 'Literal' || // es2015 node.type === 'ArrowFunctionExpression' || - node.type === 'TemplateElement' + node.type === 'TemplateElement' || + // typescript + node.type === 'TSAsExpression' ) { skipNode = node } else if ( From 0ff2455a28bb1d2eab3b94f2985b8c8c9331e6d6 Mon Sep 17 00:00:00 2001 From: Maxim Nazarjev Date: Thu, 1 Sep 2022 19:33:11 +0300 Subject: [PATCH 2/4] test(order-in-components): add tests for props with type assertions --- tests/lib/autofix.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/lib/autofix.js b/tests/lib/autofix.js index bb08d0f36..749300352 100644 --- a/tests/lib/autofix.js +++ b/tests/lib/autofix.js @@ -172,3 +172,46 @@ describe('Complex autofix test cases', () => { }) }) }) + +describe('Autofix test cases with Typescript', () => { + const tsLinter = new Linter() + tsLinter.defineParser('vue-eslint-parser', parser) + for (const key of Object.keys(rules)) { + const ruleId = `vue/${key}` + tsLinter.defineRule(ruleId, rules[key]) + } + + describe('Autofix of `vue/order-in-components` with type assertions in "props".', () => { + const config = Object.assign({}, baseConfig, { + rules: { + 'vue/order-in-components': ['error', { order: ['props', 'setup'] }] + }, + }) + + config.parserOptions.parser = { 'ts': require.resolve('@typescript-eslint/parser') } + + it('Should fix fields order', () => { + const code = ` + ` + + const output = ` + ` + + assert.equal(tsLinter.verifyAndFix(code, config, 'test.vue').output, output) + }) + }) +}) From f559da46eb9086ef5c8dff78591be93b0b79451d Mon Sep 17 00:00:00 2001 From: Maxim Nazarjev Date: Fri, 2 Sep 2022 12:10:06 +0300 Subject: [PATCH 3/4] test(order-in-components): update tests --- tests/lib/autofix.js | 43 -------------------------- tests/lib/rules/order-in-components.js | 37 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 44 deletions(-) diff --git a/tests/lib/autofix.js b/tests/lib/autofix.js index 749300352..bb08d0f36 100644 --- a/tests/lib/autofix.js +++ b/tests/lib/autofix.js @@ -172,46 +172,3 @@ describe('Complex autofix test cases', () => { }) }) }) - -describe('Autofix test cases with Typescript', () => { - const tsLinter = new Linter() - tsLinter.defineParser('vue-eslint-parser', parser) - for (const key of Object.keys(rules)) { - const ruleId = `vue/${key}` - tsLinter.defineRule(ruleId, rules[key]) - } - - describe('Autofix of `vue/order-in-components` with type assertions in "props".', () => { - const config = Object.assign({}, baseConfig, { - rules: { - 'vue/order-in-components': ['error', { order: ['props', 'setup'] }] - }, - }) - - config.parserOptions.parser = { 'ts': require.resolve('@typescript-eslint/parser') } - - it('Should fix fields order', () => { - const code = ` - ` - - const output = ` - ` - - assert.equal(tsLinter.verifyAndFix(code, config, 'test.vue').output, output) - }) - }) -}) diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js index 76d510964..feb75146b 100644 --- a/tests/lib/rules/order-in-components.js +++ b/tests/lib/rules/order-in-components.js @@ -908,6 +908,41 @@ ruleTester.run('order-in-components', rule, { line: 15 } ] - } + }, + { + filename: 'example.vue', + code: ` + + `, + parser: require.resolve('vue-eslint-parser'), + parserOptions: { + ...parserOptions, + parser: { ts: require.resolve('@typescript-eslint/parser') } + }, + output: ` + + `, + errors: [ + { + message: + 'The "props" property should be above the "setup" property on line 4.', + line: 5 + } + ] + }, ] }) From 5df0a29d8ed204565f6ab7800987bc8e90d81495 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Fri, 2 Sep 2022 11:20:34 +0200 Subject: [PATCH 4/4] Remove trailing comma --- tests/lib/rules/order-in-components.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js index feb75146b..873df3b0f 100644 --- a/tests/lib/rules/order-in-components.js +++ b/tests/lib/rules/order-in-components.js @@ -943,6 +943,6 @@ ruleTester.run('order-in-components', rule, { line: 5 } ] - }, + } ] })