'ArcanistMercurialAPI' => 'repository/api/ArcanistMercurialAPI.php',
'ArcanistMercurialParser' => 'repository/parser/ArcanistMercurialParser.php',
'ArcanistMercurialParserTestCase' => 'repository/parser/__tests__/ArcanistMercurialParserTestCase.php',
+ 'ArcanistMergeConflictLinter' => 'lint/linter/ArcanistMergeConflictLinter.php',
'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php',
'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php',
'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php',
'ArcanistMarkCommittedWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistMercurialAPI' => 'ArcanistRepositoryAPI',
'ArcanistMercurialParserTestCase' => 'ArcanistTestCase',
+ 'ArcanistMergeConflictLinter' => 'ArcanistLinter',
'ArcanistNoEffectException' => 'ArcanistUsageException',
'ArcanistNoEngineException' => 'ArcanistUsageException',
'ArcanistNoLintLinter' => 'ArcanistLinter',
->setXHPASTLinter($xhpast_linter)
->setPaths($php_paths);
+ $merge_conflict_linter = id(new ArcanistMergeConflictLinter());
+
+ foreach ($paths as $path) {
+ $merge_conflict_linter->addPath($path);
+ $merge_conflict_linter->addData($path, $this->loadData($path));
+ }
+
+ $linters[] = $merge_conflict_linter;
+
return $linters;
}
return self::GRANULARITY_FILE;
}
+ public function isBinaryFile($path) {
+ // Note that we need the lint engine set before this can be used.
+ return ArcanistDiffUtils::isHeuristicBinaryFile($this->getData($path));
+ }
+
}
--- /dev/null
+<?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) {
+ if ($this->isBinaryFile($path)) {
+ return;
+ }
+
+ $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"
+ );
+ }
+}