1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-10-24 17:48:50 +02:00
phorge-arcanist/src/lint/linter/ArcanistConduitLinter.php
vrana 66d204be81 Delete license headers from files
Summary:
This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory).

We are removing the headers for these reasons:

- It wastes space in editors, less code is visible in editor upon opening a file.
- It brings noise to diff of the first change of any file every year.
- It confuses Git file copy detection when creating small files.
- We don't have an explicit license header in other files (JS, CSS, images, documentation).
- Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new.

This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook).

Test Plan: Verified that the license survived only in unit tests and LICENSE file.

Reviewers: epriestley, btrahan, edward

Reviewed By: epriestley

CC: aran, Korvin, davidrecordon

Maniphest Tasks: T2035

Differential Revision: https://secure.phabricator.com/D3881
2012-11-05 11:16:24 -08:00

94 lines
2.7 KiB
PHP

<?php
/**
* Implements linting via Conduit RPC call.
* Slow by definition, but allows sophisticated linting that relies on
* stuff like big indexes of a codebase.
* Recommended usage is to gate these to the advice lint level.
*
* The conduit endpoint should implement a method named the same as
* the value of ArcanistConduitLinter::CONDUIT_METHOD.
*
* It takes an array with a key 'file_contents' which is an array mapping
* file paths to their complete contents.
*
* It should return an array mapping those same paths to arrays describing the
* lint for each path.
*
* The lint for a path is described as a list of structured dictionaries.
*
* The dictionary structure is effectively defined by
* ArcanistLintMessage::newFromDictionary.
*
* Effective keys are:
* 'path' => must match passed in path.
* 'line'
* 'char'
* 'code'
* 'severity' => Must match a constant in ArcanistLintSeverity.
* 'name'
* 'description'
* 'original' & 'replacement' => optional patch information
*
* This class is intended for customization via instantiation, not via
* subclassing.
*/
final class ArcanistConduitLinter extends ArcanistLinter {
const CONDUIT_METHOD = 'lint.getalllint';
private $conduitURI;
private $linterName;
private $lintByPath; // array(/pa/th/ => <lint>), valid after willLintPaths().
public function __construct($conduit_uri, $linter_name) {
$this->conduitURI = $conduit_uri;
$this->linterName = $linter_name;
}
public function willLintPaths(array $paths) {
// Load all file path data into $this->data.
array_map(array($this, 'getData'), $paths);
$conduit = new ConduitClient($this->conduitURI);
$this->lintByPath = $conduit->callMethodSynchronous(
self::CONDUIT_METHOD,
array(
'file_contents' => $this->data,
)
);
}
public function lintPath($path) {
$lint_for_path = idx($this->lintByPath, $path);
if (!$lint_for_path) {
return;
}
foreach ($lint_for_path as $lint) {
$this->addLintMessage(ArcanistLintMessage::newFromDictionary($lint));
}
}
public function getLinterName() {
return $this->linterName;
}
public function getLintSeverityMap() {
// The rationale here is that this class will only be used for custom
// linting in installations. No two server endpoints will be the same across
// different instantiations. Therefore, the server can handle all severity
// customization directly.
throw new ArcanistUsageException(
'ArcanistConduitLinter does not support client-side severity '.
'customization.'
);
}
public function getLintNameMap() {
// See getLintSeverityMap for rationale.
throw new ArcanistUsageException(
'ArcanistConduitLinter does not support a name map.'
);
}
}