Skip to content

Template for use with pull request on custom code standard projects

jrfnl edited this page Sep 10, 2024 · 3 revisions

Introduction

To gain more widespread support for PHP_CodeSniffer installers, it is important that maintainers of external PHP_CodeSniffer standards adopt using the "type" : "phpcodesniffer-standard" in their project's composer.json.

Opening an issue (or even better: a pull-request) for such a change is trivial. Finding the right words to explain the rationale can be more daunting.

Below is a template that can be used ad-verbatim to accompany any issue or pull-request to add (or change) the "type" : "phpcodesniffer-standard" in a project's Composer file.

The template

The text below can be selected and copied as-is:

## Problem/Motivation

Composer allows declaring [a package's type][composer-package-type]. When no type is declared, the default is "library".

There is a [composer plugin][composer-plugin] that can install custom PHP_CodeSniffer standards: https://github.com/PHPCSStandards/composer-installer

This plugin is part of the [PHPCSStandards][php-cs-standards] organisation, which is the new official home of [PHP_CodeSniffer][php-codesniffer]

For this installer to work, the package type needs to be set to `phpcodesniffer-standard`.

There are already [a lot of packages][phpcodesniffer-packages] that adhere to this type.

## Proposed changes

Adding the following line to the `composer.json` will make it possible for the Composer plugin to install this custom code-standard using composer:

```json
    "type" : "phpcodesniffer-standard"
```

This will in _no way_ change the existing behavior of this package for users that do not include the Composer plugin mentioned above in their projects `composer.json`.

[composer-package-type]: https://getcomposer.org/doc/04-schema.md#type
[composer-plugin]: https://getcomposer.org/doc/articles/plugins.md
[phpcodesniffer-packages]: https://github.com/search?p=2&q=filename%3Acomposer.json+type+phpcodesniffer+standard&type=Code&utf8=%E2%9C%93
[php-cs-standards]: https://github.com/PHPCSStandards/
[php-codesniffer]: https://github.com/PHPCSStandards/PHP_CodeSniffer

Rendering example

The template above will render (more or less) like this:

Problem/Motivation

Composer allows declaring a package's type. When no type is declared, the default is "library".

There is a composer plugin that can install custom PHP_CodeSniffer standards: https://github.com/PHPCSStandards/composer-installer

This plugin is part of the PHPCSStandards organisation, which is the new official home of PHP_CodeSniffer

For this installer to work, the package type needs to be set to phpcodesniffer-standard.

There are already a lot of packages that adhere to this type.

Proposed changes

Adding the following line to the composer.json will make it possible for the Composer plugin to install this custom code-standard using composer:

    "type" : "phpcodesniffer-standard"

This will in no way change the existing behavior of this package for users that do not include Composer plugin mentioned above in their projects composer.json.

Copyright of this template

CC0
To the extent possible under law, Dealerdirect and PHPCSStandards have waived all copyright and related or neighboring rights to this "Template for use with pull-request on custom PHP_Codesniffer code-standard projects".