-
Notifications
You must be signed in to change notification settings - Fork 887
Set --lib es6
, and use Map
/Set
methods where possible.
#1984
Conversation
ba5787c
to
5e72879
Compare
this.addFailureAtNode(node, Rule.FAILURE_STRING); | ||
} | ||
const isNumber = node.kind === ts.SyntaxKind.NumericLiteral && !Rule.ALLOWED_NODES.has(node.parent!.kind); | ||
const isMagicNumber = (isNumber || isUnary) && !this.allowed.has(node.getText()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the isUnary
case should also check for ALLOWED_NODES
, but this is what it did before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Opened issue #2005
|
||
class PreferForOfWalker extends Lint.BlockScopeAwareRuleWalker<{}, IncrementorMap> { | ||
public createScope() { | ||
return {}; | ||
return new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method could just return void
(need to update type parameters). scope
is never used anywhere, only blockScope
is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much cleaner
@@ -21,11 +21,10 @@ import {IOptions} from "../rule/rule"; | |||
import {RuleWalker} from "./ruleWalker"; | |||
|
|||
export class SkippableTokenAwareRuleWalker extends RuleWalker { | |||
protected tokensToSkipStartEndMap: {[start: number]: number}; | |||
private tokensToSkipStartEndMap = new Map<number, number>(); | |||
|
|||
constructor(sourceFile: ts.SourceFile, options: IOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need constructor anymore
this.addFailureAtNode(node, Rule.FAILURE_STRING); | ||
} | ||
const isNumber = node.kind === ts.SyntaxKind.NumericLiteral && !Rule.ALLOWED_NODES.has(node.parent!.kind); | ||
const isMagicNumber = (isNumber || isUnary) && !this.allowed.has(node.getText()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Opened issue #2005
@andy-hanson thanks! |
this is an awesome PR, thanks @andy-hanson |
PR checklist
What changes did you make?
Set the
"lib"
option to["es6", "dom"]
("dom" typings used by underscore).EDIT: Removed underscore; it's only used by 1 function,
camelize
, that's a one-liner. Their source, mine.Used
Map
andSet
in cases where their absence appeared to have been compensated for.Is there anything you'd like reviewers to focus on?
It's more efficient to lookup in a Map only once, so avoid this pattern:
Prefer: