Merge pull request #105 from markcheret/php-compatibility-sniffs

build: add PHPCompatibility sniffs
This commit is contained in:
Mark Cheret 2021-04-16 03:49:56 +02:00 committed by GitHub
commit b6513d9c4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 244 additions and 66 deletions

View file

@ -1275,45 +1275,45 @@ class MCI_Footnotes_Settings {
self::C_STR_FOOTNOTES_BACKLINK_TOOLTIP_TEXT => 'Alt+ ←', self::C_STR_FOOTNOTES_BACKLINK_TOOLTIP_TEXT => 'Alt+ ←',
// Reference container. // Reference container.
self::C_STR_REFERENCE_CONTAINER_NAME => 'References', self::C_STR_REFERENCE_CONTAINER_NAME => 'References',
self::C_STR_REFERENCE_CONTAINER_LABEL_ELEMENT => 'p', self::C_STR_REFERENCE_CONTAINER_LABEL_ELEMENT => 'p',
self::C_STR_REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER => 'yes', self::C_STR_REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER => 'yes',
self::C_STR_REFERENCE_CONTAINER_COLLAPSE => 'no', self::C_STR_REFERENCE_CONTAINER_COLLAPSE => 'no',
self::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE => 'jquery', self::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE => 'jquery',
self::C_STR_REFERENCE_CONTAINER_POSITION => 'post_end', self::C_STR_REFERENCE_CONTAINER_POSITION => 'post_end',
self::C_STR_REFERENCE_CONTAINER_POSITION_SHORTCODE => '[[references]]', self::C_STR_REFERENCE_CONTAINER_POSITION_SHORTCODE => '[[references]]',
self::C_STR_FOOTNOTE_SECTION_SHORTCODE => '[[/footnotesection]]', self::C_STR_FOOTNOTE_SECTION_SHORTCODE => '[[/footnotesection]]',
self::C_STR_REFERENCE_CONTAINER_START_PAGE_ENABLE => 'yes', self::C_STR_REFERENCE_CONTAINER_START_PAGE_ENABLE => 'yes',
self::C_INT_REFERENCE_CONTAINER_TOP_MARGIN => 24, self::C_INT_REFERENCE_CONTAINER_TOP_MARGIN => 24,
self::C_INT_REFERENCE_CONTAINER_BOTTOM_MARGIN => 0, self::C_INT_REFERENCE_CONTAINER_BOTTOM_MARGIN => 0,
self::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT => 'none', self::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT => 'none',
self::C_STR_FOOTNOTE_URL_WRAP_ENABLED => 'yes', self::C_STR_FOOTNOTE_URL_WRAP_ENABLED => 'yes',
self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE => 'yes', self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE => 'yes',
self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH => 'no', self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH => 'no',
self::C_STR_REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE => 'no', self::C_STR_REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE => 'no',
self::C_STR_REFERENCE_CONTAINER_ROW_BORDERS_ENABLE => 'no', self::C_STR_REFERENCE_CONTAINER_ROW_BORDERS_ENABLE => 'no',
self::C_STR_BACKLINKS_SEPARATOR_ENABLED => 'yes', self::C_STR_BACKLINKS_SEPARATOR_ENABLED => 'yes',
self::C_STR_BACKLINKS_SEPARATOR_OPTION => 'comma', self::C_STR_BACKLINKS_SEPARATOR_OPTION => 'comma',
self::C_STR_BACKLINKS_SEPARATOR_CUSTOM => '', self::C_STR_BACKLINKS_SEPARATOR_CUSTOM => '',
self::C_STR_BACKLINKS_TERMINATOR_ENABLED => 'no', self::C_STR_BACKLINKS_TERMINATOR_ENABLED => 'no',
self::C_STR_BACKLINKS_TERMINATOR_OPTION => 'full_stop', self::C_STR_BACKLINKS_TERMINATOR_OPTION => 'full_stop',
self::C_STR_BACKLINKS_TERMINATOR_CUSTOM => '', self::C_STR_BACKLINKS_TERMINATOR_CUSTOM => '',
self::C_STR_BACKLINKS_COLUMN_WIDTH_ENABLED => 'no', self::C_STR_BACKLINKS_COLUMN_WIDTH_ENABLED => 'no',
self::C_INT_BACKLINKS_COLUMN_WIDTH_SCALAR => '50', self::C_INT_BACKLINKS_COLUMN_WIDTH_SCALAR => '50',
self::C_STR_BACKLINKS_COLUMN_WIDTH_UNIT => 'px', self::C_STR_BACKLINKS_COLUMN_WIDTH_UNIT => 'px',
self::C_STR_BACKLINKS_COLUMN_MAX_WIDTH_ENABLED => 'no', self::C_STR_BACKLINKS_COLUMN_MAX_WIDTH_ENABLED => 'no',
self::C_INT_BACKLINKS_COLUMN_MAX_WIDTH_SCALAR => '140', self::C_INT_BACKLINKS_COLUMN_MAX_WIDTH_SCALAR => '140',
self::C_STR_BACKLINKS_COLUMN_MAX_WIDTH_UNIT => 'px', self::C_STR_BACKLINKS_COLUMN_MAX_WIDTH_UNIT => 'px',
self::C_STR_BACKLINKS_LINE_BREAKS_ENABLED => 'no', self::C_STR_BACKLINKS_LINE_BREAKS_ENABLED => 'no',
self::C_STR_LINK_ELEMENT_ENABLED => 'yes', self::C_STR_LINK_ELEMENT_ENABLED => 'yes',
// Footnotes in excerpts. // Footnotes in excerpts.
self::C_STR_FOOTNOTES_IN_EXCERPT => 'manual', self::C_STR_FOOTNOTES_IN_EXCERPT => 'manual',
// Footnotes love. // Footnotes love.
self::C_STR_FOOTNOTES_LOVE => 'no', self::C_STR_FOOTNOTES_LOVE => 'no',

View file

@ -1097,8 +1097,8 @@ class MCI_Footnotes_Task {
*/ */
public function footnotes_in_content( $p_str_content ) { public function footnotes_in_content( $p_str_content ) {
$l_str_ref_container_position = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION ); $l_str_ref_container_position = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION );
$l_str_footnote_section_shortcode = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTE_SECTION_SHORTCODE ); $l_str_footnote_section_shortcode = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTE_SECTION_SHORTCODE );
$l_int_footnote_section_shortcode_length = strlen( $l_str_footnote_section_shortcode ); $l_int_footnote_section_shortcode_length = strlen( $l_str_footnote_section_shortcode );
if ( strpos( $p_str_content, $l_str_footnote_section_shortcode ) === false ) { if ( strpos( $p_str_content, $l_str_footnote_section_shortcode ) === false ) {
@ -1110,14 +1110,14 @@ class MCI_Footnotes_Task {
} else { } else {
$l_str_rest_content = $p_str_content; $l_str_rest_content = $p_str_content;
$l_arr_sections_raw = array(); $l_arr_sections_raw = array();
$l_arr_sections_processed = array(); $l_arr_sections_processed = array();
do { do {
$l_int_section_end = strpos( $l_str_rest_content, $l_str_footnote_section_shortcode ); $l_int_section_end = strpos( $l_str_rest_content, $l_str_footnote_section_shortcode );
$l_arr_sections_raw[] = substr( $l_str_rest_content, 0, $l_int_section_end ); $l_arr_sections_raw[] = substr( $l_str_rest_content, 0, $l_int_section_end );
$l_str_rest_content = substr( $l_str_rest_content, $l_int_section_end + $l_int_footnote_section_shortcode_length ); $l_str_rest_content = substr( $l_str_rest_content, $l_int_section_end + $l_int_footnote_section_shortcode_length );
} while ( strpos( $l_str_rest_content, $l_str_footnote_section_shortcode ) !== false ); } while ( strpos( $l_str_rest_content, $l_str_footnote_section_shortcode ) !== false );
$l_arr_sections_raw[] = $l_str_rest_content; $l_arr_sections_raw[] = $l_str_rest_content;

View file

@ -10,23 +10,26 @@
"lint:fix": "composer run lint:php:fix && npm run lint:fix", "lint:fix": "composer run lint:php:fix && npm run lint:fix",
"format": "npm run format", "format": "npm run format",
"format:fix": "npm run format:fix", "format:fix": "npm run format:fix",
"lint:php": "./vendor/bin/phpcs --standard='WordPress' --colors --encoding=utf-8 -n -p --ignore=*/vendor/* ./*.php ./*/*.php ./*/*/*.php", "lint:php": "./vendor/bin/phpcs --standard=WordPress --colors --encoding=utf-8 -n -p --ignore=./vendor,./node_modules ./**/*.php && ./vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 7.0- --colors --encoding=utf-8 -n -p --ignore=./vendor,./node_modules ./**/*.php",
"lint:php:fix": "./vendor/bin/phpcbf --standard='WordPress' --encoding=utf-8 -p --ignore=*/vendor/* ./*.php ./*/*.php ./*/*/*.php", "lint:php:fix": "./vendor/bin/phpcbf --standard=WordPress --encoding=utf-8 -p --ignore=./vendor,./node_modules ./**/*.php && ./vendor/bin/phpcbf --standard=PHPCompatibilityWP --runtime-set testVersion 7.0- --encoding=utf-8 -p --ignore=./vendor,./node_modules ./**/*.php",
"lint:css": "npm run lint:css", "lint:css": "npm run lint:css",
"lint:css:fix": "npm run lint:css:fix", "lint:css:fix": "npm run lint:css:fix",
"lint:js": "npm run lint:js", "lint:js": "npm run lint:js",
"lint:js:fix": "npm run lint:js:fix", "lint:js:fix": "npm run lint:js:fix",
"format:js": "npm run format:js", "format:js": "npm run format:js",
"format:js:fix": "npm run format:js:fix", "format:js:fix": "npm run format:js:fix",
"docs": "./vendor/bin/phpdoc -d . -t ./docs --ignore vendor/", "docs": "./vendor/bin/phpdoc -d . -t ./docs --ignore .vendor/ --ignore .node_modules/",
"commit": "./vendor/bin/php-commitizen commit -- ./.php-commitizen.php", "commit": "./vendor/bin/php-commitizen commit -- ./.php-commitizen.php",
"post-install-cmd": "npm install && ./_tools/setup.sh" "post-install-cmd": "npm install && ./_tools/setup.sh"
}, },
"require-dev": { "require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"phpcompatibility/php-compatibility": "*",
"wp-coding-standards/wpcs": "^2.3", "wp-coding-standards/wpcs": "^2.3",
"phpdocumentor/phpdocumentor": "^3.0", "phpdocumentor/phpdocumentor": "^3.0",
"damianopetrungaro/php-commitizen": "^0.2.0", "damianopetrungaro/php-commitizen": "^0.2.0",
"marcocesarato/php-conventional-changelog": "^1.9" "marcocesarato/php-conventional-changelog": "^1.9",
} "phpcompatibility/phpcompatibility-wp": "*"
},
"prefer-stable": true
} }

176
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c15a58a62ba5d8b2d7f3273717a8381a", "content-hash": "635644be9174c16cb944ef5f2bf46e80",
"packages": [], "packages": [],
"packages-dev": [ "packages-dev": [
{ {
@ -1624,6 +1624,178 @@
}, },
"time": "2020-12-20T10:01:03+00:00" "time": "2020-12-20T10:01:03+00:00"
}, },
{
"name": "phpcompatibility/php-compatibility",
"version": "9.3.5",
"source": {
"type": "git",
"url": "https://github.com/PHPCompatibility/PHPCompatibility.git",
"reference": "9fb324479acf6f39452e0655d2429cc0d3914243"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243",
"reference": "9fb324479acf6f39452e0655d2429cc0d3914243",
"shasum": ""
},
"require": {
"php": ">=5.3",
"squizlabs/php_codesniffer": "^2.3 || ^3.0.2"
},
"conflict": {
"squizlabs/php_codesniffer": "2.6.2"
},
"require-dev": {
"phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0"
},
"suggest": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.",
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
},
"type": "phpcodesniffer-standard",
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "Wim Godden",
"homepage": "https://github.com/wimg",
"role": "lead"
},
{
"name": "Juliette Reinders Folmer",
"homepage": "https://github.com/jrfnl",
"role": "lead"
},
{
"name": "Contributors",
"homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors"
}
],
"description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.",
"homepage": "http://techblog.wimgodden.be/tag/codesniffer/",
"keywords": [
"compatibility",
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues",
"source": "https://github.com/PHPCompatibility/PHPCompatibility"
},
"time": "2019-12-27T09:44:58+00:00"
},
{
"name": "phpcompatibility/phpcompatibility-paragonie",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git",
"reference": "ddabec839cc003651f2ce695c938686d1086cf43"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/ddabec839cc003651f2ce695c938686d1086cf43",
"reference": "ddabec839cc003651f2ce695c938686d1086cf43",
"shasum": ""
},
"require": {
"phpcompatibility/php-compatibility": "^9.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"paragonie/random_compat": "dev-master",
"paragonie/sodium_compat": "dev-master"
},
"suggest": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
},
"type": "phpcodesniffer-standard",
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "Wim Godden",
"role": "lead"
},
{
"name": "Juliette Reinders Folmer",
"role": "lead"
}
],
"description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.",
"homepage": "http://phpcompatibility.com/",
"keywords": [
"compatibility",
"paragonie",
"phpcs",
"polyfill",
"standards"
],
"support": {
"issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues",
"source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie"
},
"time": "2021-02-15T10:24:51+00:00"
},
{
"name": "phpcompatibility/phpcompatibility-wp",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git",
"reference": "b7dc0cd7a8f767ccac5e7637550ea1c50a67b09e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b7dc0cd7a8f767ccac5e7637550ea1c50a67b09e",
"reference": "b7dc0cd7a8f767ccac5e7637550ea1c50a67b09e",
"shasum": ""
},
"require": {
"phpcompatibility/php-compatibility": "^9.0",
"phpcompatibility/phpcompatibility-paragonie": "^1.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7"
},
"suggest": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
},
"type": "phpcodesniffer-standard",
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "Wim Godden",
"role": "lead"
},
{
"name": "Juliette Reinders Folmer",
"role": "lead"
}
],
"description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.",
"homepage": "http://phpcompatibility.com/",
"keywords": [
"compatibility",
"phpcs",
"standards",
"wordpress"
],
"support": {
"issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues",
"source": "https://github.com/PHPCompatibility/PHPCompatibilityWP"
},
"time": "2021-02-15T12:58:46+00:00"
},
{ {
"name": "phpdocumentor/flyfinder", "name": "phpdocumentor/flyfinder",
"version": "1.0.0", "version": "1.0.0",
@ -5232,7 +5404,7 @@
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": [],
"prefer-stable": false, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],
"platform-dev": [], "platform-dev": [],

View file

@ -29,33 +29,36 @@ do
FILES="$FILES $PROJECT/$FILE" FILES="$FILES $PROJECT/$FILE"
done done
if [ -f "$PROJECT/phpcs.ruleset.xml" ] #if [ -f "$PROJECT/phpcs.ruleset.xml" ]
then #then
RULESET="$PROJECT/phpcs.ruleset.xml" # RULESET="$PROJECT/phpcs.ruleset.xml"
elif [ -f "$PROJECT/phpcs.xml.dist" ] #elif [ -f "$PROJECT/phpcs.xml.dist" ]
then #then
RULESET="$PROJECT/phpcs.xml.dist" # RULESET="$PROJECT/phpcs.xml.dist"
else #else
RULESET="WordPress" RULESETS=("WordPress" "PHPCompatibilityWP")
fi #fi
if [ "$FILES" != "" ] if [ "$FILES" != "" ]
then then
echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..." for RULESET in $RULESETS; do
./vendor/bin/phpcs --standard="$RULESET" --colors --encoding=utf-8 -n -p $FILES echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..."
if [ $? != 0 ] ./vendor/bin/phpcs --standard="$RULESET" --runtime-set testVersion 7.0- --colors --encoding=utf-8 -n -p $FILES
then
echo "Coding standards errors have been detected. Running phpcbf..."
./vendor/bin/phpcbf --standard="$RULESET" --encoding=utf-8 -n -p $FILES
git add $FILES
echo "Running Code Sniffer again..."
./vendor/bin/phpcs --standard="$RULESET" --colors --encoding=utf-8 -n -p $FILES
if [ $? != 0 ] if [ $? != 0 ]
then then
echo "Errors found not fixable automatically. You need to manually fix them." echo "Coding standards errors have been detected. Running phpcbf..."
exit 1 ./vendor/bin/phpcbf --standard="$RULESET" --runtime-set testVersion 7.0- --encoding=utf-8 -n -p $FILES
git add $FILES
echo "Running Code Sniffer again..."
./vendor/bin/phpcs --standard="$RULESET" --runtime-set testVersion 7.0- --colors --encoding=utf-8 -n -p $FILES
if [ $? != 0 ]
then
echo "Errors found not fixable automatically. You need to manually fix them."
exit 1
fi
fi fi
fi echo "$RULESET passed."
done
fi fi
exit $? exit $?