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

variable-name rule should support injecting constructors with angular #457

Closed
btesser opened this issue Jun 23, 2015 · 7 comments
Closed

Comments

@btesser
Copy link

btesser commented Jun 23, 2015

The following code makes the variable-name inspection fail, despite the fact it is a valid use case. Any suggestions?

class MyController {
  constructor(ExternalConstructor: IExternalConstructor) {
    var z: IExternal = new ExternalConstructor();
  }
}
@leeavital
Copy link
Contributor

TSLint isn't aware of types, so it doesn't know that ExternalConstructor is being used a constructor. You could write a custom rule that rule that is aware of variables that are used as constructors and allows them to be uppercased.

@Delagen
Copy link

Delagen commented Jul 1, 2015

constructor(@Inject(Http) http:Http)

[typedef] expected parameter: 'Inject' to have a typedef

@leeavital
Copy link
Contributor

@Delagen this looks like an unrelated bug. Moving this to its own issue.

@leeavital
Copy link
Contributor

#479

@btesser
Copy link
Author

btesser commented Jul 1, 2015

Is there any way to specify an argument as a constructor? Maybe by using

function (<Function()=>void>UserConstructor)

Or even

function (UserConstructor: typeof User)

Or some similar syntax. The type definition itself should allow tslint to know it isn't a normal variable

@adidahiya
Copy link
Contributor

We should be able to check in the constructor function block if a variable is used as a constructor, i.e. invoked with new.

Also I think the latest TS language services provide some access to type information, but I haven't looked into it too much yet.

@adidahiya adidahiya changed the title variable-name doesn't support injecting constructors with angular variable-name rule should support injecting constructors with angular Jul 20, 2015
@adidahiya adidahiya added the P1 label Aug 13, 2015
@adidahiya
Copy link
Contributor

I think this request is best now addressed by the pascal-case option for the variable-name rule. The above solutions seem overly complicated compared to that option, so I'm closing this out.

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

No branches or pull requests

4 participants