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 1 commit
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
11 changes: 10 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,14 @@ 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) &&
// See https://github.com/palantir/tslint/issues/4518
// and https://github.com/ajafff/tsutils/issues/94
// TODO: Remove this check once tsutils handles Byte Order Markers correctly.
rrogowski marked this conversation as resolved.
Show resolved Hide resolved
match[0].charCodeAt(0) !== ZERO_WIDTH_NO_BREAK_SPACE
rrogowski marked this conversation as resolved.
Show resolved Hide resolved
) {
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 @@
{
"rules": {
"no-trailing-whitespace": true
}
}