From d857208395a06c3bf23ffb0161d20116870ce2a0 Mon Sep 17 00:00:00 2001 From: Matt Banz Date: Thu, 9 Mar 2017 14:20:03 -0700 Subject: [PATCH] file-header fix for single-line comments (#2320) --- src/rules/fileHeaderRule.ts | 2 +- .../rules/file-header/bad-single-line/test.js.lint | 14 ++++++++++++++ .../rules/file-header/bad-single-line/test.ts.lint | 14 ++++++++++++++ test/rules/file-header/bad-single-line/tslint.json | 8 ++++++++ test/rules/file-header/bad/test.js.lint | 4 ++-- test/rules/file-header/empty-file/test.js.lint | 3 ++- test/rules/file-header/empty-file/test.ts.lint | 3 ++- .../file-header/good-single-line/test.js.lint | 9 +++++++++ .../file-header/good-single-line/test.ts.lint | 9 +++++++++ .../rules/file-header/good-single-line/tslint.json | 8 ++++++++ 10 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 test/rules/file-header/bad-single-line/test.js.lint create mode 100644 test/rules/file-header/bad-single-line/test.ts.lint create mode 100644 test/rules/file-header/bad-single-line/tslint.json create mode 100644 test/rules/file-header/good-single-line/test.js.lint create mode 100644 test/rules/file-header/good-single-line/test.ts.lint create mode 100644 test/rules/file-header/good-single-line/tslint.json diff --git a/src/rules/fileHeaderRule.ts b/src/rules/fileHeaderRule.ts index 01e016e0651..a1d3ac89fef 100644 --- a/src/rules/fileHeaderRule.ts +++ b/src/rules/fileHeaderRule.ts @@ -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) { diff --git a/test/rules/file-header/bad-single-line/test.js.lint b/test/rules/file-header/bad-single-line/test.js.lint new file mode 100644 index 00000000000..331b1634b8e --- /dev/null +++ b/test/rules/file-header/bad-single-line/test.js.lint @@ -0,0 +1,14 @@ +// Bad header 1 +~nil [missing file header] + +export class A { + x = 1; + + B() { + return 2; + } +} + +/* + * Good header 2 + */ diff --git a/test/rules/file-header/bad-single-line/test.ts.lint b/test/rules/file-header/bad-single-line/test.ts.lint new file mode 100644 index 00000000000..9c69e523faf --- /dev/null +++ b/test/rules/file-header/bad-single-line/test.ts.lint @@ -0,0 +1,14 @@ +// Bad header 1 +~nil [missing file header] + +export class A { + public x = 1; + + public B() { + return 2; + } +} + +/* + * Good header 2 + */ diff --git a/test/rules/file-header/bad-single-line/tslint.json b/test/rules/file-header/bad-single-line/tslint.json new file mode 100644 index 00000000000..d995363715f --- /dev/null +++ b/test/rules/file-header/bad-single-line/tslint.json @@ -0,0 +1,8 @@ +{ + "rules": { + "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] + } +} diff --git a/test/rules/file-header/bad/test.js.lint b/test/rules/file-header/bad/test.js.lint index f26963fcabf..0d5de16dfe7 100644 --- a/test/rules/file-header/bad/test.js.lint +++ b/test/rules/file-header/bad/test.js.lint @@ -4,9 +4,9 @@ */ export class A { - public x = 1; + x = 1; - public B() { + B() { return 2; } } diff --git a/test/rules/file-header/empty-file/test.js.lint b/test/rules/file-header/empty-file/test.js.lint index 2fcdac38485..40e2acd429d 100644 --- a/test/rules/file-header/empty-file/test.js.lint +++ b/test/rules/file-header/empty-file/test.js.lint @@ -1 +1,2 @@ -// empty. + +~nil [missing file header] diff --git a/test/rules/file-header/empty-file/test.ts.lint b/test/rules/file-header/empty-file/test.ts.lint index 2fcdac38485..40e2acd429d 100644 --- a/test/rules/file-header/empty-file/test.ts.lint +++ b/test/rules/file-header/empty-file/test.ts.lint @@ -1 +1,2 @@ -// empty. + +~nil [missing file header] diff --git a/test/rules/file-header/good-single-line/test.js.lint b/test/rules/file-header/good-single-line/test.js.lint new file mode 100644 index 00000000000..1cfeaf12e78 --- /dev/null +++ b/test/rules/file-header/good-single-line/test.js.lint @@ -0,0 +1,9 @@ +// Good header 4 + +export class A { + x = 1; + + B() { + return 2; + } +} diff --git a/test/rules/file-header/good-single-line/test.ts.lint b/test/rules/file-header/good-single-line/test.ts.lint new file mode 100644 index 00000000000..7c9cd1e230b --- /dev/null +++ b/test/rules/file-header/good-single-line/test.ts.lint @@ -0,0 +1,9 @@ +// Good header 4 + +export class A { + public x = 1; + + public B() { + return 2; + } +} diff --git a/test/rules/file-header/good-single-line/tslint.json b/test/rules/file-header/good-single-line/tslint.json new file mode 100644 index 00000000000..d995363715f --- /dev/null +++ b/test/rules/file-header/good-single-line/tslint.json @@ -0,0 +1,8 @@ +{ + "rules": { + "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] + } +}