mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-23 15:36:52 +00:00
Drop disabled lints
Covered by RecordLintJobTest::testDropInlineMediaCaptionLints Change-Id: I564389ec9bd20cf36ec7a9bf96b1aebf7777cbbc
This commit is contained in:
parent
648b48f283
commit
ed8e449e13
|
@ -86,7 +86,8 @@
|
||||||
"class": "MediaWiki\\Linter\\RecordLintJob",
|
"class": "MediaWiki\\Linter\\RecordLintJob",
|
||||||
"services": [
|
"services": [
|
||||||
"Linter.TotalsLookup",
|
"Linter.TotalsLookup",
|
||||||
"Linter.Database"
|
"Linter.Database",
|
||||||
|
"Linter.CategoryManager"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -62,12 +62,19 @@ class CategoryManager {
|
||||||
*/
|
*/
|
||||||
private $hasNoParams = [];
|
private $hasNoParams = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool[]
|
||||||
|
* @phan-var array<string,bool>
|
||||||
|
*/
|
||||||
|
private $isEnabled = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do not instantiate directly: use MediaWikiServices to fetch.
|
* Do not instantiate directly: use MediaWikiServices to fetch.
|
||||||
* @param array $linterCategories
|
* @param array $linterCategories
|
||||||
*/
|
*/
|
||||||
public function __construct( array $linterCategories ) {
|
public function __construct( array $linterCategories ) {
|
||||||
foreach ( $linterCategories as $name => $info ) {
|
foreach ( $linterCategories as $name => $info ) {
|
||||||
|
$this->isEnabled[$name] = $info['enabled'];
|
||||||
if ( $info['enabled'] ) {
|
if ( $info['enabled'] ) {
|
||||||
$this->categories[$info['priority']][] = $name;
|
$this->categories[$info['priority']][] = $name;
|
||||||
}
|
}
|
||||||
|
@ -107,6 +114,11 @@ class CategoryManager {
|
||||||
return isset( $this->hasNoParams[$name] );
|
return isset( $this->hasNoParams[$name] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isEnabled( string $name ): bool {
|
||||||
|
// Default to true so !isKnownCategory aren't dropped
|
||||||
|
return $this->isEnabled[$name] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -268,6 +268,11 @@ class Hooks implements
|
||||||
$catCounts = [];
|
$catCounts = [];
|
||||||
foreach ( $data as $info ) {
|
foreach ( $data as $info ) {
|
||||||
if ( $this->categoryManager->isKnownCategory( $info['type'] ) ) {
|
if ( $this->categoryManager->isKnownCategory( $info['type'] ) ) {
|
||||||
|
// NOTE: Redundant with RecordLintJob, but why even create the job
|
||||||
|
if ( !$this->categoryManager->isEnabled( $info['type'] ) ) {
|
||||||
|
// Drop lints of these types for now
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$info[ 'dbid' ] = null;
|
$info[ 'dbid' ] = null;
|
||||||
} elseif ( !isset( $info[ 'dbid' ] ) ) {
|
} elseif ( !isset( $info[ 'dbid' ] ) ) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -308,10 +313,13 @@ class Hooks implements
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$job = new RecordLintJob( $title, [
|
$job = new RecordLintJob(
|
||||||
'errors' => $errors,
|
$title,
|
||||||
'revision' => $revision,
|
[ 'errors' => $errors, 'revision' => $revision ],
|
||||||
], $this->totalsLookup, $this->database );
|
$this->totalsLookup,
|
||||||
|
$this->database,
|
||||||
|
$this->categoryManager
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->jobQueueGroup->push( $job );
|
$this->jobQueueGroup->push( $job );
|
||||||
|
|
|
@ -27,6 +27,7 @@ use MediaWiki\Page\PageReference;
|
||||||
class RecordLintJob extends Job {
|
class RecordLintJob extends Job {
|
||||||
private TotalsLookup $totalsLookup;
|
private TotalsLookup $totalsLookup;
|
||||||
private Database $database;
|
private Database $database;
|
||||||
|
private CategoryManager $categoryManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RecordLintJob constructor.
|
* RecordLintJob constructor.
|
||||||
|
@ -34,16 +35,19 @@ class RecordLintJob extends Job {
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param TotalsLookup $totalsLookup
|
* @param TotalsLookup $totalsLookup
|
||||||
* @param Database $database
|
* @param Database $database
|
||||||
|
* @param CategoryManager $categoryManager
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PageReference $page,
|
PageReference $page,
|
||||||
array $params,
|
array $params,
|
||||||
TotalsLookup $totalsLookup,
|
TotalsLookup $totalsLookup,
|
||||||
Database $database
|
Database $database,
|
||||||
|
CategoryManager $categoryManager
|
||||||
) {
|
) {
|
||||||
parent::__construct( 'RecordLintJob', $page, $params );
|
parent::__construct( 'RecordLintJob', $page, $params );
|
||||||
$this->totalsLookup = $totalsLookup;
|
$this->totalsLookup = $totalsLookup;
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
|
$this->categoryManager = $categoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run() {
|
public function run() {
|
||||||
|
@ -55,7 +59,7 @@ class RecordLintJob extends Job {
|
||||||
// [ 'id' => LintError ]
|
// [ 'id' => LintError ]
|
||||||
$errors = [];
|
$errors = [];
|
||||||
foreach ( $this->params['errors'] as $errorInfo ) {
|
foreach ( $this->params['errors'] as $errorInfo ) {
|
||||||
if ( in_array( $errorInfo['type'], [ 'inline-media-caption', 'missing-image-alt-text' ] ) ) {
|
if ( !$this->categoryManager->isEnabled( $errorInfo['type'] ) ) {
|
||||||
// Drop lints of these types for now
|
// Drop lints of these types for now
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
|
||||||
$page,
|
$page,
|
||||||
$params,
|
$params,
|
||||||
$services->get( 'Linter.TotalsLookup' ),
|
$services->get( 'Linter.TotalsLookup' ),
|
||||||
$this->getDatabase()
|
$this->getDatabase(),
|
||||||
|
$services->get( 'Linter.CategoryManager' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,8 @@ class SpecialLintErrorsTest extends SpecialPageTestBase {
|
||||||
$page,
|
$page,
|
||||||
$params,
|
$params,
|
||||||
$services->get( 'Linter.TotalsLookup' ),
|
$services->get( 'Linter.TotalsLookup' ),
|
||||||
$this->getDatabase()
|
$this->getDatabase(),
|
||||||
|
$services->get( 'Linter.CategoryManager' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue