-
Notifications
You must be signed in to change notification settings - Fork 888
no-unused-variable: shouldn't warn about all params in some cases #1337
Comments
You can use the "ignore-pattern" option in this case to specify a regex that corresponds to variables that are intentionally unused. For example,
would ignore all variables that start with an underscore and not report errors when they are unused. Going to close this issue because "ignore-pattern" is designed exactly for this scenario! |
so I'd have to go through my code and rename variables based on their parameter order just to satisfy this rule? |
Yep, but it's not that unusual: starting unused variables with an underscore is a standard convention in languages with stricter compilers, like Go and Rust, as far as I know. |
So if I were to rename that first var to |
Good question - I believe the rule only works one way here. TSLint won't complain if you use a variable that meets the "ignore-pattern" option |
Perhaps that could be a configurable option to add to this rule? |
to me it is a bug, tslint should not throw error in this case. |
@marcoturi no-unused-variable is deprecated in favor of compiler options and we plan to remove it in the next major version, see #1481. I filed #1851 to address the sparse documentation around this. |
Bug Report
3.11.0
1.8.10
gulp-tslint
via Visual Studio 2015TypeScript code being linted
with
tslint.json
configuration:Actual behavior
The
event
parameter is reported as unused, which is technically correct... but it has to be there so I can access the 2nd parameter, which I need.Right now I'm needing to put comments like
// tslint:disable-next-line:no-unused-variable
all over the place.Expected behavior
Since I only need to use the 2nd parameter, it seems dumb to warn me about the first parameter not being used since this is how the framework I'm using works.
The text was updated successfully, but these errors were encountered: