From 43f8e7eb7119f62ccf2dcf7de45ca069b8168422 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 24 Aug 2015 21:11:54 -0700 Subject: [PATCH] Recover from PyLint raising messages at character "-1" Summary: Fixes T9257. For some messages, PyLint can raise at "character -1", which we don't allow since we don't consider it to make sense. Test Plan: - Added failing unit test from T9257. - Applied patch. - Test now passes. Reviewers: joshuaspence, chad Reviewed By: joshuaspence, chad Maniphest Tasks: T9257 Differential Revision: https://secure.phabricator.com/D13991 --- src/lint/linter/ArcanistPyLintLinter.php | 7 ++++++- src/lint/linter/__tests__/pylint/negativechar.lint-test | 6 ++++++ src/lint/linter/__tests__/xml/languages-7.lint-test | 7 ------- 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 src/lint/linter/__tests__/pylint/negativechar.lint-test delete mode 100644 src/lint/linter/__tests__/xml/languages-7.lint-test diff --git a/src/lint/linter/ArcanistPyLintLinter.php b/src/lint/linter/ArcanistPyLintLinter.php index 4884ab9f..44793a50 100644 --- a/src/lint/linter/ArcanistPyLintLinter.php +++ b/src/lint/linter/ArcanistPyLintLinter.php @@ -130,10 +130,15 @@ final class ArcanistPyLintLinter extends ArcanistExternalLinter { continue; } + // NOTE: PyLint sometimes returns -1 as the character offset for a + // message. If it does, treat it as 0. See T9257. + $char = (int)$matches[1]; + $char = max(0, $char); + $message = id(new ArcanistLintMessage()) ->setPath($path) ->setLine($matches[0]) - ->setChar($matches[1]) + ->setChar($char) ->setCode($matches[2]) ->setSeverity($this->getLintMessageSeverity($matches[2])) ->setName(ucwords(str_replace('-', ' ', $matches[3]))) diff --git a/src/lint/linter/__tests__/pylint/negativechar.lint-test b/src/lint/linter/__tests__/pylint/negativechar.lint-test new file mode 100644 index 00000000..18b69adb --- /dev/null +++ b/src/lint/linter/__tests__/pylint/negativechar.lint-test @@ -0,0 +1,6 @@ +"""Docstring""" + +""" +Useless string """ +~~~~~~~~~~ +warning:4:0 See T9257. diff --git a/src/lint/linter/__tests__/xml/languages-7.lint-test b/src/lint/linter/__tests__/xml/languages-7.lint-test deleted file mode 100644 index 54b4c98b..00000000 --- a/src/lint/linter/__tests__/xml/languages-7.lint-test +++ /dev/null @@ -1,7 +0,0 @@ - - - - -~~~~~~~~~~ -error:4:7 -error:5:1