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

add skip-blank-lines option to no-trailing-whitespace #3346

Merged
merged 3 commits into from Oct 20, 2017
Merged

add skip-blank-lines option to no-trailing-whitespace #3346

merged 3 commits into from Oct 20, 2017

Conversation

cyrilgandon
Copy link
Contributor

@cyrilgandon cyrilgandon commented Oct 19, 2017

PR checklist

Overview of change:

Is there anything you'd like reviewers to focus on?

Should the option be called skip-blank-lines like eslint, or ignore-blank-lines, like every other option of the rule?

CHANGELOG.md entry:

[new-rule-option] no-trailing-whitespace : ignore-blank-lines

@@ -24,11 +24,13 @@ import { getTemplateRanges } from "./noConsecutiveBlankLinesRule";
const OPTION_IGNORE_COMMENTS = "ignore-comments";
const OPTION_IGNORE_JSDOC = "ignore-jsdoc";
const OPTION_IGNORE_TEMPLATE_STRINGS = "ignore-template-strings";
const OPTION_SKIP_BLANK_LINES = "skip-blank-lines";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to "ignore-blank-lines" for consistency

@@ -78,12 +82,15 @@ function walk(ctx: Lint.WalkContext<Options>) {
const sourceFile = ctx.sourceFile;
const text = sourceFile.text;
for (const line of getLineRanges(sourceFile)) {
const match = text.substr(line.pos, line.contentLength).match(/\s+$/);
if (match !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a separate function or regex.
match[0] contains the full match. If the length of the match is equal to the line length, the line consists only of whitespace.

if (match !== null && (!ctx.options.skipBlankLines || match[0].length !== line.contentLength))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even simpler: check if match.index === 0

@ajafff
Copy link
Contributor

ajafff commented Oct 20, 2017

CI failure is unrelated because of upstream changes in typescript@next
Will try to fix this in a separate PR. Until then I cannot merge this PR.

@ajafff ajafff mentioned this pull request Oct 20, 2017
4 tasks
@ajafff
Copy link
Contributor

ajafff commented Oct 20, 2017

By the way: you don't need to include the link to the rule's documentation in the changelog entry. This is done by the script that generates the changelog.

@ajafff ajafff merged commit c1b842a into palantir:master Oct 20, 2017
@ajafff
Copy link
Contributor

ajafff commented Oct 20, 2017

Thanks @cyrilgandon

@gonzofish
Copy link

Awesome!

@cyrilgandon cyrilgandon deleted the noTrailingWhitespace-skipBlankLines branch October 22, 2017 14:38
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this pull request Apr 9, 2018
@cmartin88
Copy link

Has this been implemented? Not seeing it in webstorm.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants