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

fix for #4518: (no-trailing-whitespace) flags leading empty line as error #4543

Merged
merged 4 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion src/rules/noTrailingWhitespaceRule.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-trailing-whitespace": true
}
}