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

add fix function to noConsecutiveBlankLines #2201

Merged
merged 3 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rules/noConsecutiveBlankLinesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Rule extends Lint.Rules.AbstractRule {
public static metadata: Lint.IRuleMetadata = {
ruleName: "no-consecutive-blank-lines",
description: "Disallows one or more blank lines in a row.",
hasFix: true,
rationale: "Helps maintain a readable style in your codebase.",
optionsDescription: Lint.Utils.dedent`
An optional number of maximum allowed sequential blanks can be specified. If no value
Expand Down Expand Up @@ -97,10 +98,14 @@ class NoConsecutiveBlankLinesWalker extends Lint.RuleWalker {
}

const startLineNum = arr[0];
const endLineNum = arr[arr.length - allowedBlanks];
const pos = lineStarts[startLineNum + 1];
const end = lineStarts[endLineNum];
const isInTemplate = templateIntervals.some((interval) => pos >= interval.startPosition && pos < interval.endPosition);

if (!isInTemplate) {
this.addFailureAt(pos, 1, failureMessage);
const fix = this.createFix(this.deleteFromTo(pos, end));
this.addFailureAt(pos, 1, failureMessage, fix);
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/rules/no-consecutive-blank-lines/default/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// the markup for this test is a little bit weird
// tslint, for the first error below, says it goes from
// [5, 1] to [6, 1], and thus the markup appears to be off (but it's not)

class Clazz { // comment

public funcxion() {

// also comment

console.log("test");

}

}

//Begin whitespace
// The next two lines of "code" contain only tabs or spaces, they are also considered "blank" lines

let foo = `


`;

let bar = `${bar

}`;
27 changes: 27 additions & 0 deletions test/rules/no-consecutive-blank-lines/multiple/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// the markup for this test is a little bit weird
// tslint, for the first error below, says it goes from
// [5, 1] to [6, 1], and thus the markup appears to be off (but it's not)

class Clazz { // comment


public funcxion() {

// also comment


// still allowed since 2 lines only


// this one won't be allowed anymore

console.log("test");

}


}

//Begin whitespace
// The next lines contain only tabs or spaces, they are also considered "blank" lines