Linting - dotherightthing/wpdtrt-plugin-boilerplate GitHub Wiki
DTRT WordPress Plugin Boilerplate supports code linting, both during development, and when running automated tests.
- Stable @ 1.5.0
- SCSS (SassLint, see
.sass-lint.yml
) - JavaScript (ESLint, see
.eslintrc
) - PHP (CodeSniffer, see
gulpfile.js
andphpcs.xml
)
To see all sniffs run by PHPCS:
$ vendor/bin/phpcs --standard=WordPress -e
or, if using phpcs.xml
(see below):
$ vendor/bin/phpcs --standard=phpcs.xml -e
Source: Listing phpcs rules and excluding commenting sniff
This is useful during development.
In the plugin's ./phpcs.xml
, which is used by Sublime Text:
<?xml version="1.0"?>
<ruleset name="DTRT WordPress">
<description>WordPress standards with DTRT dev exclusions</description>
<!-- The WordPress ruleset cherry picks sniffs from Generic, PEAR, PSR-2, Squiz etc -->
<rule ref="WordPress">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.Functions.DontExtract"/>
<exclude name="WordPress.CSRF.NonceVerification"/>
<exclude name="WordPress.XSS.EscapeOutput"/>
<exclude name="WordPress.VIP.ValidatedSanitizedInput"/>
</rule>
</ruleset>
And in the boilerplate's Gulpfile.js
, which is used by Gulp (via Yarn & Travis):
.pipe(phpcs({
bin: "vendor/bin/phpcs",
// standard must be included and cannot reference phpcs.xml, which is ignored
standard: "WordPress", // -Core + -Docs + -Extra + -VIP
warningSeverity: 0, // minimum severity required to display an error or warning.
showSniffCode: true,
// phpcs.xml exclusions are duplicated below:
exclude: [
"WordPress.Files.FileName",
"WordPress.Functions.DontExtract",
"WordPress.CSRF.NonceVerification",
"WordPress.XSS.EscapeOutput",
"WordPress.VIP.ValidatedSanitizedInput"
]
}))
- SublimeLinter
- SublimeLinter-eslint
- SublimeLinter-json
- SublimeLinter-phpcs
- SublimeLinter-contrib-sass-lint
{
"folders":
[
{
"path": "."
}
],
"settings":
{
"SublimeLinter.linters.phpcs.args":
[
"-s",
"--warning-severity=0"
],
"SublimeLinter.linters.phpcs.disable": false,
"SublimeLinter.linters.phpcs.standard": "${folder}/phpcs.xml"
}
}
Sublime Text > Preferences > Package Settings > SublimeLinter > Settings
// SublimeLinter Settings - User
{
"linters": {
"jshint": {
"disable": false,
"selector": "*.js, gulpfile.js"
},
"phpcs": {
"disable": false,
"standard": "${folder}/phpcs.xml",
"args": [
"-s",
"--warning-severity=0"
]
}
}
}
yarn run lint
This is also run during the Travis CI build.