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

file-header fix for single-line comments #2320

Merged
merged 1 commit into from
Mar 9, 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
2 changes: 1 addition & 1 deletion src/rules/fileHeaderRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Rule extends Lint.Rules.AbstractRule {
class FileHeaderWalker extends Lint.RuleWalker {
// match a single line or multi line comment with leading whitespace
// the wildcard dot does not match new lines - we can use [\s\S] instead
private commentRegexp: RegExp = /^\s*(\/\/(.*?)|\/\*([\s\S]*?)\*\/)/;
private commentRegexp: RegExp = /^\s*(\/\/(.*)|\/\*([\s\S]*?)\*\/)/;
private headerRegexp: RegExp;

public setRegexp(headerRegexp: RegExp) {
Expand Down
14 changes: 14 additions & 0 deletions test/rules/file-header/bad-single-line/test.js.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Bad header 1
~nil [missing file header]

export class A {
x = 1;

B() {
return 2;
}
}

/*
* Good header 2
*/
14 changes: 14 additions & 0 deletions test/rules/file-header/bad-single-line/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Bad header 1
~nil [missing file header]

export class A {
public x = 1;

public B() {
return 2;
}
}

/*
* Good header 2
*/
8 changes: 8 additions & 0 deletions test/rules/file-header/bad-single-line/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"file-header": [true, "Good header \\d"]
},
"jsRules": {
"file-header": [true, "Good header \\d"]
}
}
4 changes: 2 additions & 2 deletions test/rules/file-header/bad/test.js.lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

export class A {
public x = 1;
x = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is supposed to be a .js file test, I removed the visibility modifiers.


public B() {
B() {
return 2;
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/rules/file-header/empty-file/test.js.lint
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this file had just a single-line comment. That case is now covered by both the good-single-line and bad-single-line tests. I have modified this file to truly be empty.

~nil [missing file header]
3 changes: 2 additions & 1 deletion test/rules/file-header/empty-file/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// empty.

~nil [missing file header]
9 changes: 9 additions & 0 deletions test/rules/file-header/good-single-line/test.js.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Good header 4

export class A {
x = 1;

B() {
return 2;
}
}
9 changes: 9 additions & 0 deletions test/rules/file-header/good-single-line/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Good header 4

export class A {
public x = 1;

public B() {
return 2;
}
}
8 changes: 8 additions & 0 deletions test/rules/file-header/good-single-line/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"file-header": [true, "Good header \\d"]
},
"jsRules": {
"file-header": [true, "Good header \\d"]
}
}