-
Notifications
You must be signed in to change notification settings - Fork 889
Rule suggestion: restrict + operands #697
Comments
I've made a start, but just run into a problem |
sounds like a good lint rule, thanks for looking into this! |
TSLint currently only gets type information on a per-file basis, so to do this properly, I think we're blocked on #680 |
Ah. Is that why the |
Sorry, to be more explicit: that question relates to the TypeScript issue I created |
No, I'm not sure why the type checker returns Perhaps we're not instantiating the checker correctly? |
Hmm, having done a quick test I think it is related. In the following example the import {Banana} from "./somewhere_else";
// Banana has type signature: Banana(): string
let y = "test" + Banana(); My guess would be that when it hits an identifier defined outside of the scope of what is being checked it assumes an |
Right, there's obviously no way for the TypeChecker to know what |
This one is approved to be implemented in |
@alexeagle but only if you use |
@alexeagle thanks for the link. Agreed with @myitcv that it can still be a TSLint rule that is a more granular opt-in than |
* Changed Linter to accept multiple files (constructor overload) * Created TypedRule class which accepts a Program with a SourceFile * Rules extending this class can now access the type checker by implementing applyWithProgram * Added an example restrictPlusOperands rule (palantir#697) that uses the types * Added a fixes interface to RuleFailure, allowing text-replacement suggested fixes
* Changed Linter to accept multiple files (constructor overload) * Created TypedRule class which receives a Program with a SourceFile * Rules extending this class can now access the type checker by implementing applyWithProgram * Added an example restrictPlusOperands rule (palantir#697) that uses types
* Changed Linter to accept multiple files (constructor overload) * Created TypedRule class which receives a Program with a SourceFile * Rules extending this class can now access the type checker by implementing applyWithProgram * Added an example restrictPlusOperands rule (palantir#697) that uses types
* Changed Linter to accept multiple files (constructor overload) * Created TypedRule class which receives a Program with a SourceFile * Rules extending this class can now access the type checker by implementing applyWithProgram * Added an example restrictPlusOperands rule (palantir#697) that uses types
This rule restricts the + operands to either both numbers or both strings. Relates to palantir#697
This rule restricts the + operands to either both numbers or both string. Relates to palantir#697
This rule restricts the + operands to either both numbers or both string. Relates to palantir#697
Can this be closed now we have https://palantir.github.io/tslint/rules/restrict-plus-operands/? |
With reference to the binary
+
operator in the specI find it rather disconcerting that this is allowed:
Would there be interest in a rule that forces the two operands to
+
to either:string
number
and fail otherwise?
Do we have the necessary type information available during linting to do this?
The text was updated successfully, but these errors were encountered: