Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(order-in-components): allow autofix with TypeScript PropType #1955

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rules/order-in-components.js
Expand Up @@ -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 (
Expand Down
43 changes: 43 additions & 0 deletions tests/lib/autofix.js
Expand Up @@ -172,3 +172,46 @@ describe('Complex autofix test cases', () => {
})
})
})

describe('Autofix test cases with Typescript', () => {
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
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 = `
<script lang="ts">
export default {
setup () {},
props: {
foo: { type: Array as PropType<number[]> },
}
};
</script>`

const output = `
<script lang="ts">
export default {
props: {
foo: { type: Array as PropType<number[]> },
},
setup () {}
};
</script>`

assert.equal(tsLinter.verifyAndFix(code, config, 'test.vue').output, output)
})
})
})