mediawiki / mediawiki-codesniffer
MediaWiki CodeSniffer Standards
Installs: 2 060 059
Dependents: 305
Suggesters: 0
Security: 0
Stars: 33
Watchers: 12
Forks: 11
Type:phpcodesniffer-standard
Requires
- php: >=7.4.0
- ext-json: *
- ext-mbstring: *
- composer/semver: 3.4.2 || 3.4.3
- composer/spdx-licenses: ~1.5.2
- phpcsstandards/phpcsextra: 1.2.1
- squizlabs/php_codesniffer: 3.10.3
- symfony/polyfill-php80: ^1.26.0
Requires (Dev)
- ext-dom: *
- mediawiki/mediawiki-phan-config: 0.14.0
- mediawiki/minus-x: 1.1.3
- php-parallel-lint/php-console-highlighter: 1.0.0
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpunit/phpunit: 9.6.16
- dev-master
- v45.0.0
- v44.0.0
- v43.0.0
- v42.0.0
- v41.0.0
- v40.0.1
- v40.0.0
- v39.0.0
- v38.0.0
- v37.0.0
- v36.0.0
- v35.0.0
- v34.0.0
- v33.0.0
- v32.0.0
- v31.0.0
- v30.0.0
- v29.0.0
- v28.0.0
- v27.0.0
- v26.0.0
- 25.0.0
- v24.0.0
- v23.0.0
- v22.0.0
- v21.0.0
- v20.0.0
- 19.x-dev
- 19.4.0
- 19.3.0
- v19.2.0
- 19.1.0
- v19.0.0
- v18.0.0
- v17.0.0
- v16.0.1
- v16.0.0
- v15.0.0
- v14.1.0
- v14.0.0
- v13.0.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.1
- v0.10.0
- v0.9.0
- 0.8.x-dev
- v0.8.1
- v0.8.0
- v0.8.0-alpha.1
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- 0.1.0
This package is auto-updated.
Last update: 2024-10-30 18:51:47 UTC
README
Abstract
This project implements a set of rules for use with PHP CodeSniffer.
See MediaWiki conventions on our wiki for a detailed description of the coding conventions that are validated by these rules. :-)
How to install
-
Create a composer.json which adds this project as a dependency:
{ "require-dev": { "mediawiki/mediawiki-codesniffer": "40.0.1" }, "scripts": { "test": [ "phpcs -p -s" ], "fix": "phpcbf" } }
-
Create a .phpcs.xml with our configuration:
<?xml version="1.0"?> <ruleset> <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/> <file>.</file> <arg name="bootstrap" value="./vendor/mediawiki/mediawiki-codesniffer/utils/bootstrap-ci.php"/> <arg name="extensions" value="php"/> <arg name="encoding" value="UTF-8"/> </ruleset>
-
Install:
composer update
-
Run:
composer test
-
Run:
composer fix
to auto-fix some of the errors, others might need manual intervention. -
Commit!
Note that for most MediaWiki projects, we'd also recommend adding a PHP linter
to your composer.json
– see the full documentation for more details.
Configuration
Some of the sniffs provided by this codesniffer standard allow you to configure details of how they work.
-
MediaWiki.Classes.FullQualifiedClassName
: This sniff is disabled by default.<rule ref="MediaWiki.Classes.FullQualifiedClassName"> <severity>5</severity> <properties> <property name="allowMainNamespace" value="false" /> <property name="allowInheritance" value="false" /> <property name="allowFunctions" value="false" /> </properties> </rule>
-
MediaWiki.Usage.ExtendClassUsage
: This sniff lets you exclude globals from being reported by the sniff, in case they cannot be replaced with a Config::getConfig() call. Examples that are already in the list include$wgTitle
and$wgUser
.<rule ref="MediaWiki.Usage.ExtendClassUsage"> <properties> <property name="nonConfigGlobals[]" type="array" value="$wg...,$wg..." /> </properties> </rule>
-
MediaWiki.Commenting.ClassLevelLicense
: This sniff does nothing by default.<rule ref="MediaWiki.Commenting.ClassLevelLicense"> <properties> <property name="license" value="GPL-2.0-or-later" /> </properties> </rule>
-
MediaWiki.NamingConventions.PrefixedGlobalFunctions
: This sniff lets you define a list of ignored global functions and a list of allowed prefixes. By default the only allowed prefix is 'wf', corresponding to the global functionwf...()
.<rule ref="MediaWiki.NamingConventions.PrefixedGlobalFunctions"> <properties> <property name="allowedPrefixes[]" value="wf,..." /> <property name="ignoreList[]" value="...,..." /> </properties> </rule>
-
MediaWiki.NamingConventions.ValidGlobalName
: This sniff lets you define a list of ignored globals and a list of allowed prefixes. By default the only allowed prefix is 'wg', for global variables$wg...
.<rule ref="MediaWiki.NamingConventions.ValidGlobalName"> <properties> <property name="allowedPrefixes[]" value="wg,..." /> <property name="ignoreList[]" value="...,..." /> </properties> </rule>
-
MediaWiki.Arrays.TrailingComma
: This sniff lets you enforce that multi-line arrays have trailing commas, which makes Git diffs nicer. It can also enforce that single-line arrays have no trailing comma. By default, it does nothing.<rule ref="MediaWiki.Arrays.TrailingComma"> <properties> <property name="singleLine" value="false" /> <property name="multiLine" value="true" /> </properties> </rule>