Skip to content

[@typescript-eslint/no-unnecessary-type-assertion] Puzzling fix in vue ts project #2591

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

Closed
3 tasks done
eightHundreds opened this issue Sep 22, 2020 · 4 comments · Fixed by #2680
Closed
3 tasks done
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@eightHundreds
Copy link

eightHundreds commented Sep 22, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

https://github.com/eightHundreds/eslint-vue-ts--typescript-eslint-no-unnecessary-type-assertion-issue

  1. git clone
  2. npm i
  3. npx eslint ./src/components/tmp.vue --fix

Expected Result

<script lang="ts">
/* eslint-disable class-methods-use-this */
export default class Cmp {
  get a() {
    const list: Array<string> = [];
    return list;
  }

  async mounted() {
    this.a as Array<string>;
  }
}
</script>

Actual Result

<script lang="ts">
/* eslint-disable class-methods-use-this */
export default class Cmp {
  get a() {
    const list: Array<string> = [];
    return list;
  }

  async mouna as Array<string>;
  }
}
</script>

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.2.0
@typescript-eslint/parser 4.2.0
TypeScript 3.9.3
ESLint 7.9.0
node 10.14.2
@eightHundreds eightHundreds added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Sep 22, 2020
@bradzacher
Copy link
Member

You ticked the box saying you've upgraded to the latest version of our tooling, but you've listed v2.33.0 as your version. This version is 4 months old.............

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Sep 22, 2020
@eightHundreds
Copy link
Author

You ticked the box saying you've upgraded to the latest version of our tooling, but you've listed v2.33.0 as your version. This version is 4 months old.............

I upgraded and the problem still exists

@bradzacher
Copy link
Member

I upgraded and the problem still exists

You should always try the latest version before filing an issue to ensure that it hasn't been fixed. We release every week, so there's a chance the latest version has fixed an issue.


This is occurring because the lint rule uses the typescript nodes to do the fixes.

return originalNode.kind === ts.SyntaxKind.TypeAssertionExpression
? fixer.removeRange([
originalNode.getStart(),
originalNode.expression.getStart(),
])
: fixer.removeRange([
originalNode.expression.end,
originalNode.end,
]);

vue-eslint-parser alters the locations information for every node it produces within a script tag, but it doesn't know about the typescript nodes, so their range information is wrong. The fix is being applied as if there was no script tag.

Simple fix - happy to accept a PR.

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed awaiting response Issues waiting for a reply from the OP or another party labels Sep 24, 2020
@thomasmichaelwallace
Copy link
Contributor

Happy to pick this up-

thomasmichaelwallace added a commit to thomasmichaelwallace/typescript-eslint that referenced this issue Oct 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants