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

Commit

Permalink
handle current line and next line switch comments
Browse files Browse the repository at this point in the history
  • Loading branch information
patsissons committed Apr 29, 2016
1 parent af710b3 commit 23df6ce
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/enableDisableRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,46 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {
if (!(ruleToAdd in this.enableDisableRuleMap)) {
this.enableDisableRuleMap[ruleToAdd] = [];
}
this.enableDisableRuleMap[ruleToAdd].push({
isEnabled: isEnabled,
position: startingPosition,
});
if (isCurrentLine) {
// start at the line beginning
this.enableDisableRuleMap[ruleToAdd].push({
isEnabled: isEnabled,
position: lineStartingPosition,
});
// end at the end of the comment
this.enableDisableRuleMap[ruleToAdd].push({
isEnabled: !isEnabled,
position: scanner.getTextPos() + 1,
});
} else {
this.enableDisableRuleMap[ruleToAdd].push({
isEnabled: isEnabled,
position: startingPosition,
});

if (isNextLine) {
const nextLineEndPos = scanner.lookAhead(() => {
// look ahead for the end of the following line
// we need to skip the next new line and the following one
let newLineCount = 2;

while (scanner.scan() !== ts.SyntaxKind.EndOfFileToken) {
if (scanner.getToken() === ts.SyntaxKind.NewLineTrivia) {
if (--newLineCount === 0) {
break;
}
}
}

return scanner.getStartPos() + 1;
});

this.enableDisableRuleMap[ruleToAdd].push({
isEnabled: !isEnabled,
position: nextLineEndPos,
});
}
}
}
}
}
Expand Down

0 comments on commit 23df6ce

Please sign in to comment.