{"id":19045489,"url":"https://github.com/yoast/yoastcs","last_synced_at":"2025-04-15T14:58:06.608Z","repository":{"id":27173885,"uuid":"30643578","full_name":"Yoast/yoastcs","owner":"Yoast","description":"Yoast coding standards","archived":false,"fork":false,"pushed_at":"2025-03-19T11:53:37.000Z","size":1129,"stargazers_count":21,"open_issues_count":16,"forks_count":3,"subscribers_count":16,"default_branch":"develop","last_synced_at":"2025-04-15T14:57:58.323Z","etag":null,"topics":["coding-standards","mess-detector","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yoast.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-11T10:54:20.000Z","updated_at":"2025-03-19T11:49:53.000Z","dependencies_parsed_at":"2024-06-18T17:11:09.637Z","dependency_job_id":null,"html_url":"https://github.com/Yoast/yoastcs","commit_stats":{"total_commits":346,"total_committers":9,"mean_commits":38.44444444444444,"dds":"0.21965317919075145","last_synced_commit":"866ede2824d151725a185c1e3b2a5c8ee9ecf182"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yoast%2Fyoastcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yoast%2Fyoastcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yoast%2Fyoastcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yoast%2Fyoastcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yoast","download_url":"https://codeload.github.com/Yoast/yoastcs/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094938,"owners_count":21211836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coding-standards","mess-detector","php"],"created_at":"2024-11-08T22:50:23.242Z","updated_at":"2025-04-15T14:58:06.587Z","avatar_url":"https://github.com/Yoast.png","language":"PHP","readme":"# Yoast Coding Standards\n\n[![Coverage Status](https://coveralls.io/repos/github/Yoast/yoastcs/badge.svg?branch=develop)](https://coveralls.io/github/Yoast/yoastcs?branch=develop)\n\nYoast Coding Standards (YoastCS) is a project with rulesets for code style and quality tools to be used in Yoast projects.\n\n## Installation\n\n### Standalone\n\nStandards are provided as a [Composer](https://getcomposer.org/) package and can be installed with:\n\n```bash\ncomposer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true\ncomposer global require --dev yoast/yoastcs:\"^3.0\"\n```\n\n### As dependency\n\nTo include standards as part of a project require them as development dependencies:\n\n```bash\ncomposer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true\ncomposer require --dev yoast/yoastcs:\"^3.0\"\n```\n\nComposer will automatically install dependencies and register YoastCS and other external standards with PHP_CodeSniffer.\n\n## Tools provided via YoastCS\n\n* PHP Parallel Lint\n* PHP_CodeSniffer and select standards for PHP_CodeSniffer, including a number of Yoast native sniffs.\n\n\n## PHP Parallel Lint\n\n[PHP Parallel Lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint/) is a tool to lint PHP files against parse errors.\n\nPHP Parallel Lint does not use a configuration file, so [command-line options](https://github.com/php-parallel-lint/PHP-Parallel-Lint/#command-line-options) need to be passed to configure what files to scan.\n\nIt is best practice within the Yoast projects, to add a script to the `composer.json` file which encapsules the command with the appropriate command-line options to ensure that running the tool will yield the same results each time.\n\nTypically, (a variation on) the following snippet would be added to the `composer.json` file for a project:\n```json\n    \"scripts\" : {\n        \"lint\": [\n            \"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git\"\n        ]\n    }\n```\n\n\n## PHP Code Sniffer\n\nSet of [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) rules.\n\nSeverity levels:\n\n - error level issues are considered mandatory to fix in Yoast projects and enforced in continuous integration\n - warning level issues are considered recommended to fix\n\n### The YoastCS Standard\n\nThe `Yoast` standard for PHP_CodeSniffer is comprised of the following:\n* The `WordPress` ruleset from the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards) implementing the official [WordPress PHP Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/), with some [select exclusions](https://github.com/Yoast/yoastcs/blob/develop/Yoast/ruleset.xml#L29-L75).\n* The [`PHPCompatibilityWP`](https://github.com/PHPCompatibility/PHPCompatibilityWP) ruleset which checks code for PHP cross-version compatibility while preventing false positives for functionality polyfilled within WordPress.\n* The [`VariableAnalysis`](https://github.com/sirbrillig/phpcs-variable-analysis/) ruleset.\n* Select additional sniffs taken from [`PHP_CodeSniffer`](https://github.com/PHPCSStandards/PHP_CodeSniffer).\n* Select additional sniffs taken from [`PHPCSExtra`](https://github.com/PHPCSStandards/PHPCSExtra).\n* Select additional sniffs taken from [`SlevomatCodingStandard`](https://github.com/slevomat/coding-standard).\n* Select additional sniffs taken from [WordPress VIP Coding Standards](https://github.com/Automattic/VIP-Coding-Standards/).\n* A number of custom Yoast specific sniffs.\n\nFiles within version management and dependency related directories, such as the Composer `vendor` directory, are excluded from the scans by default.\n\n#### Sniffs\n\nTo obtain a list of all sniffs used within YoastCS:\n```bash\n\"vendor/bin/phpcs\" -e --standard=Yoast\n```\n\n#### Sniff Documentation\n\nNot all sniffs have documentation available about what they sniff for, but for those which do, this documentation can be viewed from the command-line:\n```bash\n\"vendor/bin/phpcs\" --standard=Yoast --generator=Text\n```\n\n### Running the sniffs\n\n#### Command line\n\n```bash\n\"vendor/bin/phpcs\" --extensions=php /path/to/folder/\n```\n\nFor more command-line options, please have a read through the [PHP_CodeSniffer documentation](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Usage).\n\n#### Yoast plugin repositories\n\nAll Yoast plugin repositories contain a `[.]phpcs.xml.dist` file which contains the repository specific configuration.\n\nFrom the root of these repositories, you can run PHPCS by using:\n```bash\ncomposer check-cs-warnings\n```\n\n#### PhpStorm\n\nRefer to [Using PHP Code Sniffer Tool](https://www.jetbrains.com/phpstorm/help/using-php-code-sniffer-tool.html) in the PhpStorm documentation.\n\nAfter installation, the `Yoast` standard will be available as a choice in PHP Code Sniffer Validation inspection.\n\n### The YoastCS \"Threshold\" report\n\nThe YoastCS package includes a custom `YoastCS\\Yoast\\Reports\\Threshold` report for PHP_CodeSniffer to compare the current PHPCS run results with predefined \"threshold\" settings.\n\nThe report will look in the runtime environment for the following two environment variables and will take the values of those as the thresholds to compare the PHPCS run results against:\n* `YOASTCS_THRESHOLD_ERRORS`\n* `YOASTCS_THRESHOLD_WARNINGS`\n\nIf the environment variables are not set, they will default to 0 for both, i.e. no errors or warnings allowed.\n\nThe report will not print any details about the issues found, it just shows a summary based on the thresholds:\n```\nPHP CODE SNIFFER THRESHOLD COMPARISON\n------------------------------------------------------------------------------------------------------------------------\nCoding standards ERRORS: 148/130.\nCoding standards WARNINGS: 539/539.\n\nPlease fix any errors introduced in your code and run PHPCS again to verify.\nPlease fix any warnings introduced in your code and run PHPCS again to verify.\n```\n\nAfter the report has run, a global `YOASTCS_ABOVE_THRESHOLD` constant (boolean) will be available which can be used in calling scripts.\n\nTo use this report, run PHPCS with the following command-line argument: `--report=YoastCS\\Yoast\\Reports\\Threshold`.\n_Note: depending on the OS the command is run on, the backslashes in the report name may need to be escaped (doubled)._\n\nFor those Yoast plugin repositories which use thresholds, the status can be checked locally by running:\n```bash\ncomposer check-cs-thresholds\n```\n\n## Changelog\n\nThe changelog for this package can be found in the [CHANGELOG.md](https://github.com/Yoast/yoastcs/blob/develop/CHANGELOG.md) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoast%2Fyoastcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoast%2Fyoastcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoast%2Fyoastcs/lists"}