Skip to content

Commit

Permalink
[bug] fixed new issue in ter-newline-after-var rule (buzinas#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
webschik committed Jan 12, 2019
1 parent 17354db commit 17d6839
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/rules/terNewlineAfterVarRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ class RuleWalker extends Lint.AbstractWalker<ITerNewlineAfterVarOptions> {
const nextSibling: ts.Node|void = getNextSiblingNode(node);
const nextSiblingKind: number|void = nextSibling && nextSibling.kind;

// prevent a conflict with "eofline" rule
if (!nextSibling || nextSiblingKind !== ts.SyntaxKind.EndOfFileToken) {
if (
!(isNewLineAlwaysRequired && nextSiblingKind === ts.SyntaxKind.VariableStatement) &&

// prevent a conflict with "eofline" rule
!(nextSibling && nextSiblingKind === ts.SyntaxKind.EndOfFileToken)
) {
const isNewLineRequired: boolean = isNewLineAlwaysRequired && nextSiblingKind !== ts.SyntaxKind.VariableStatement;
const unexpectedLineFixes: Lint.Replacement[] = [];
const expectedLineFixes: Lint.Replacement[] = [];
Expand Down
48 changes: 48 additions & 0 deletions src/test/rules/terNewlineAfterVarRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ function expecting (errors: ['expectedBlankLine' | 'unexpectedBlankLine', number
}

ruleTester.addTestGroup('always', 'should always require an empty line after variable declarations ', [
{
code: dedent`
const foo1 = 1;
const bar1 = 2; // Inline comment
const foo2 = 3; /* Multiline
comment */
const bar2 = 4;
`,
output: dedent`
const foo1 = 1;
const bar1 = 2; // Inline comment
const foo2 = 3; /* Multiline
comment */
const bar2 = 4;
`,
options: []
},
{
code: dedent`
var greet = "hello,",
Expand Down Expand Up @@ -227,6 +250,31 @@ ruleTester.addTestGroup('always', 'should always require an empty line after var
]);

ruleTester.addTestGroup('never', 'should disallow empty lines after variable declarations ', [
{
code: dedent`
const foo1 = 1;
const bar1 = 2; // Inline comment
const foo2 = 3; /* Multiline
comment */
const bar2 = 4;
`,
output: dedent`
const foo1 = 1;
const bar1 = 2; // Inline comment
const foo2 = 3; /* Multiline
comment */
const bar2 = 4;
`,
options: ['never'],
errors: expecting([
['unexpectedBlankLine', 1],
['unexpectedBlankLine', 3],
['unexpectedBlankLine', 5]
])
},
{
code: dedent`
var greet = "hello,",
Expand Down

0 comments on commit 17d6839

Please sign in to comment.