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

Commit

Permalink
file-header fix for single-line comments (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
battmanz authored and adidahiya committed Mar 9, 2017
1 parent fa6f96e commit d857208
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 5 deletions.
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;

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.

~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"]
}
}

0 comments on commit d857208

Please sign in to comment.