From 912dd34541e73eb79191065776c3793057204e6c Mon Sep 17 00:00:00 2001 From: Peter Downey Date: Wed, 25 Nov 2026 03:51:07 -0500 Subject: [PATCH] Run the checks of Codacy's WordPress standard in CI as well Codacy's "WordPress" coding standard turns on checks that the plugin's own configuration did not run. Each one that fits the WordPress style and passes on the plugin is now in a configuration file that both CI and Codacy read, so a pull request gets the same checks before Codacy runs: - PHPCS: 24 checks join phpcs-wordpress.xml (PHPCS's own standards and Slevomat, now a dev dependency); codacy-configs.py copies Slevomat into phpcs.xml. - ESLint: 85 rules (70 core, 15 unicorn) join eslint.config.mjs, which Codacy reads and the full configuration includes. - Stylelint: 21 rules join stylelint-wordpress.json; codacy-configs.py copies them into .stylelintrc.json. - Biome: biome.json turns on Codacy's 232 lint rules; npm run lint:biome runs it with Biome 2.5.14, the version Codacy uses. - Pylint: .pylintrc turns on Codacy's 95 checks. - Bandit: bandit.yml runs every test. Checks that contradict the WordPress style or this code (such as Yoda conditions, tab indentation, or no-ternary) and deprecated ESLint rules are listed in the files as left out, each with its reason. The lint job runs Pylint, Bandit, and Biome, which lint-requirements.txt and package.json pin. PHPMD and markdownlint already ran every check Codacy turns on. Co-Authored-By: Claude Opus 5.5 --- .codacy.yml | 9 +- .distignore | 2 + .gitattributes | 3 + .github/labeler.yml | 3 + .github/lint-requirements.txt | 2 + .github/scripts/codacy-configs.py | 12 +- .github/workflows/wp-compatibility-test.yml | 21 +- .pylintrc | 105 ++++++++ .stylelintrc.json | 98 +++++++ CONTRIBUTING.md | 5 +- bandit.yml | 3 + biome.json | 275 ++++++++++++++++++++ composer.json | 3 +- composer.lock | 67 ++++- eslint.config.mjs | 98 +++++++ package-lock.json | 176 +++++++++++++ package.json | 2 + phpcs-wordpress.xml | 65 +++++ phpcs.xml | 28 ++ stylelint-wordpress.json | 75 +++++- 20 files changed, 1041 insertions(+), 11 deletions(-) create mode 100644 .pylintrc create mode 100644 bandit.yml create mode 100644 biome.json diff --git a/.codacy.yml b/.codacy.yml index 894fd0d..302575e 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -1,10 +1,11 @@ --- # Codacy configuration # -# With each tool's "Configuration file" setting on, Codacy reads phpcs.xml, phpmd.xml, eslint.config.mjs, .stylelintrc.json, and -# .markdownlint.json. Codacy installs no WordPress standards or packages, so those files hold only -# what it can run; CI runs the full configurations (phpcs-wordpress.xml, phpmd.xml, eslint.wordpress.config.mjs, stylelint-wordpress.json). -# See CONTRIBUTING.md. +# With each tool's "Configuration file" setting on, Codacy reads phpcs.xml, phpmd.xml, +# eslint.config.mjs, .stylelintrc.json, .markdownlint.json, biome.json, .pylintrc, and bandit.yml. +# Codacy installs no WordPress standards or packages, so those files hold only what it can run; CI +# runs the full configurations (phpcs-wordpress.xml, phpmd.xml, eslint.wordpress.config.mjs, +# stylelint-wordpress.json) and the same Biome, Pylint, and Bandit files. See CONTRIBUTING.md. engines: # Lizard reads the lock files as source code and reports their length. diff --git a/.distignore b/.distignore index b82e565..15e784c 100644 --- a/.distignore +++ b/.distignore @@ -69,6 +69,8 @@ /package.json /package-lock.json /phpcs.xml +/bandit.yml +/biome.json /phpcs-wordpress.xml /phpmd.xml /phpstan.neon diff --git a/.gitattributes b/.gitattributes index a95182f..0590399 100644 --- a/.gitattributes +++ b/.gitattributes @@ -23,6 +23,9 @@ /package.json export-ignore /package-lock.json export-ignore /phpcs.xml export-ignore +/bandit.yml export-ignore +/.pylintrc export-ignore +/biome.json export-ignore /phpcs-wordpress.xml export-ignore /phpmd.xml export-ignore /phpstan.neon export-ignore diff --git a/.github/labeler.yml b/.github/labeler.yml index 64124fc..ae33d87 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -53,6 +53,9 @@ testing: - any-glob-to-any-file: stubs/**/* - any-glob-to-any-file: phpunit.xml - any-glob-to-any-file: phpcs.xml + - any-glob-to-any-file: bandit.yml + - any-glob-to-any-file: .pylintrc + - any-glob-to-any-file: biome.json - any-glob-to-any-file: phpcs-wordpress.xml - any-glob-to-any-file: phpmd.xml - any-glob-to-any-file: phpstan.neon diff --git a/.github/lint-requirements.txt b/.github/lint-requirements.txt index eb9249c..c5b6168 100644 --- a/.github/lint-requirements.txt +++ b/.github/lint-requirements.txt @@ -1,7 +1,9 @@ # Linters that the lint job of wp-compatibility-test.yml installs. # Renovate keeps the versions current. actionlint-py==1.7.12.25 +bandit==1.9.4 mypy==2.4.1 +pylint==4.1.4 ruff==0.17.5 yamllint==1.38.0 zizmor==1.32.0 diff --git a/.github/scripts/codacy-configs.py b/.github/scripts/codacy-configs.py index 21f9d10..b6f26f7 100755 --- a/.github/scripts/codacy-configs.py +++ b/.github/scripts/codacy-configs.py @@ -34,7 +34,17 @@ # PHPCS standards that Codacy installs. PHPCompatibilityWP is referenced as a whole standard in # phpcs.xml's hand-written part, so its sniffs are not listed one by one. -CODACY_PHPCS_STANDARDS = ("Generic", "PEAR", "PSR1", "PSR2", "PSR12", "Squiz", "Zend", "VariableAnalysis") +CODACY_PHPCS_STANDARDS = ( + "Generic", + "PEAR", + "PSR1", + "PSR2", + "PSR12", + "Squiz", + "Zend", + "SlevomatCodingStandard", + "VariableAnalysis", +) BEGIN = " " END = " " # A message code (Standard.Category.Sniff.Code) has three dots; a sniff code has two. diff --git a/.github/workflows/wp-compatibility-test.yml b/.github/workflows/wp-compatibility-test.yml index 2373d4b..5d56454 100644 --- a/.github/workflows/wp-compatibility-test.yml +++ b/.github/workflows/wp-compatibility-test.yml @@ -1343,6 +1343,17 @@ jobs: # .mypy.ini names the files and sets the strict mode. run: mypy + - name: Run Pylint + id: run_pylint + # .pylintrc turns on the checks Codacy's Pylint runs; Codacy reads the same file. + run: pylint --rcfile=.pylintrc .github/scripts/*.py + + - name: Run Bandit + id: run_bandit + # bandit.yml runs every test; Codacy reads the same file. Bandit's default exclusions also + # match .github, so -x replaces them. + run: bandit --configfile bandit.yml -x node_modules .github/scripts/*.py + - name: Run markdownlint id: run_markdownlint run: | @@ -1367,6 +1378,11 @@ jobs: npm run --silent lint:css python3 .github/scripts/codacy-configs.py stylelint --check + - name: Run Biome + id: run_biome + # biome.json turns on the lint rules Codacy's Biome runs; Codacy reads the same file. + run: npm run --silent lint:biome + - name: Preserve diagnostic summary id: preserve_diagnostics if: ${{ always() }} @@ -1382,9 +1398,12 @@ jobs: run_zizmor=${{ steps.run_zizmor.outcome }} run_ruff=${{ steps.run_ruff.outcome }} run_mypy=${{ steps.run_mypy.outcome }} + run_pylint=${{ steps.run_pylint.outcome }} + run_bandit=${{ steps.run_bandit.outcome }} run_markdownlint=${{ steps.run_markdownlint.outcome }} run_eslint=${{ steps.run_eslint.outcome }} run_stylelint=${{ steps.run_stylelint.outcome }} + run_biome=${{ steps.run_biome.outcome }} run: | mkdir -p "$RUNNER_TEMP/optimizations-ace-mc-diagnostics" printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/optimizations-ace-mc-diagnostics/steps.txt" @@ -1425,7 +1444,7 @@ jobs: uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_node.outcome == 'failure' && 'setup_node' || steps.install_npm_dependencies.outcome == 'failure' && 'install_npm_dependencies' || steps.install_python_linters.outcome == 'failure' && 'install_python_linters' || steps.run_yamllint.outcome == 'failure' && 'run_yamllint' || steps.run_actionlint.outcome == 'failure' && 'run_actionlint' || steps.run_zizmor.outcome == 'failure' && 'run_zizmor' || steps.run_ruff.outcome == 'failure' && 'run_ruff' || steps.run_mypy.outcome == 'failure' && 'run_mypy' || steps.run_markdownlint.outcome == 'failure' && 'run_markdownlint' || steps.run_eslint.outcome == 'failure' && 'run_eslint' || steps.run_stylelint.outcome == 'failure' && 'run_stylelint' || 'unknown_or_canceled' }} + FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_node.outcome == 'failure' && 'setup_node' || steps.install_npm_dependencies.outcome == 'failure' && 'install_npm_dependencies' || steps.install_python_linters.outcome == 'failure' && 'install_python_linters' || steps.run_yamllint.outcome == 'failure' && 'run_yamllint' || steps.run_actionlint.outcome == 'failure' && 'run_actionlint' || steps.run_zizmor.outcome == 'failure' && 'run_zizmor' || steps.run_ruff.outcome == 'failure' && 'run_ruff' || steps.run_mypy.outcome == 'failure' && 'run_mypy' || steps.run_pylint.outcome == 'failure' && 'run_pylint' || steps.run_bandit.outcome == 'failure' && 'run_bandit' || steps.run_markdownlint.outcome == 'failure' && 'run_markdownlint' || steps.run_eslint.outcome == 'failure' && 'run_eslint' || steps.run_stylelint.outcome == 'failure' && 'run_stylelint' || steps.run_biome.outcome == 'failure' && 'run_biome' || 'unknown_or_canceled' }} NODE_VERSION: '24' RUN_ID: ${{ github.run_id }} WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..8a66ad8 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,105 @@ +# Pylint settings: the checks that Codacy's Pylint runs on the automation scripts. Codacy reads +# this file, and the lint job of wp-compatibility-test.yml runs Pylint with it. Ruff and mypy +# check the same scripts with their own, wider rule sets. + +[MAIN] +py-version = 3.12 + +[MESSAGES CONTROL] +disable = all +enable = + C0123, + C0200, + E0100, + E0101, + E0102, + E0103, + E0104, + E0105, + E0106, + E0107, + E0108, + E0110, + E0112, + E0113, + E0114, + E0115, + E0117, + E0202, + E0203, + E0211, + E0236, + E0238, + E0239, + E0240, + E0241, + E0301, + E0302, + E0601, + E0603, + E0604, + E0701, + E0702, + E0704, + E0710, + E0711, + E0712, + E1003, + E1102, + E1111, + E1120, + E1121, + E1123, + E1124, + E1125, + E1126, + E1127, + E1132, + E1200, + E1201, + E1205, + E1206, + E1300, + E1301, + E1302, + E1303, + E1304, + E1305, + E1306, + R0202, + R0203, + W0101, + W0102, + W0104, + W0105, + W0106, + W0107, + W0108, + W0109, + W0120, + W0122, + W0123, + W0124, + W0150, + W0199, + W0221, + W0222, + W0233, + W0404, + W0410, + W0601, + W0602, + W0604, + W0611, + W0612, + W0622, + W0702, + W0705, + W0711, + W1300, + W1301, + W1302, + W1303, + W1305, + W1306, + W1307 diff --git a/.stylelintrc.json b/.stylelintrc.json index 36ac7dd..ebcc8fa 100644 --- a/.stylelintrc.json +++ b/.stylelintrc.json @@ -1,5 +1,17 @@ { "rules": { + "alpha-value-notation": [ + "percentage", + { + "exceptProperties": [ + "opacity", + "fill-opacity", + "flood-opacity", + "stop-opacity", + "stroke-opacity" + ] + } + ], "annotation-no-unknown": null, "at-rule-descriptor-no-unknown": [ true @@ -24,6 +36,9 @@ "at-rule-no-unknown": [ true ], + "at-rule-no-vendor-prefix": [ + true + ], "at-rule-prelude-no-invalid": [ true, { @@ -35,6 +50,9 @@ "block-no-empty": [ true ], + "color-function-notation": [ + "modern" + ], "color-hex-length": [ "short" ], @@ -52,6 +70,25 @@ "comment-no-empty": [ true ], + "comment-whitespace-inside": [ + "always" + ], + "custom-media-pattern": [ + "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" + ], + "custom-property-empty-line-before": [ + "always", + { + "except": [ + "after-custom-property", + "first-nested" + ], + "ignore": [ + "after-comment", + "inside-single-line-block" + ] + } + ], "custom-property-no-missing-var-function": [ true ], @@ -70,9 +107,28 @@ ] } ], + "declaration-block-no-redundant-longhand-properties": [ + true + ], "declaration-block-no-shorthand-property-overrides": [ true ], + "declaration-block-single-line-max-declarations": [ + 1 + ], + "declaration-empty-line-before": [ + "always", + { + "except": [ + "after-declaration", + "first-nested" + ], + "ignore": [ + "after-comment", + "inside-single-line-block" + ] + } + ], "declaration-property-unit-allowed-list": [ { "line-height": [ @@ -113,10 +169,22 @@ "function-url-quotes": [ "never" ], + "hue-degree-notation": [ + "angle" + ], + "import-notation": [ + "url" + ], "keyframe-block-no-duplicate-selectors": null, "keyframe-declaration-no-important": [ true ], + "keyframe-selector-notation": [ + "percentage-unless-within-keyword-only-block" + ], + "keyframes-name-pattern": [ + "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" + ], "length-zero-no-unit": [ true, { @@ -131,9 +199,15 @@ "media-feature-name-no-unknown": [ true ], + "media-feature-name-no-vendor-prefix": [ + true + ], "media-feature-name-value-no-unknown": [ true ], + "media-feature-range-notation": [ + "context" + ], "media-query-no-invalid": null, "media-type-no-deprecated": [ true @@ -168,12 +242,18 @@ "no-irregular-whitespace": [ true ], + "number-max-precision": [ + 4 + ], "property-no-deprecated": [ true ], "property-no-unknown": [ true ], + "property-no-vendor-prefix": [ + true + ], "rule-empty-line-before": [ "always", { @@ -198,6 +278,12 @@ "message": "Selector should use lowercase and separate words with hyphens (selector-id-pattern)" } ], + "selector-no-vendor-prefix": [ + true + ], + "selector-not-notation": [ + "complex" + ], "selector-pseudo-class-no-unknown": [ true ], @@ -218,6 +304,9 @@ ] } ], + "shorthand-property-no-redundant-values": [ + true + ], "string-no-newline": [ true, { @@ -232,6 +321,15 @@ ], "value-keyword-case": [ "lower" + ], + "value-no-vendor-prefix": [ + true, + { + "ignoreValues": [ + "box", + "inline-box" + ] + } ] } } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 939ec08..12223b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -108,6 +108,9 @@ optimizations-ace-mc/ |-- phpcs.xml # The part Codacy can run, generated from phpcs-wordpress.xml |-- phpstan.neon # PHPStan configuration |-- phpmd.xml # PHPMD configuration +|-- biome.json # Biome lint rules (npm run lint:biome, CI, Codacy) +|-- .pylintrc # Pylint checks for .github/scripts (CI, Codacy) +|-- bandit.yml # Bandit settings for .github/scripts (CI, Codacy) |-- eslint.wordpress.config.mjs # ESLint configuration (npm run lint:js, CI) |-- eslint.config.mjs # Its settings without the WordPress standards, for Codacy |-- stylelint-wordpress.json # Stylelint configuration (npm run lint:css, CI) @@ -120,7 +123,7 @@ optimizations-ace-mc/ The release package holds the main plugin file, `readme.txt`, `LICENSE`, `includes/`, `assets/`, and `languages/`. When you add a top-level file or directory, add it to `.distignore` and `.gitattributes` unless it must ship; `.github/scripts/check-plugin-package.py` fails when the package lists disagree. -Codacy reads `phpcs.xml`, `phpmd.xml`, `eslint.config.mjs`, and `.stylelintrc.json`, but it installs no WordPress coding standards, no PHPCSExtra, no WordPress ESLint or Stylelint packages, and only PHPMD 2. Keep those files to what Codacy installs; the full configurations add the rest. After changing `phpcs-wordpress.xml` or `stylelint-wordpress.json`, or updating their packages, regenerate the Codacy copies with `python .github/scripts/codacy-configs.py phpcs` and `python .github/scripts/codacy-configs.py stylelint`. CI fails when they are out of date. +Codacy reads `phpcs.xml`, `phpmd.xml`, `eslint.config.mjs`, and `.stylelintrc.json`, but it installs no WordPress coding standards, no PHPCSExtra, no WordPress ESLint or Stylelint packages, and only PHPMD 2. Keep those files to what Codacy installs; the full configurations add the rest. After changing `phpcs-wordpress.xml` or `stylelint-wordpress.json`, or updating their packages, regenerate the Codacy copies with `python .github/scripts/codacy-configs.py phpcs` and `python .github/scripts/codacy-configs.py stylelint`. CI fails when they are out of date. Codacy also reads `biome.json`, `.pylintrc`, and `bandit.yml`, and CI runs Biome (`npm run lint:biome`), Pylint, and Bandit with the same files, so a pull request gets every check Codacy runs before Codacy does. ## Making Changes diff --git a/bandit.yml b/bandit.yml new file mode 100644 index 0000000..9151319 --- /dev/null +++ b/bandit.yml @@ -0,0 +1,3 @@ +# Bandit settings: every test runs, none skipped. Codacy's Bandit reads this file, and the lint job +# of wp-compatibility-test.yml runs Bandit with it. +skips: [] diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..5faab12 --- /dev/null +++ b/biome.json @@ -0,0 +1,275 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.5.14/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "includes": [ + "**", + "!**/vendor", + "!**/node_modules", + "!**/package-lock.json", + "!**/composer.lock" + ] + }, + "formatter": { + "enabled": false + }, + "assist": { + "enabled": false + }, + "linter": { + "enabled": true, + "rules": { + "preset": "none", + "a11y": { + "noAccessKey": "error", + "noAriaHiddenOnFocusable": "error", + "noAriaUnsupportedElements": "error", + "noAutofocus": "error", + "noDistractingElements": "error", + "noHeaderScope": "error", + "noInteractiveElementToNoninteractiveRole": "error", + "noLabelWithoutControl": "error", + "noNoninteractiveElementToInteractiveRole": "error", + "noNoninteractiveTabindex": "error", + "noPositiveTabindex": "error", + "noRedundantAlt": "error", + "noRedundantRoles": "error", + "noStaticElementInteractions": "error", + "noSvgWithoutTitle": "error", + "useAltText": "error", + "useAnchorContent": "error", + "useAriaActivedescendantWithTabindex": "error", + "useAriaPropsForRole": "error", + "useAriaPropsSupportedByRole": "error", + "useButtonType": "error", + "useFocusableInteractive": "error", + "useGenericFontNames": "error", + "useHeadingContent": "error", + "useHtmlLang": "error", + "useIframeTitle": "error", + "useKeyWithClickEvents": "error", + "useKeyWithMouseEvents": "error", + "useMediaCaption": "error", + "useSemanticElements": "error", + "useValidAnchor": "error", + "useValidAriaProps": "error", + "useValidAriaRole": "error", + "useValidAriaValues": "error", + "useValidAutocomplete": "error", + "useValidLang": "error" + }, + "complexity": { + "noAdjacentSpacesInRegex": "error", + "noArguments": "error", + "noBannedTypes": "error", + "noCommaOperator": "error", + "noEmptyTypeParameters": "error", + "noExtraBooleanCast": "error", + "noFlatMapIdentity": "error", + "noImportantStyles": "error", + "noStaticOnlyClass": "error", + "noThisInStatic": "error", + "noUselessCatch": "error", + "noUselessConstructor": "error", + "noUselessContinue": "error", + "noUselessEmptyExport": "error", + "noUselessEscapeInRegex": "error", + "noUselessFragments": "error", + "noUselessLabel": "error", + "noUselessLoneBlockStatements": "error", + "noUselessRename": "error", + "noUselessStringRaw": "error", + "noUselessSwitchCase": "error", + "noUselessTernary": "error", + "noUselessThisAlias": "error", + "noUselessTypeConstraint": "error", + "noUselessUndefinedInitialization": "error", + "useArrowFunction": "error", + "useDateNow": "error", + "useFlatMap": "error", + "useIndexOf": "error", + "useLiteralKeys": "error", + "useNumericLiterals": "error", + "useOptionalChain": "error", + "useRegexLiterals": "error", + "useSimpleNumberKeys": "error" + }, + "correctness": { + "noChildrenProp": "error", + "noConstAssign": "error", + "noConstantCondition": "error", + "noConstantMathMinMaxClamp": "error", + "noConstructorReturn": "error", + "noEmptyCharacterClassInRegex": "error", + "noEmptyPattern": "error", + "noGlobalObjectCalls": "error", + "noInnerDeclarations": "error", + "noInvalidBuiltinInstantiation": "error", + "noInvalidConstructorSuper": "error", + "noInvalidDirectionInLinearGradient": "error", + "noInvalidGridAreas": "error", + "noInvalidPositionAtImportRule": "error", + "noInvalidUseBeforeDeclaration": "error", + "noMissingVarFunction": "error", + "noNonoctalDecimalEscape": "error", + "noPrecisionLoss": "error", + "noPrivateImports": "error", + "noQwikUseVisibleTask": "error", + "noRenderReturnValue": "error", + "noSelfAssign": "error", + "noSetterReturn": "error", + "noStringCaseMismatch": "error", + "noSwitchDeclarations": "error", + "noUnknownFunction": "error", + "noUnknownMediaFeatureName": "error", + "noUnknownProperty": "error", + "noUnknownPseudoClass": "error", + "noUnknownPseudoElement": "error", + "noUnknownTypeSelector": "error", + "noUnknownUnit": "error", + "noUnmatchableAnbSelector": "error", + "noUnreachable": "error", + "noUnreachableSuper": "error", + "noUnsafeFinally": "error", + "noUnsafeOptionalChaining": "error", + "noUnusedFunctionParameters": "error", + "noUnusedImports": "error", + "noUnusedLabels": "error", + "noUnusedPrivateClassMembers": "error", + "noUnusedVariables": "error", + "noVoidElementsWithChildren": "error", + "noVoidTypeReturn": "error", + "noVueDataObjectDeclaration": "error", + "noVueDuplicateKeys": "error", + "noVueReservedKeys": "error", + "noVueReservedProps": "error", + "useExhaustiveDependencies": "error", + "useGraphqlNamedOperations": "error", + "useHookAtTopLevel": "error", + "useImageSize": "error", + "useIsNan": "error", + "useJsxKeyInIterable": "error", + "useParseIntRadix": "error", + "useQwikClasslist": "error", + "useQwikMethodUsage": "error", + "useQwikValidLexicalScope": "error", + "useValidForDirection": "error", + "useValidTypeof": "error", + "useYield": "error" + }, + "performance": { + "noAccumulatingSpread": "error", + "noDynamicNamespaceImportAccess": "error", + "noImgElement": "error", + "noUnwantedPolyfillio": "error", + "useGoogleFontPreconnect": "error" + }, + "security": { + "noBlankTarget": "error", + "noDangerouslySetInnerHtml": "error", + "noDangerouslySetInnerHtmlWithChildren": "error", + "noGlobalEval": "error" + }, + "style": { + "noDescendingSpecificity": "error", + "noHeadElement": "error", + "noNonNullAssertion": "error", + "useArrayLiterals": "error", + "useConst": "error", + "useDeprecatedReason": "error", + "useExponentiationOperator": "error", + "useExportType": "error", + "useImportType": "error", + "useLiteralEnumMembers": "error", + "useNodejsImportProtocol": "error", + "useShorthandFunctionType": "error", + "useTemplate": "error" + }, + "suspicious": { + "noApproximativeNumericConstant": "error", + "noArrayIndexKey": "error", + "noAssignInExpressions": "error", + "noAsyncPromiseExecutor": "error", + "noBiomeFirstException": "error", + "noCatchAssign": "error", + "noClassAssign": "error", + "noCommentText": "error", + "noCompareNegZero": "error", + "noConfusingLabels": "error", + "noConfusingVoidType": "error", + "noConstEnum": "error", + "noControlCharactersInRegex": "error", + "noDebugger": "error", + "noDocumentCookie": "error", + "noDocumentImportInPage": "error", + "noDoubleEquals": "error", + "noDuplicateAtImportRules": "error", + "noDuplicateCase": "error", + "noDuplicateClassMembers": "error", + "noDuplicateCustomProperties": "error", + "noDuplicateElseIf": "error", + "noDuplicateFields": "error", + "noDuplicateFontNames": "error", + "noDuplicateJsxProps": "error", + "noDuplicateObjectKeys": "error", + "noDuplicateParameters": "error", + "noDuplicateProperties": "error", + "noDuplicateSelectorsKeyframeBlock": "error", + "noDuplicateTestHooks": "error", + "noEmptyBlock": "error", + "noEmptyInterface": "error", + "noExplicitAny": "error", + "noExportsInTest": "error", + "noExtraNonNullAssertion": "error", + "noFallthroughSwitchClause": "error", + "noFocusedTests": "error", + "noFunctionAssign": "error", + "noGlobalAssign": "error", + "noGlobalIsFinite": "error", + "noGlobalIsNan": "error", + "noHeadImportInDocument": "error", + "noImplicitAnyLet": "error", + "noImportAssign": "error", + "noImportantInKeyframe": "error", + "noIrregularWhitespace": "error", + "noLabelVar": "error", + "noMisleadingCharacterClass": "error", + "noMisleadingInstantiator": "error", + "noMisrefactoredShorthandAssign": "error", + "noNonNullAssertedOptionalChain": "error", + "noOctalEscape": "error", + "noPrototypeBuiltins": "error", + "noQuickfixBiome": "error", + "noReactSpecificProps": "error", + "noRedeclare": "error", + "noRedundantUseStrict": "error", + "noSelfCompare": "error", + "noShadowRestrictedNames": "error", + "noShorthandPropertyOverrides": "error", + "noSparseArray": "error", + "noSuspiciousSemicolonInJsx": "error", + "noTemplateCurlyInString": "error", + "noThenProperty": "error", + "noTsIgnore": "error", + "noUnknownAtRules": "error", + "noUnsafeDeclarationMerging": "error", + "noUnsafeNegation": "error", + "noUselessEscapeInString": "error", + "noUselessRegexBackrefs": "error", + "noWith": "error", + "useAdjacentOverloadSignatures": "error", + "useBiomeIgnoreFolder": "error", + "useDefaultSwitchClauseLast": "error", + "useGetterReturn": "error", + "useGoogleFontDisplay": "error", + "useIsArray": "error", + "useIterableCallbackReturn": "error", + "useNamespaceKeyword": "error" + } + } + } +} diff --git a/composer.json b/composer.json index 162c50f..43b0d61 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "phpcompatibility/phpcompatibility-wp": "^2.1", "automattic/vipwpcs": "^3.0.1", "z4kn4fein/php-semver": "^3.0", - "rector/rector": "^2.6" + "rector/rector": "^2.6", + "slevomat/coding-standard": "^8.22.1" }, "scripts": { "phpcs": "phpcs --standard=phpcs-wordpress.xml", diff --git a/composer.lock b/composer.lock index a0ace75..a9fb409 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": "ce72259d2c2957f9a02b872aba4214b4", + "content-hash": "1e36270ecdafa8dec4c3e7bdd596039c", "packages": [], "packages-dev": [ { @@ -5876,6 +5876,71 @@ }, "time": "2025-09-30T22:22:48+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "8.22.1", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "1dd80bf3b93692bedb21a6623c496887fad05fec" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/1dd80bf3b93692bedb21a6623c496887fad05fec", + "reference": "1dd80bf3b93692bedb21a6623c496887fad05fec", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.1.2", + "php": "^7.4 || ^8.0", + "phpstan/phpdoc-parser": "^2.3.0", + "squizlabs/php_codesniffer": "^3.13.4" + }, + "require-dev": { + "phing/phing": "3.0.1|3.1.0", + "php-parallel-lint/php-parallel-lint": "1.4.0", + "phpstan/phpstan": "2.1.24", + "phpstan/phpstan-deprecation-rules": "2.0.3", + "phpstan/phpstan-phpunit": "2.0.7", + "phpstan/phpstan-strict-rules": "2.0.6", + "phpunit/phpunit": "9.6.8|10.5.48|11.4.4|11.5.36|12.3.10" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.22.1" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2025-09-13T08:53:30+00:00" + }, { "name": "spatie/array-to-xml", "version": "3.4.4", diff --git a/eslint.config.mjs b/eslint.config.mjs index 01f67c3..414d3b2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -65,9 +65,36 @@ const modernizationRules = Object.fromEntries( 'prefer-type-error', 'text-encoding-identifier-case', 'throw-new-error', + 'consistent-assert', + 'consistent-existence-index-check', + 'custom-error-definition', + 'error-message', + 'explicit-length-check', + 'import-style', + 'no-accessor-recursion', + 'no-array-callback-reference', + 'no-invalid-fetch-options', + 'no-invalid-remove-event-listener', + 'no-new-buffer', + 'no-object-as-default-parameter', + 'no-thenable', + 'prefer-math-min-max', + 'require-post-message-target-origin', ].map( ( rule ) => [ `unicorn/${ rule }`, 'error' ] ), ); +/* + * Codacy's "WordPress" standard also turns on these rules, which this file + * leaves out: + * - deprecated in ESLint, with a newer rule or no longer relevant: + * global-require, no-buffer-constructor, no-confusing-arrow, + * no-negated-in-lhs, no-new-symbol, no-path-concat, no-process-env, + * no-process-exit, no-return-await, no-sync. + * - against this code's style or reporting on code that is right as written: + * no-await-in-loop, no-continue, no-promise-executor-return, no-ternary, + * no-void, prefer-reflect, require-atomic-updates. + */ + export const ignores = { ignores: [ '.private/**', 'coverage/**', 'node_modules/**', 'vendor/**' ], }; @@ -98,6 +125,77 @@ export const projectConfigs = [ 'prefer-rest-params': 'error', 'prefer-spread': 'error', 'prefer-template': 'error', + // Checks that Codacy's "WordPress" standard also runs; each passes on this code. + 'for-direction': 'error', + 'getter-return': 'error', + 'no-async-promise-executor': 'error', + 'no-case-declarations': 'error', + 'no-class-assign': 'error', + 'no-compare-neg-zero': 'error', + 'no-constant-binary-expression': 'error', + 'no-constant-condition': 'error', + 'no-constructor-return': 'error', + 'no-control-regex': 'error', + 'no-delete-var': 'error', + 'no-dupe-else-if': 'error', + 'no-empty': 'error', + 'no-empty-character-class': 'error', + 'no-empty-function': 'error', + 'no-empty-pattern': 'error', + 'no-empty-static-block': 'error', + 'no-ex-assign': 'error', + 'no-extra-bind': 'error', + 'no-extra-boolean-cast': 'error', + 'no-func-assign': 'error', + 'no-global-assign': 'error', + 'no-import-assign': 'error', + 'no-inner-declarations': [ 'error', 'functions' ], + 'no-invalid-regexp': 'error', + 'no-invalid-this': 'error', + 'no-iterator': 'error', + 'no-label-var': 'error', + 'no-loop-func': 'error', + 'no-loss-of-precision': 'error', + 'no-misleading-character-class': 'error', + 'no-new-native-nonconstructor': 'error', + 'no-nonoctal-decimal-escape': 'error', + 'no-obj-calls': 'error', + 'no-object-constructor': 'error', + 'no-octal': 'error', + 'no-octal-escape': 'error', + 'no-param-reassign': 'error', + 'no-proto': 'error', + 'no-prototype-builtins': 'error', + 'no-regex-spaces': 'error', + 'no-return-assign': [ 'error', 'always' ], + 'no-script-url': 'error', + 'no-self-assign': 'error', + 'no-self-compare': 'error', + 'no-setter-return': 'error', + 'no-shadow-restricted-names': 'error', + 'no-sparse-arrays': 'error', + 'no-template-curly-in-string': 'error', + 'no-this-before-super': 'error', + 'no-throw-literal': 'error', + 'no-underscore-dangle': 'error', + 'no-unexpected-multiline': 'error', + 'no-unmodified-loop-condition': 'error', + 'no-unneeded-ternary': 'error', + 'no-unreachable-loop': 'error', + 'no-unsafe-finally': 'error', + 'no-unsafe-optional-chaining': 'error', + 'no-unused-labels': 'error', + 'no-unused-private-class-members': 'error', + 'no-use-before-define': 'error', + 'no-useless-assignment': 'error', + 'no-useless-backreference': 'error', + 'no-useless-call': 'error', + 'no-useless-catch': 'error', + 'no-useless-escape': 'error', + 'no-useless-rename': 'error', + 'no-warning-comments': 'error', + 'require-yield': 'error', + 'use-isnan': 'error', }, }, { diff --git a/package-lock.json b/package-lock.json index 4fa59d5..c979145 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "optimizations-ace-mc", "license": "GPL-3.0-or-later", "devDependencies": { + "@biomejs/biome": "2.5.14", "@wordpress/browserslist-config": "7.2.0", "@wordpress/eslint-plugin": "28.2.0", "@wordpress/stylelint-config": "27.1.0", @@ -295,6 +296,181 @@ "node": ">=6.9.0" } }, + "node_modules/@biomejs/biome": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-2.5.14.tgz", + "integrity": "sha512-0FabLIjd4M/dm8VFI86RMaLLdgepzbdfiAL2R8cr7V81OYYrP1w7Z73KfAwPK5h9SrEBXTzNG2y+mBwPo9xRnw==", + "dev": true, + "license": "MIT OR Apache-2.0", + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "2.5.14", + "@biomejs/cli-darwin-x64": "2.5.14", + "@biomejs/cli-linux-arm64": "2.5.14", + "@biomejs/cli-linux-arm64-musl": "2.5.14", + "@biomejs/cli-linux-x64": "2.5.14", + "@biomejs/cli-linux-x64-musl": "2.5.14", + "@biomejs/cli-win32-arm64": "2.5.14", + "@biomejs/cli-win32-x64": "2.5.14" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.5.14.tgz", + "integrity": "sha512-UnzaXO65L4tsZimFITFP2M121GyhDcWFrT3pL5ZJ5U4XcS/0L5VHYytVohdCf/gnDUFHgl2I9xnt5bV/J1kxHQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.5.14.tgz", + "integrity": "sha512-kiy8qA16K93J7uvFfWi4LgjqDpnRKyePAna6A0Y4jxyUga35SYpIZ2cNWlhy0lsfgqRenCpfymnJWEZ6mgpRgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.5.14.tgz", + "integrity": "sha512-vO/9BaU1n30CiFNLx49gMTMtbCAAqlo/EqFoG0BU3deQInTbJrmXSmTQ9e3FoDZIKQnvSLDVNL4lx1ci7y1T1Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.5.14.tgz", + "integrity": "sha512-SJ9PrZkBnnH9dHJDnxk34vKs0GB2dbsioaft6/hPhWJ7AHpwYH83Isnhj0FSRpFkGgpVfJ1lds23ApB2czUDLQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-2.5.14.tgz", + "integrity": "sha512-VHZRa7CCQBUWKxNwUvHJeuW03WFRgN5NWO//SDGOitc9QIeNyfA42V9zlKm+x82xFSG9Bzi5fi+hbhm9anO8yA==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.5.14.tgz", + "integrity": "sha512-2kI5PrMgW5dcEZYrstLPmUmCwkUwZY39rP4BN93Vxbwcs2O57LDQOktUZZYPvvspN5i0mhGr3TJtF5sU26NUWg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.5.14.tgz", + "integrity": "sha512-pHgAFffmZtaYoxavEsWEYNvcA7NwOIjLyqw2HXyLbt16xYryX0L4fMV2u0G9ag6LNYPIoqWaWqzUcnc6rLGGXg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "2.5.14", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-2.5.14.tgz", + "integrity": "sha512-oJWmBhoHsnhUKIke+0gXDX0mltJrWHA1UyHsrTlXwX0TL64ilVZAo+TYZm97baecV0esBdpzy3k96q+09JaZUQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, "node_modules/@cacheable/memory": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@cacheable/memory/-/memory-2.2.0.tgz", diff --git a/package.json b/package.json index f126ac7..8994302 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,13 @@ }, "scripts": { "lint:css": "stylelint --config stylelint-wordpress.json \"assets/css/**/*.css\"", + "lint:biome": "biome lint .", "lint:js": "eslint --config eslint.wordpress.config.mjs --max-warnings 0 .", "lint:md": "markdownlint-cli2", "test": "node --test \"tests/js/**/*.test.mjs\"" }, "devDependencies": { + "@biomejs/biome": "2.5.14", "@wordpress/browserslist-config": "7.2.0", "@wordpress/eslint-plugin": "28.2.0", "@wordpress/stylelint-config": "27.1.0", diff --git a/phpcs-wordpress.xml b/phpcs-wordpress.xml index 57b0c2b..d8db5f5 100644 --- a/phpcs-wordpress.xml +++ b/phpcs-wordpress.xml @@ -194,6 +194,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpcs.xml b/phpcs.xml index fe0fa40..7fc7ae6 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -100,8 +100,10 @@ 0 + + @@ -129,6 +131,7 @@ + 5 @@ -147,6 +150,7 @@ + @@ -178,6 +182,7 @@ + 0 @@ -192,6 +197,7 @@ 5 warning + @@ -199,8 +205,14 @@ + + + + + + 0 @@ -210,6 +222,8 @@ 5 + + @@ -256,6 +270,18 @@ 5 + + + + + + + + + + + + 5 @@ -433,6 +459,7 @@ 5 + @@ -454,6 +481,7 @@ 5 + diff --git a/stylelint-wordpress.json b/stylelint-wordpress.json index e8eaf83..d3a9cc7 100644 --- a/stylelint-wordpress.json +++ b/stylelint-wordpress.json @@ -1,7 +1,78 @@ { "extends": "@wordpress/stylelint-config", - "plugins": ["stylelint-no-unsupported-browser-features"], + "plugins": [ + "stylelint-no-unsupported-browser-features" + ], "rules": { - "plugin/no-unsupported-browser-features": [true, { "severity": "error" }] + "plugin/no-unsupported-browser-features": [ + true, + { + "severity": "error" + } + ], + "alpha-value-notation": [ + "percentage", + { + "exceptProperties": [ + "opacity", + "fill-opacity", + "flood-opacity", + "stop-opacity", + "stroke-opacity" + ] + } + ], + "at-rule-no-vendor-prefix": true, + "color-function-notation": "modern", + "comment-whitespace-inside": "always", + "custom-media-pattern": "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$", + "custom-property-empty-line-before": [ + "always", + { + "except": [ + "after-custom-property", + "first-nested" + ], + "ignore": [ + "after-comment", + "inside-single-line-block" + ] + } + ], + "declaration-block-no-redundant-longhand-properties": true, + "declaration-block-single-line-max-declarations": 1, + "declaration-empty-line-before": [ + "always", + { + "except": [ + "after-declaration", + "first-nested" + ], + "ignore": [ + "after-comment", + "inside-single-line-block" + ] + } + ], + "hue-degree-notation": "angle", + "import-notation": "url", + "keyframe-selector-notation": "percentage-unless-within-keyword-only-block", + "keyframes-name-pattern": "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$", + "media-feature-name-no-vendor-prefix": true, + "media-feature-range-notation": "context", + "number-max-precision": 4, + "property-no-vendor-prefix": true, + "selector-no-vendor-prefix": true, + "selector-not-notation": "complex", + "shorthand-property-no-redundant-values": true, + "value-no-vendor-prefix": [ + true, + { + "ignoreValues": [ + "box", + "inline-box" + ] + } + ] } }