Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Exempting "this" from the "no-shadowed-variable" rule #2214

Closed
wardds opened this issue Feb 17, 2017 · 2 comments · Fixed by #2598
Closed

Exempting "this" from the "no-shadowed-variable" rule #2214

wardds opened this issue Feb 17, 2017 · 2 comments · Fixed by #2598

Comments

@wardds
Copy link

wardds commented Feb 17, 2017

Bug Report

  • TSLint version: 4.4.2
  • TypeScript version: 2.1.6
  • Running TSLint via: (please choose one) Visual Studio Code

TypeScript code being linted

namespace MyNamespace {

	class MyClass {
		public constructor(private myOtherClass: MyOtherClass) {}

		public myFunction(this: MyOtherClass): void {
			function handler(this: MyClass): void {}
		}
	}

	class MyOtherClass {
		public constructor() {}
	}
}

with tslint.json configuration:

"no-shadowed-variable": true,

Actual behavior

message: 'Shadowed variable: 'this' (no-shadowed-variable)' at: '7,21'

Expected behavior

Since typescript 2.0 we can specify the type of this in functions. So technically this is not a variable (since it's not a real parameter) that can be shadowed. I'd like it to be exempted it from this rule.

@adidahiya
Copy link
Contributor

looks like a bug. accepting PRs

@wardds
Copy link
Author

wardds commented Feb 27, 2017

Thanks. My first instinct is to simply add an if statement in this rule's code to check for the first parameter and if it's name is "this". But I'm not very familiar with tslint's source code so there might be a more elegant solution, like having the parameter iterator ignore the this assignments - but that might conflict with other rules that do need to include it. Any thoughts on this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants