-
Notifications
You must be signed in to change notification settings - Fork 887
Rewrite and fix EnableDisableRulesWalker #2062
Conversation
constructor(sourceFile: ts.SourceFile, options: IOptions, rules: {[name: string]: any}) { | ||
super(sourceFile, options); | ||
export class EnableDisableRulesWalker { | ||
private enableDisableRuleMap: {[rulename: string]: IEnableDisablePosition[]}; |
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.
Use a 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.
I wanted to change that, but there are many exported functions that expect this to be an object. So this would require a larger rewrite.
|
||
return ruleStateMap[ruleStateMap.length - 1].isEnabled; | ||
private handleComment(commentText: string, pos: TokenPosition) { | ||
const match = /^\s*tslint:/.exec(commentText); |
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.
How about /^\s*tslint:((enable|disable)(-(line|next-line))?)/
and use the capture groups?
|
||
constructor(sourceFile: ts.SourceFile, options: IOptions, rules: {[name: string]: any}) { | ||
super(sourceFile, options); | ||
export class EnableDisableRulesWalker { |
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.
Since there's no walk()
this could use a name change.
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.
Sounds reasonable. Open for suggestions
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.
looks good. Thanks
Also, I don't think anyone is using this class so I don't think it's breaking |
PR checklist
What changes did you make?
enable-line
anddisable-line
switched from the start of the line only to the end of the comment. That is correct for single line comments, but multiline comments can be followed by other statements.enable-next-line
anddisable-next-line
switched from the start of the comment instead of the start of the next line./*tslint:disable foo bar*/
removedbar*/
resulting in swiching onlyfoo
/*tslint:disable foo*/
removedfoo*/
resulting in switching all rules/*tslint:disable:foo*/
tried to switch rulefoo*/
, which does not exist -> nothing changedIs there anything you'd like reviewers to focus on?
Don't know if this is a breaking change, because it used to be this way for a while, although not documented.
Furthermore this changes the API of
EnableDisableRulesWalker
which is no longer a subclass ofRuleWalker
. This class is exported by the package, so it could be used by others. Don't know if care or if we even want to support this, because technically everyRule
could be used from outside the project.If we consider this an implementation detail, we should remove the export in
index.ts
for the next major version. This should also be done for all other "internal" functions and classes.