Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe5bca8

Browse filesBrowse files
committed
Next-line rule was too strict
We have a few places where we do this: ```ts if { //... } // Look, a comment else { //... } ``` I don't think we want to forbid these cases, so I'm loosening the requirement from "must be on the line after the prior curly brace" to "can't be on the same line as the curly brace".
1 parent cd390fd commit fe5bca8
Copy full SHA for fe5bca8

1 file changed

+5-5Lines changed: 5 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎scripts/tslint/nextLineRule.ts‎

Copy file name to clipboardExpand all lines: scripts/tslint/nextLineRule.ts
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const OPTION_CATCH = "check-catch";
55
const OPTION_ELSE = "check-else";
66

77
export class Rule extends Lint.Rules.AbstractRule {
8-
public static CATCH_FAILURE_STRING = "'catch' should be on the line following the previous block's ending curly brace";
9-
public static ELSE_FAILURE_STRING = "'else' should be on the line following the previous block's ending curly brace";
8+
public static CATCH_FAILURE_STRING = "'catch' should not be on the same line as the preceeding block's curly brace";
9+
public static ELSE_FAILURE_STRING = "'else' should not be on the same line as the preceeding block's curly brace";
1010

1111
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
1212
return this.applyWithWalker(new NextLineWalker(sourceFile, this.getOptions()));
@@ -25,7 +25,7 @@ class NextLineWalker extends Lint.RuleWalker {
2525
if (this.hasOption(OPTION_ELSE) && !!elseKeyword) {
2626
const thenStatementEndLoc = sourceFile.getLineAndCharacterOfPosition(thenStatement.getEnd());
2727
const elseKeywordLoc = sourceFile.getLineAndCharacterOfPosition(elseKeyword.getStart(sourceFile));
28-
if (thenStatementEndLoc.line !== (elseKeywordLoc.line - 1)) {
28+
if (thenStatementEndLoc.line === elseKeywordLoc.line) {
2929
const failure = this.createFailure(elseKeyword.getStart(sourceFile), elseKeyword.getWidth(sourceFile), Rule.ELSE_FAILURE_STRING);
3030
this.addFailure(failure);
3131
}
@@ -47,7 +47,7 @@ class NextLineWalker extends Lint.RuleWalker {
4747
const catchKeyword = catchClause.getFirstToken(sourceFile);
4848
const tryClosingBraceLoc = sourceFile.getLineAndCharacterOfPosition(tryClosingBrace.getEnd());
4949
const catchKeywordLoc = sourceFile.getLineAndCharacterOfPosition(catchKeyword.getStart(sourceFile));
50-
if (tryClosingBraceLoc.line !== (catchKeywordLoc.line - 1)) {
50+
if (tryClosingBraceLoc.line === catchKeywordLoc.line) {
5151
const failure = this.createFailure(catchKeyword.getStart(sourceFile), catchKeyword.getWidth(sourceFile), Rule.CATCH_FAILURE_STRING);
5252
this.addFailure(failure);
5353
}
@@ -58,4 +58,4 @@ class NextLineWalker extends Lint.RuleWalker {
5858

5959
function getFirstChildOfKind(node: ts.Node, kind: ts.SyntaxKind) {
6060
return node.getChildren().filter((child) => child.kind === kind)[0];
61-
}
61+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.