diff --git a/src/rules/noTrailingWhitespaceRule.ts b/src/rules/noTrailingWhitespaceRule.ts index 06b6a8d3585..411de7696e8 100644 --- a/src/rules/noTrailingWhitespaceRule.ts +++ b/src/rules/noTrailingWhitespaceRule.ts @@ -22,6 +22,8 @@ import * as Lint from "../index"; import { getTemplateRanges } from "./noConsecutiveBlankLinesRule"; +const ZERO_WIDTH_NO_BREAK_SPACE = 0xfeff; + const OPTION_IGNORE_COMMENTS = "ignore-comments"; const OPTION_IGNORE_JSDOC = "ignore-jsdoc"; const OPTION_IGNORE_TEMPLATE_STRINGS = "ignore-template-strings"; @@ -87,7 +89,11 @@ function walk(ctx: Lint.WalkContext) { for (const line of getLineRanges(sourceFile)) { // \s matches any whitespace character (equal to [\r\n\t\f\v ]) const match = text.substr(line.pos, line.contentLength).match(/\s+$/); - if (match !== null && !(ctx.options.ignoreBlankLines && match.index === 0)) { + if ( + match !== null && + !(ctx.options.ignoreBlankLines && match.index === 0) && + match[0] !== String.fromCharCode(ZERO_WIDTH_NO_BREAK_SPACE) + ) { possibleFailures.push({ end: line.pos + line.contentLength, pos: line.pos + match.index!, diff --git a/test/rules/no-trailing-whitespace/zero-width-no-break-space/test.ts.lint b/test/rules/no-trailing-whitespace/zero-width-no-break-space/test.ts.lint new file mode 100644 index 00000000000..c873c6af5a2 --- /dev/null +++ b/test/rules/no-trailing-whitespace/zero-width-no-break-space/test.ts.lint @@ -0,0 +1,4 @@ + +// This file starts with a zero width no-break-space. +// See http://www.fileformat.info/info/unicode/char/feff/index.htm +const a = 3; diff --git a/test/rules/no-trailing-whitespace/zero-width-no-break-space/test2.ts.lint b/test/rules/no-trailing-whitespace/zero-width-no-break-space/test2.ts.lint new file mode 100644 index 00000000000..96c770979e8 --- /dev/null +++ b/test/rules/no-trailing-whitespace/zero-width-no-break-space/test2.ts.lint @@ -0,0 +1,5 @@ + +~~ [trailing whitespace] +// This file starts with a zero width no-break-space followed by a trailing space. +// See http://www.fileformat.info/info/unicode/char/feff/index.htm +const a = 3; diff --git a/test/rules/no-trailing-whitespace/zero-width-no-break-space/tslint.json b/test/rules/no-trailing-whitespace/zero-width-no-break-space/tslint.json new file mode 100644 index 00000000000..f81bfe73957 --- /dev/null +++ b/test/rules/no-trailing-whitespace/zero-width-no-break-space/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-trailing-whitespace": true + } +}