1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +01:00

Respect @nolint

Summary:
Respect @nolint annotations

Test Plan:
New "test case"

Differential Revision: 41
Reviewed By: epriestley
Reviewers: epriestley
CC: epriestley
This commit is contained in:
adonohue 2011-02-24 17:59:49 -08:00 committed by epriestley
parent 651f567f96
commit cc8c7d4997
8 changed files with 130 additions and 2 deletions

View file

@ -49,6 +49,7 @@ phutil_register_library_map(array(
'ArcanistMarkCommittedWorkflow' => 'workflow/mark-committed', 'ArcanistMarkCommittedWorkflow' => 'workflow/mark-committed',
'ArcanistNoEffectException' => 'exception/usage/noeffect', 'ArcanistNoEffectException' => 'exception/usage/noeffect',
'ArcanistNoEngineException' => 'exception/usage/noengine', 'ArcanistNoEngineException' => 'exception/usage/noengine',
'ArcanistNoLintLinter' => 'lint/linter/nolint',
'ArcanistPEP8Linter' => 'lint/linter/pep8', 'ArcanistPEP8Linter' => 'lint/linter/pep8',
'ArcanistPatchWorkflow' => 'workflow/patch', 'ArcanistPatchWorkflow' => 'workflow/patch',
'ArcanistPhutilModuleLinter' => 'lint/linter/phutilmodule', 'ArcanistPhutilModuleLinter' => 'lint/linter/phutilmodule',
@ -98,6 +99,7 @@ phutil_register_library_map(array(
'ArcanistMarkCommittedWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistMarkCommittedWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistNoEffectException' => 'ArcanistUsageException', 'ArcanistNoEffectException' => 'ArcanistUsageException',
'ArcanistNoEngineException' => 'ArcanistUsageException', 'ArcanistNoEngineException' => 'ArcanistUsageException',
'ArcanistNoLintLinter' => 'ArcanistLinter',
'ArcanistPEP8Linter' => 'ArcanistLinter', 'ArcanistPEP8Linter' => 'ArcanistLinter',
'ArcanistPatchWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistPatchWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistPhutilModuleLinter' => 'ArcanistLinter', 'ArcanistPhutilModuleLinter' => 'ArcanistLinter',

View file

@ -53,6 +53,9 @@ class PhutilLintEngine extends ArcanistLintEngine {
$generated_linter = new ArcanistGeneratedLinter(); $generated_linter = new ArcanistGeneratedLinter();
$linters[] = $generated_linter; $linters[] = $generated_linter;
$nolint_linter = new ArcanistNoLintLinter();
$linters[] = $nolint_linter;
$text_linter = new ArcanistTextLinter(); $text_linter = new ArcanistTextLinter();
$linters[] = $text_linter; $linters[] = $text_linter;
foreach ($paths as $path) { foreach ($paths as $path) {
@ -64,6 +67,9 @@ class PhutilLintEngine extends ArcanistLintEngine {
$generated_linter->addPath($path); $generated_linter->addPath($path);
$generated_linter->addData($path, $this->loadData($path)); $generated_linter->addData($path, $this->loadData($path));
$nolint_linter->addPath($path);
$nolint_linter->addData($path, $this->loadData($path));
$text_linter->addPath($path); $text_linter->addPath($path);
$text_linter->addData($path, $this->loadData($path)); $text_linter->addData($path, $this->loadData($path));
} }

View file

@ -10,6 +10,7 @@ phutil_require_module('arcanist', 'lint/engine/base');
phutil_require_module('arcanist', 'lint/linter/apachelicense'); phutil_require_module('arcanist', 'lint/linter/apachelicense');
phutil_require_module('arcanist', 'lint/linter/filename'); phutil_require_module('arcanist', 'lint/linter/filename');
phutil_require_module('arcanist', 'lint/linter/generated'); phutil_require_module('arcanist', 'lint/linter/generated');
phutil_require_module('arcanist', 'lint/linter/nolint');
phutil_require_module('arcanist', 'lint/linter/phutilmodule'); phutil_require_module('arcanist', 'lint/linter/phutilmodule');
phutil_require_module('arcanist', 'lint/linter/text'); phutil_require_module('arcanist', 'lint/linter/text');
phutil_require_module('arcanist', 'lint/linter/xhpast'); phutil_require_module('arcanist', 'lint/linter/xhpast');

View file

@ -1,5 +1,21 @@
<?php <?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* Stops other linters from running on generated code. * Stops other linters from running on generated code.
* *
@ -27,7 +43,7 @@ class ArcanistGeneratedLinter extends ArcanistLinter {
public function lintPath($path) { public function lintPath($path) {
$data = $this->getData($path); $data = $this->getData($path);
if (preg_match('/@generated/', $data)) { if (preg_match('/@'.'generated/', $data)) {
$this->stopAllLinters(); $this->stopAllLinters();
} }
} }

View file

@ -0,0 +1,50 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Stops other linters from running on code marked with
* a nolint annotation.
*
* @group linter
*/
class ArcanistNoLintLinter extends ArcanistLinter {
public function willLintPaths(array $paths) {
return;
}
public function getLinterName() {
return 'NOLINT';
}
public function getLintSeverityMap() {
return array();
}
public function getLintNameMap() {
return array(
);
}
public function lintPath($path) {
$data = $this->getData($path);
if (preg_match('/@'.'nolint/', $data)) {
$this->stopAllLinters();
}
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('arcanist', 'lint/linter/base');
phutil_require_source('ArcanistNoLintLinter.php');

View file

@ -0,0 +1,29 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Test for @{class:ArcanistNoLintLinter}.
*
* Not a real test... meant to fail lint
* if @nolint is not respected.
*
* @group testcase
*/
class ArcanistNoLintTestCaseMisnamed extends ArcanistLinterTestCase {
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('arcanist', 'lint/linter/base/test');
phutil_require_source('ArcanistNoLintTestCase.php');