From 3c4735795a2963c5ddff6dceaf60122d01ca3dc0 Mon Sep 17 00:00:00 2001 From: Hubert Kowalski Date: Wed, 3 May 2017 03:29:14 -0700 Subject: [PATCH] Detect trailing spaces and tabs Summary: Ref T12655 - this change properly detects trailing spaces or tabs (or combinations of thereof) on end of lines. Test Plan: Use Text lint with trailing whitespace rule on files with spaces, tabs or combinations of thereof. Should properly detect and fix all those. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, Itms Maniphest Tasks: T12655 Differential Revision: https://secure.phabricator.com/D17814 --- src/lint/linter/ArcanistTextLinter.php | 2 +- ....lint-test => trailing-whitespace-1.lint-test} | 0 .../text/trailing-whitespace-2.lint-test | 15 +++++++++++++++ .../text/trailing-whitespace-3.lint-test | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) rename src/lint/linter/__tests__/text/{trailing-whitespace.lint-test => trailing-whitespace-1.lint-test} (100%) create mode 100644 src/lint/linter/__tests__/text/trailing-whitespace-2.lint-test create mode 100644 src/lint/linter/__tests__/text/trailing-whitespace-3.lint-test diff --git a/src/lint/linter/ArcanistTextLinter.php b/src/lint/linter/ArcanistTextLinter.php index 2f81b039..87a2d8a7 100644 --- a/src/lint/linter/ArcanistTextLinter.php +++ b/src/lint/linter/ArcanistTextLinter.php @@ -245,7 +245,7 @@ final class ArcanistTextLinter extends ArcanistLinter { $matches = null; $preg = preg_match_all( - '/ +$/m', + '/[[:blank:]]+$/m', $data, $matches, PREG_OFFSET_CAPTURE); diff --git a/src/lint/linter/__tests__/text/trailing-whitespace.lint-test b/src/lint/linter/__tests__/text/trailing-whitespace-1.lint-test similarity index 100% rename from src/lint/linter/__tests__/text/trailing-whitespace.lint-test rename to src/lint/linter/__tests__/text/trailing-whitespace-1.lint-test diff --git a/src/lint/linter/__tests__/text/trailing-whitespace-2.lint-test b/src/lint/linter/__tests__/text/trailing-whitespace-2.lint-test new file mode 100644 index 00000000..0863c187 --- /dev/null +++ b/src/lint/linter/__tests__/text/trailing-whitespace-2.lint-test @@ -0,0 +1,15 @@ +Lorem ipsum dolor sit amet, +consectetur adipiscing elit. +Phasellus sodales nibh erat, +in hendrerit nulla dictum interdum. +~~~~~~~~~~ +error:1:28 +autofix:1:28 +autofix:2:29 +autofix:3:29 +autofix:4:36 +~~~~~~~~~~ +Lorem ipsum dolor sit amet, +consectetur adipiscing elit. +Phasellus sodales nibh erat, +in hendrerit nulla dictum interdum. diff --git a/src/lint/linter/__tests__/text/trailing-whitespace-3.lint-test b/src/lint/linter/__tests__/text/trailing-whitespace-3.lint-test new file mode 100644 index 00000000..e92f7bbd --- /dev/null +++ b/src/lint/linter/__tests__/text/trailing-whitespace-3.lint-test @@ -0,0 +1,15 @@ +Lorem ipsum dolor sit amet, +consectetur adipiscing elit. +Phasellus sodales nibh erat, +in hendrerit nulla dictum interdum. +~~~~~~~~~~ +error:1:28 +autofix:1:28 +autofix:2:29 +autofix:3:29 +autofix:4:36 +~~~~~~~~~~ +Lorem ipsum dolor sit amet, +consectetur adipiscing elit. +Phasellus sodales nibh erat, +in hendrerit nulla dictum interdum.