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

Commit

Permalink
fix for #4518: (no-trailing-whitespace) flags leading empty line as e…
Browse files Browse the repository at this point in the history
…rror (#4543)

* fix for #4518

* add new test case

* Fixed Prettier formatting on the rule
  • Loading branch information
rrogowski authored and Josh Goldberg committed Mar 7, 2019
1 parent 5ae2048 commit 8dc82fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rules/noTrailingWhitespaceRule.ts
Expand Up @@ -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";
Expand Down Expand Up @@ -87,7 +89,11 @@ function walk(ctx: Lint.WalkContext<Options>) {
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!,
Expand Down
@@ -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;
@@ -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;
@@ -0,0 +1,5 @@
{
"rules": {
"no-trailing-whitespace": true
}
}

0 comments on commit 8dc82fc

Please sign in to comment.