quick-lint-js
quick-lint-js copied to clipboard
warn on unused variables
- [ ] #1075
Configuration idea:
"warn-if-unused": true
// don't warn for let, params, functions, classes, types, ...
"warn-if-unused": ["import", "const"]
"warn-if-unused": {
"/[^_].*/": true, // warn on any variable without a _ prefix
"/^.*/": ["import"] // warn on all unused imported variables
}
Concern: What if multiple regexp patterns match? Concern: Should we try to be compatible with ESLint?
Alternative config idea:
"warn-if-unused": true
// don't warn for let, params, functions, classes, types, ...
"warn-if-unused": ["import", "const"]
"warn-if-unused": [
"import", // warn on all unused imported variables
{"/[^_].*/": ["const", "let", "var"]}, // warn on any local var without a _ prefix
"/^[A-Z].*/" // warn on anything unused starting with a capital letter
]
Array items are processed in order. If no array item matches, don't warn.
But how would we say "warn for unused anything except unused classes"?
Another idea (probably bad):
"warn-if-unused": [
"import", // warn on all unused imported variables
["/[^_].*/", ["const", "let", "var"]], // warn on any local var without a _ prefix
"/^[A-Z].*/" // warn on anything unused starting with a capital letter
]
Outer-most array is 'or', but middle arrays are 'and', and inner-most arrays are 'or'.
Verbose style:
"warn-if-unused": [
"import",
{"name": "/[^_].*/", "kind": ["const", "let", "var"], "warn": true},
"/^[A-Z].*/"
]
I think I like the verbose style for clarity.
jooc would
const {a} = require('foo')
be an import or const type?
const