Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix closing generic with open brace same line caused by Prettier #14

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions linesBetweenClassMembersRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ var LinesBetweenClassMembersWalker = (function (_super) {
* We do not want to enforce a newline after opening brace for the class declaration
*/
LinesBetweenClassMembersWalker.prototype.isPrevLineOpeningBrace = function (node, sourceFile) {
var prevLine = this.getPrevLinesText(node, sourceFile);
return prevLine.trim() === '{';
var prevLine = this.getPrevLinesText(node, sourceFile).trim();
return prevLine === '{' || prevLine === '> {';
};
/**
* Tests whether method is within a class (as opposed to within an object literal)
Expand Down
10 changes: 10 additions & 0 deletions src/linesBetweenClassMembersRule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ test('passes if first method in class and opening brace before it', (t: AssertCo
t.is(results.errorCount, 0);
});

test('passes if first method in class and opening brace before it and generic closing greater-than same line', (t: AssertContext) => {
const results = TestHelpers.lint('passes/closingGenericSameLineAsOpenBrace.ts');
t.is(results.errorCount, 0);
});

test('passes if implements keyword is on a line after class definition', (t: AssertContext) => {
const results = TestHelpers.lint('passes/implementsKeywordOnLineBelowClassDefinition.ts');
t.is(results.errorCount, 0);
});

test('passes if new line and method comment between class methods', (t: AssertContext) => {
const results = TestHelpers.lint('passes/newLineAndMethodComment.ts');
t.is(results.errorCount, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/linesBetweenClassMembersRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ class LinesBetweenClassMembersWalker extends Lint.RuleWalker {
*/
private isPreviousLineClassDec(node: ts.FunctionLikeDeclaration, sourceFile: ts.SourceFile): boolean {
const prevLine = this.getPrevLinesText(node, sourceFile);
return /\bclass\b\s+[A-Za-z0-9]+/.test(prevLine);
return /\bclass\b\s+[A-Za-z0-9]+/.test(prevLine) || prevLine.trim().startsWith('implements');
}

/**
* Tests whether the previous line is the opening brace
* We do not want to enforce a newline after opening brace for the class declaration
*/
private isPrevLineOpeningBrace(node: ts.FunctionLikeDeclaration, sourceFile: ts.SourceFile): boolean {
const prevLine = this.getPrevLinesText(node, sourceFile);
return prevLine.trim() === '{';
const prevLine = this.getPrevLinesText(node, sourceFile).trim();
return prevLine === '{' || prevLine === '> {';
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/passes/closingGenericSameLineAsOpenBrace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class ClosingGenericSameLineAsOpenBrace<
TSomeType,
TSomeOtherType,
TThirdType
> {
constructor() {

}

someType: TSomeType;
someOtherType: TSomeOtherType;
thirdType: TThirdType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface SomeInterface {
name: string;
}

export class SomeClass
implements SomeInterface {
constructor() { }

name = 'test';
}