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

Single line ignore switches #1175

Merged
merged 5 commits into from
Apr 29, 2016
Merged

Single line ignore switches #1175

merged 5 commits into from
Apr 29, 2016

Conversation

patsissons
Copy link
Contributor

This PR supports using ESLint style single line ignore switches by using tslint:disable-line and tslint:disable-next-line.

This PR resolves #144

@@ -36,25 +37,33 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {
return;
}

// keep track of the beginning of the line so that we can use it for same line switches
if (scanner.getToken() === ts.SyntaxKind.NewLineTrivia) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As opposed to tracking this, you could use:

node.getLineAndCharacterOfPosition in conjunction with scanner.getTokenPos

@patsissons
Copy link
Contributor Author

I'll see what I can come up with tonight

@jkillian
Copy link
Contributor

Looking good to me @patsissons! Let's see if we can simplify things a little using the SourceFile APIs, but if it seems like a bad idea after trying it to you, we can stick with something more like it is now

@patsissons
Copy link
Contributor Author

I'm all for optimized clean code 👍 what you're suggesting sounds pretty reasonable.

@patsissons patsissons force-pushed the master branch 2 times, most recently from 954501f to f0b1abd Compare April 29, 2016 06:40
// end at the beginning of the next line
this.enableDisableRuleMap[ruleToAdd].push({
isEnabled: !isEnabled,
position: scanner.getTextPos() + 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be:
position: this.getStartOfLinePosition(node, startingPosition, 1), ?

Possible that the current version is fine, I just don't understand what it's doing exactly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The third param is line offset, which defaults to 0, the current line. For current line switches we want to start at the beginning of the current line, so line offset isn't necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the lack of clarity, I was referring to if position: scanner.getTextPos() + 1, should be changed

Copy link
Contributor Author

@patsissons patsissons Apr 29, 2016

Choose a reason for hiding this comment

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

Oh sorry, i see what you were trying to say now. Either version should yield the same position. scanner.getTextPos() returns the position of the end of the text currently parsed token, the +1 is just to bump the position to the beginning of the next line. I guess that the current expression may be a little terse, I could add an extra comment for clarity if you like?

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries, the comment above is clear enough! Just wanted to check that this was as intended. PR merged!

@jkillian
Copy link
Contributor

👍 Like this new version, much easier to read and understand! Just had one comment above, looks good to me otherwise

@patsissons
Copy link
Contributor Author

Thoughts on tests to cover the start and stop interval creation? Or is that better captured in a new PR?

@jkillian
Copy link
Contributor

jkillian commented Apr 29, 2016

As far as tests, I think we should be able to move this over to the newer, more visual testing system. (I.e. the files in test/rules.) Test case(s) could go in test/rules/_integration/comments. That can be a follow-up though

@jkillian jkillian merged commit a20178a into palantir:master Apr 29, 2016
@jkillian
Copy link
Contributor

@patsissons Do you want to do the test PR? Or should I try to knock it out? Just want to make sure we don't duplicate work

@patsissons
Copy link
Contributor Author

I probably wouldn't get to it for a few days, so go ahead. Plus you'll definitely have a better understanding on how to improve things than I will.

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

Successfully merging this pull request may close these issues.

Ignore a line with a single comment
2 participants