Navigation Menu

Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unnecessary-type-assertion] correct fixer for…
Browse files Browse the repository at this point in the history
… vue files (#2680)
  • Loading branch information
thomasmichaelwallace committed Oct 18, 2020
1 parent c505863 commit 55111af
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
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

0 comments on commit 55111af

Please sign in to comment.