0

Is it possible to make VS Code highlight unused parameters? I'm working on a Vue component with TypeScript if this make any difference.

It shows unused imports just fine:
enter image description here

but not unused properties:
enter image description here

I have added this to my settings.json file but it didn't help.

"editor.showUnused": true,
"workbench.colorCustomizations": {
    "editorUnnecessaryCode.border": "#ff0000"
}

Vue component example

import Vue from 'vue';
import { Component } from 'vue-property-decorator';

@Component
    export default class VueComponentExample extends Vue {

    bla: boolean = false;
  
}
</script>
starball
  • 20,030
  • 7
  • 43
  • 238
  • This can be achieved thanks to ESlint: https://stackoverflow.com/a/68225547/8816585 – kissu Dec 01 '22 at 12:32
  • I just tried "no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }] from the doc https://eslint.org/docs/latest/rules/no-unused-vars it got some properties but it's still not showing local component properties. – Dan Sørensen Dec 01 '22 at 12:56
  • What do you mean exactly by `local component properties`? Mind sharing your whole ESlint setup? Got a public github repo? – kissu Dec 01 '22 at 13:05
  • thanks for the help so far kissu ! :) Just added a little example, and the bla property is the one I'm referring to. the eslint file isn't that interesting it only have some indent, quotes, semi and vue/html-indent so I pretty sure nothing in here should cause this. – Dan Sørensen Dec 01 '22 at 14:51
  • Not sure how it behaves with `vue-property-decorator`, but ESlint should be able to find out what is not used so far. Maybe you need something additional while using classes like there. – kissu Dec 01 '22 at 15:14

1 Answers1

0

Since in your tags you indicate that you are using TypeScript, you can use the noUnusedParameters tsconfig setting. Quoting from the setting's docs:

Report errors on unused parameters in functions.

Like so in the tsconfig.json:

{
  ...
  "compilerOptions": {
    ...
    "noUnusedParameters": true,
    ...
  }
  ...
}

Or, as indicated in the comments by @kissu, you could use ESLint. For some tips on setup, see Vue 2 - ESLint + Standard + Prettier.

starball
  • 20,030
  • 7
  • 43
  • 238