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(eslint-plugin): [no-unnecessary-type-assertion] correct fixer for vue files #2680

Merged
merged 3 commits into from Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -241,12 +241,12 @@ export default util.createRule<Options, MessageIds>({
fix(fixer) {
return originalNode.kind === ts.SyntaxKind.TypeAssertionExpression
? fixer.removeRange([
originalNode.getStart(),
originalNode.expression.getStart(),
node.range[0],
node.expression.range[0] - 1,
])
: fixer.removeRange([
originalNode.expression.end,
originalNode.end,
node.expression.range[1] + 1,
node.range[1],
]);
},
});
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/fixtures/vue-sfc/.eslintrc.js
Expand Up @@ -19,5 +19,7 @@ module.exports = {
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'semi-spacing': 'error',
},
};
15 changes: 15 additions & 0 deletions tests/integration/fixtures/vue-sfc/Utility.vue
@@ -0,0 +1,15 @@
<script lang="ts">
/* https://github.com/typescript-eslint/typescript-eslint/issues/2591 */
/* eslint-disable class-methods-use-this */
export default class Utility {
get a() {
const list: Array<string> = [];
return list;
}

get b() {
const a = this.a as Array<string>;
return a;
}
}
</script>
25 changes: 25 additions & 0 deletions tests/integration/fixtures/vue-sfc/test.js.snap
Expand Up @@ -80,6 +80,31 @@ export default Vue.extend({
}
});
</script>
",
"usedDeprecatedRules": Array [],
"warningCount": 0,
},
Object {
"errorCount": 0,
"filePath": "/usr/linked/Utility.vue",
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"messages": Array [],
"output": "<script lang=\\"ts\\">
/* https://github.com/typescript-eslint/typescript-eslint/issues/2591 */
/* eslint-disable class-methods-use-this */
export default class Utility {
get a() {
const list: Array<string> = [];
return list;
}

get b() {
const a = this.a;
return a;
}
}
</script>
",
"usedDeprecatedRules": Array [],
"warningCount": 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/fixtures/vue-sfc/test.sh
Expand Up @@ -23,7 +23,7 @@ npm install vuex@latest vue-property-decorator@latest

# Run the linting
# (the "|| true" helps make sure that we run our tests on failed linting runs as well)
npx eslint --format json --output-file /usr/lint-output.json --config /usr/linked/.eslintrc.js /usr/linked/**/*.vue || true
npx eslint --format json --output-file /usr/lint-output.json --config /usr/linked/.eslintrc.js /usr/linked/**/*.vue --fix-dry-run || true

# Run our assertions against the linting output
npx jest /usr/test.js --snapshotResolver=/usr/utils/jest-snapshot-resolver.js