-
Notifications
You must be signed in to change notification settings - Fork 889
add skip-blank-lines option to no-trailing-whitespace #3346
add skip-blank-lines option to no-trailing-whitespace #3346
Conversation
@@ -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"; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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
CI failure is unrelated because of upstream changes in typescript@next |
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. |
Thanks @cyrilgandon |
Awesome! |
Has this been implemented? Not seeing it in webstorm. |
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, orignore-blank-lines
, like every other option of the rule?CHANGELOG.md entry:
[new-rule-option]
no-trailing-whitespace
:ignore-blank-lines