Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55111af

Browse files
fix(eslint-plugin): [no-unnecessary-type-assertion] correct fixer for vue files (typescript-eslint#2680)
1 parent c505863 commit 55111af

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ export default util.createRule<Options, MessageIds>({
241241
fix(fixer) {
242242
return originalNode.kind === ts.SyntaxKind.TypeAssertionExpression
243243
? fixer.removeRange([
244-
originalNode.getStart(),
245-
originalNode.expression.getStart(),
244+
node.range[0],
245+
node.expression.range[0] - 1,
246246
])
247247
: fixer.removeRange([
248-
originalNode.expression.end,
249-
originalNode.end,
248+
node.expression.range[1] + 1,
249+
node.range[1],
250250
]);
251251
},
252252
});

tests/integration/fixtures/vue-sfc/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ module.exports = {
1919
],
2020
rules: {
2121
'@typescript-eslint/no-explicit-any': 'error',
22+
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
23+
'semi-spacing': 'error',
2224
},
2325
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script lang="ts">
2+
/* https://github.com/typescript-eslint/typescript-eslint/issues/2591 */
3+
/* eslint-disable class-methods-use-this */
4+
export default class Utility {
5+
get a() {
6+
const list: Array<string> = [];
7+
return list;
8+
}
9+
10+
get b() {
11+
const a = this.a as Array<string>;
12+
return a;
13+
}
14+
}
15+
</script>

tests/integration/fixtures/vue-sfc/test.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ export default Vue.extend({
8080
}
8181
});
8282
</script>
83+
",
84+
"usedDeprecatedRules": Array [],
85+
"warningCount": 0,
86+
},
87+
Object {
88+
"errorCount": 0,
89+
"filePath": "/usr/linked/Utility.vue",
90+
"fixableErrorCount": 0,
91+
"fixableWarningCount": 0,
92+
"messages": Array [],
93+
"output": "<script lang=\\"ts\\">
94+
/* https://github.com/typescript-eslint/typescript-eslint/issues/2591 */
95+
/* eslint-disable class-methods-use-this */
96+
export default class Utility {
97+
get a() {
98+
const list: Array<string> = [];
99+
return list;
100+
}
101+
102+
get b() {
103+
const a = this.a;
104+
return a;
105+
}
106+
}
107+
</script>
83108
",
84109
"usedDeprecatedRules": Array [],
85110
"warningCount": 0,

tests/integration/fixtures/vue-sfc/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ npm install vuex@latest vue-property-decorator@latest
2323

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

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

0 commit comments

Comments
 (0)