3.11.01.8.10gulp-tslint via Visual Studio 2015this.$scope.$on("$myEvent", (event: angular.IAngularEvent, customerNumber: string) => {
this.getCustomerInfo(customerNumber);
});
with tslint.json configuration:
"no-unused-variable": [ true, "check-parameters" ],
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.
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.
You can use the "ignore-pattern" option in this case to specify a regex that corresponds to variables that are intentionally unused. For example,
"no-unused-variable": [true, {"ignore-pattern": "^_"}]
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 _event and later on it was used by someone who was not aware of this convention, would that be flagged?
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.
Most helpful comment
to me it is a bug, tslint should not throw error in this case.