From 43a5de6cef8d592049d043060673c50311573f0e Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Fri, 16 Apr 2021 01:23:23 +0100 Subject: [PATCH 1/5] build: add PHPCompatibility sniffs --- composer.json | 11 ++-- composer.lock | 176 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 181 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 7a919f3..d675906 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ "lint:fix": "composer run lint:php:fix && npm run lint:fix", "format": "npm run format", "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:fix": "./vendor/bin/phpcbf --standard='WordPress' --encoding=utf-8 -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,./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:fix": "npm run lint:css:fix", "lint:js": "npm run lint:js", @@ -24,9 +24,12 @@ }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "phpcompatibility/php-compatibility": "*", "wp-coding-standards/wpcs": "^2.3", "phpdocumentor/phpdocumentor": "^3.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 } diff --git a/composer.lock b/composer.lock index 35d5665..6ddce94 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c15a58a62ba5d8b2d7f3273717a8381a", + "content-hash": "635644be9174c16cb944ef5f2bf46e80", "packages": [], "packages-dev": [ { @@ -1624,6 +1624,178 @@ }, "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", "version": "1.0.0", @@ -5232,7 +5404,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": [], - "prefer-stable": false, + "prefer-stable": true, "prefer-lowest": false, "platform": [], "platform-dev": [], From 9926a42e8ca4537f8f9e83953cedecfc3de03416 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Fri, 16 Apr 2021 01:23:33 +0100 Subject: [PATCH 2/5] style: lint code --- class/settings.php | 64 +++++++++++++++++++++++----------------------- class/task.php | 12 ++++----- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/class/settings.php b/class/settings.php index 3b05d0c..a54ff03 100644 --- a/class/settings.php +++ b/class/settings.php @@ -1275,45 +1275,45 @@ class MCI_Footnotes_Settings { self::C_STR_FOOTNOTES_BACKLINK_TOOLTIP_TEXT => 'Alt+ ←', // Reference container. - self::C_STR_REFERENCE_CONTAINER_NAME => 'References', - self::C_STR_REFERENCE_CONTAINER_LABEL_ELEMENT => 'p', - self::C_STR_REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER => 'yes', - self::C_STR_REFERENCE_CONTAINER_COLLAPSE => 'no', - self::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE => 'jquery', - self::C_STR_REFERENCE_CONTAINER_POSITION => 'post_end', - self::C_STR_REFERENCE_CONTAINER_POSITION_SHORTCODE => '[[references]]', - self::C_STR_FOOTNOTE_SECTION_SHORTCODE => '[[/footnotesection]]', - self::C_STR_REFERENCE_CONTAINER_START_PAGE_ENABLE => 'yes', - self::C_INT_REFERENCE_CONTAINER_TOP_MARGIN => 24, - self::C_INT_REFERENCE_CONTAINER_BOTTOM_MARGIN => 0, - self::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT => 'none', - self::C_STR_FOOTNOTE_URL_WRAP_ENABLED => 'yes', - self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE => 'yes', - self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH => 'no', - self::C_STR_REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE => 'no', - self::C_STR_REFERENCE_CONTAINER_ROW_BORDERS_ENABLE => 'no', + self::C_STR_REFERENCE_CONTAINER_NAME => 'References', + self::C_STR_REFERENCE_CONTAINER_LABEL_ELEMENT => 'p', + self::C_STR_REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER => 'yes', + self::C_STR_REFERENCE_CONTAINER_COLLAPSE => 'no', + self::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE => 'jquery', + self::C_STR_REFERENCE_CONTAINER_POSITION => 'post_end', + self::C_STR_REFERENCE_CONTAINER_POSITION_SHORTCODE => '[[references]]', + self::C_STR_FOOTNOTE_SECTION_SHORTCODE => '[[/footnotesection]]', + self::C_STR_REFERENCE_CONTAINER_START_PAGE_ENABLE => 'yes', + self::C_INT_REFERENCE_CONTAINER_TOP_MARGIN => 24, + self::C_INT_REFERENCE_CONTAINER_BOTTOM_MARGIN => 0, + self::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT => 'none', + self::C_STR_FOOTNOTE_URL_WRAP_ENABLED => 'yes', + self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE => 'yes', + self::C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH => 'no', + self::C_STR_REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE => 'no', + self::C_STR_REFERENCE_CONTAINER_ROW_BORDERS_ENABLE => 'no', - self::C_STR_BACKLINKS_SEPARATOR_ENABLED => 'yes', - self::C_STR_BACKLINKS_SEPARATOR_OPTION => 'comma', - self::C_STR_BACKLINKS_SEPARATOR_CUSTOM => '', + self::C_STR_BACKLINKS_SEPARATOR_ENABLED => 'yes', + self::C_STR_BACKLINKS_SEPARATOR_OPTION => 'comma', + self::C_STR_BACKLINKS_SEPARATOR_CUSTOM => '', - self::C_STR_BACKLINKS_TERMINATOR_ENABLED => 'no', - self::C_STR_BACKLINKS_TERMINATOR_OPTION => 'full_stop', - self::C_STR_BACKLINKS_TERMINATOR_CUSTOM => '', + self::C_STR_BACKLINKS_TERMINATOR_ENABLED => 'no', + self::C_STR_BACKLINKS_TERMINATOR_OPTION => 'full_stop', + self::C_STR_BACKLINKS_TERMINATOR_CUSTOM => '', - self::C_STR_BACKLINKS_COLUMN_WIDTH_ENABLED => 'no', - self::C_INT_BACKLINKS_COLUMN_WIDTH_SCALAR => '50', - self::C_STR_BACKLINKS_COLUMN_WIDTH_UNIT => 'px', + self::C_STR_BACKLINKS_COLUMN_WIDTH_ENABLED => 'no', + self::C_INT_BACKLINKS_COLUMN_WIDTH_SCALAR => '50', + self::C_STR_BACKLINKS_COLUMN_WIDTH_UNIT => 'px', - self::C_STR_BACKLINKS_COLUMN_MAX_WIDTH_ENABLED => 'no', - 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_ENABLED => 'no', + self::C_INT_BACKLINKS_COLUMN_MAX_WIDTH_SCALAR => '140', + self::C_STR_BACKLINKS_COLUMN_MAX_WIDTH_UNIT => 'px', - self::C_STR_BACKLINKS_LINE_BREAKS_ENABLED => 'no', - self::C_STR_LINK_ELEMENT_ENABLED => 'yes', + self::C_STR_BACKLINKS_LINE_BREAKS_ENABLED => 'no', + self::C_STR_LINK_ELEMENT_ENABLED => 'yes', // Footnotes in excerpts. - self::C_STR_FOOTNOTES_IN_EXCERPT => 'manual', + self::C_STR_FOOTNOTES_IN_EXCERPT => 'manual', // Footnotes love. self::C_STR_FOOTNOTES_LOVE => 'no', diff --git a/class/task.php b/class/task.php index becc14b..db61494 100644 --- a/class/task.php +++ b/class/task.php @@ -1097,8 +1097,8 @@ class MCI_Footnotes_Task { */ 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_footnote_section_shortcode = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTE_SECTION_SHORTCODE ); + $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_int_footnote_section_shortcode_length = strlen( $l_str_footnote_section_shortcode ); if ( strpos( $p_str_content, $l_str_footnote_section_shortcode ) === false ) { @@ -1110,14 +1110,14 @@ class MCI_Footnotes_Task { } else { - $l_str_rest_content = $p_str_content; - $l_arr_sections_raw = array(); + $l_str_rest_content = $p_str_content; + $l_arr_sections_raw = array(); $l_arr_sections_processed = array(); 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_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 ); $l_arr_sections_raw[] = $l_str_rest_content; From de4e53f94112f5d74e4f15267d903133bb2e10d5 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Fri, 16 Apr 2021 01:29:27 +0100 Subject: [PATCH 3/5] build: add PHPCompat checks to pre-commit hook --- contrib/pre-commit | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/contrib/pre-commit b/contrib/pre-commit index 0dc792f..f4b5861 100644 --- a/contrib/pre-commit +++ b/contrib/pre-commit @@ -29,33 +29,36 @@ do FILES="$FILES $PROJECT/$FILE" done -if [ -f "$PROJECT/phpcs.ruleset.xml" ] -then - RULESET="$PROJECT/phpcs.ruleset.xml" -elif [ -f "$PROJECT/phpcs.xml.dist" ] -then - RULESET="$PROJECT/phpcs.xml.dist" -else - RULESET="WordPress" -fi +#if [ -f "$PROJECT/phpcs.ruleset.xml" ] +#then +# RULESET="$PROJECT/phpcs.ruleset.xml" +#elif [ -f "$PROJECT/phpcs.xml.dist" ] +#then +# RULESET="$PROJECT/phpcs.xml.dist" +#else + RULESETS=["WordPress","PHPCompatibilityWP"] +#fi if [ "$FILES" != "" ] then - echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..." - ./vendor/bin/phpcs --standard="$RULESET" --colors --encoding=utf-8 -n -p $FILES - if [ $? != 0 ] - 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 + for RULESET in $RULESETS; do + echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..." + ./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 + echo "Coding standards errors have been detected. Running phpcbf..." + ./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 + echo "$RULESET passed." + done fi exit $? From bdd99ac3bc1524f1515c88256248cb1065ae7bae Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Fri, 16 Apr 2021 01:34:08 +0100 Subject: [PATCH 4/5] fix: fix array dec --- contrib/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/pre-commit b/contrib/pre-commit index f4b5861..68b3e47 100644 --- a/contrib/pre-commit +++ b/contrib/pre-commit @@ -36,7 +36,7 @@ done #then # RULESET="$PROJECT/phpcs.xml.dist" #else - RULESETS=["WordPress","PHPCompatibilityWP"] +RULESETS=("WordPress" "PHPCompatibilityWP") #fi if [ "$FILES" != "" ] From 2d7f8125602dadd1ae54b0f8a06610965b609b8b Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Fri, 16 Apr 2021 01:43:25 +0100 Subject: [PATCH 5/5] build: add `node_modules` ignore --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d675906..de6be1e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "lint:js:fix": "npm run lint:js:fix", "format:js": "npm run format:js", "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", "post-install-cmd": "npm install && ./_tools/setup.sh" },