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

Rewrite and fix EnableDisableRulesWalker #2062

Merged
merged 3 commits into from
Jan 21, 2017
Merged

Rewrite and fix EnableDisableRulesWalker #2062

merged 3 commits into from
Jan 21, 2017

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented Jan 17, 2017

PR checklist

  • Addresses an existing issue: #0000
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update
  • Enable CircleCI for your fork (https://circleci.com/add-projects)

What changes did you make?

  • Add minor clarification to line switches documentation.
  • Split up methods into maintainable chunks of code
  • Fix bugs to make behaviour as described in the docs:
    • enable-line and disable-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 and disable-next-line switched from the start of the comment instead of the start of the next line.
    • handling of multiline comment end
      • /*tslint:disable foo bar*/ removed bar*/ resulting in swiching only foo
      • /*tslint:disable foo*/ removed foo*/ resulting in switching all rules
      • /*tslint:disable:foo*/ tried to switch rule foo*/, which does not exist -> nothing changed
  • add tests for everything stated above

Is 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 of RuleWalker. 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 every Rule 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.

constructor(sourceFile: ts.SourceFile, options: IOptions, rules: {[name: string]: any}) {
super(sourceFile, options);
export class EnableDisableRulesWalker {
private enableDisableRuleMap: {[rulename: string]: IEnableDisablePosition[]};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a Map?

Copy link
Contributor Author

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);
Copy link
Contributor

@andy-hanson andy-hanson Jan 18, 2017

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@nchen63 nchen63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Thanks

@nchen63
Copy link
Contributor

nchen63 commented Jan 21, 2017

Also, I don't think anyone is using this class so I don't think it's breaking

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

Successfully merging this pull request may close these issues.

3 participants