1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-25 05:58:20 +01:00
phorge-arcanist/src/lint/linter/ArcanistMergeConflictLinter.php
epriestley 2c5c9815c0 Support PHPCS as a .arclint linter
Summary:
Ref T3186. Ref T2039. Ref T3771. A few effects here:

  # Expose PHPCS as a `.arclint` linter.
  # Turn PHPCS into an ArcanistExternalLinter linter.
  # Add test coverage for PHPCS.
  # Add a `severity.rules` option to `.arclint`. Some linters have very explicit builtin severities ("error", "warning") but their meanings are different from how arc interprets these terms. For example, PHPCS raises "wrong indentation level" as an "error". You can already use the "severity" map to adjust individual rules, but if you want to adjust an entire linter it's currently difficult. This rule map makes it easy. There's substantial precedent for this in other linters, notably all the Python linters.

For `severity.rules`, for example, this will turn all PHPCS "errors" into warnings, and all of its warnings into advice:

      "severity.rules" : {
        "(^PHPCS\\.E\\.)" : "warning",
        "(^PHPCS\\.W\\.)" : "advice"
      }

The user can use `severity` (or more rules) to get additional granularity adjustments if they desire.

Test Plan: 5bb919bc3a

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, ajtrichards

Maniphest Tasks: T2039, T3186, T3771

Differential Revision: https://secure.phabricator.com/D6830
2013-08-29 06:47:27 -07:00

46 lines
1.1 KiB
PHP

<?php
/**
* Checks files for unresolved merge conflicts.
*
* @group linter
*/
final class ArcanistMergeConflictLinter extends ArcanistLinter {
const LINT_MERGECONFLICT = 1;
public function willLintPaths(array $paths) {
return;
}
public function lintPath($path) {
$lines = phutil_split_lines($this->getData($path), false);
foreach ($lines as $lineno => $line) {
// An unresolved merge conflict will contain a series of seven
// '<', '=', or '>'.
if (preg_match('/^(>{7}|<{7}|={7})$/', $line)) {
$this->raiseLintAtLine(
$lineno + 1,
0,
self::LINT_MERGECONFLICT,
"This syntax indicates there is an unresolved merge conflict.");
}
}
}
public function getLinterName() {
return "MERGECONFLICT";
}
public function getLintSeverityMap() {
return array(
self::LINT_MERGECONFLICT => ArcanistLintSeverity::SEVERITY_ERROR
);
}
public function getLintNameMap() {
return array(
self::LINT_MERGECONFLICT => "Unresolved merge conflict"
);
}
}