Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.

Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement: the maintainer, privately through GitHub ([@pekral](https://github.com/pekral)). All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of actions.

**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
79 changes: 79 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Contributing

This package ships **no sniffs of its own**. [`ruleset.xml`](../ruleset.xml) selects and configures sniffs that
[Slevomat Coding Standard](https://github.com/slevomat/coding-standard) already provides. Almost every
contribution is therefore a decision about a single sniff — enable it, exclude it, change its settings, or skip
it for certain paths.

## How the repository is laid out

| Path | Role |
| --- | --- |
| [`ruleset.xml`](../ruleset.xml) | The ruleset that ships. A sniff is either enabled with `<rule ref="…">` or listed with `<exclude name="…">`. |
| [`docs/rules.md`](../docs/rules.md) | Every rule the ruleset enables, with key settings and path exclusions. |
| `Examples/` | Sample code for each rule group. `composer check` runs the ruleset against it. |
| `src/`, `build.php` | Build tooling for `composer check-unused-sniffs`. Not used by the ruleset. |
| `tests/` | PHPUnit tests for the build tooling. |

`composer check-unused-sniffs` walks `vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/`,
collects every Slevomat sniff, and fails if a sniff appears in `ruleset.xml` neither as a `<rule ref>` nor as an
`<exclude name>`.

That guard is the point of the setup: when Slevomat releases new sniffs, CI fails until someone decides about
each one. Nothing is silently skipped.

## Proposing a change

Open an issue first. For a new rule, use the
[New PHPCS Rule Proposal](https://github.com/pekral/phpcs-rules/issues/new?template=new-rule.yml) template.
For a rule that misbehaves, use the
[Bug report](https://github.com/pekral/phpcs-rules/issues/new?template=bug_report.yml) template.

A sniff that crashes or reports correct code as wrong is usually a bug in
[Slevomat Coding Standard itself](https://github.com/slevomat/coding-standard/issues). This repository only
chooses which sniffs run and how they are configured.

## Development setup

```bash
composer install
```

`composer.json` requires PHP `^8.4`. CI runs every check on PHP 8.4 and 8.5.

| Command | What it does |
| --- | --- |
| `composer test` | PHPUnit |
| `composer test:coverage` | PHPUnit with an HTML coverage report in `coverage-report/` |
| `composer check` | PHPCS with this ruleset on `Examples/`, `src/` and `tests/` |
| `composer check-unused-sniffs` | Report Slevomat sniffs that `ruleset.xml` neither enables nor excludes |
| `composer phpstan` | PHPStan on `src/` at level `max` |
| `composer rector` | Rector dry run on `src/` and `tests/` |
| `composer fix` | Apply Rector on `src/` and `tests/`, then `phpcbf` on `Examples/`, `src/` and `tests/` |
| `composer build` | Installs the [pekral/cursor-rules](https://github.com/pekral/cursor-rules) agent rules for Claude, then runs `fix`, `rector`, `check`, `check-unused-sniffs`, `phpstan`, `test`, and `git gone` |

`composer fix` and `composer build` rewrite files in `Examples/`, `src/` and `tests/` in place.

### CI

Pull requests and pushes to `master` run `composer test`, `composer check`, `composer phpstan`,
`composer rector`, and `composer check-unused-sniffs` on PHP 8.4 and 8.5. A scheduled workflow runs
`composer update` every Sunday and opens a pull request when dependencies change; Dependabot also checks
Composer dependencies weekly.

## Pull requests

1. Change `ruleset.xml`: enable the sniff with `<rule ref="…">`, or list it with `<exclude name="…">`.
2. Add or update the matching file in `Examples/`, and the rule's row in `docs/rules.md`.
3. Run `composer build` and make it pass.
4. Add an entry to `CHANGELOG.md` under `## [Unreleased]`.
5. Use [Conventional Commits](https://www.conventionalcommits.org/) — `feat:`, `fix:`, `docs:`, `chore:`.
Commit subjects are written in English.
6. Open the pull request against `master`.

Enabling, excluding, or reconfiguring a sniff changes what PHPCS reports in every project that uses this
ruleset. Say so in the pull request description, so the release notes can carry it.

## Reporting a security issue

Do not open a public issue. See [SECURITY.md](SECURITY.md).
65 changes: 65 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Bug report
description: Report a rule in the ruleset that reports or fixes code incorrectly
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
This package ships no sniffs of its own — `ruleset.xml` selects and configures sniffs from
Slevomat Coding Standard. Open this issue when a rule should be configured, excluded, or skipped for
certain paths **for everyone**. You can always override a rule in your own `ruleset.xml`.

A sniff that crashes, or reports correct code as wrong regardless of configuration, is a bug in
[Slevomat Coding Standard itself](https://github.com/slevomat/coding-standard/issues). Report it there.

- type: input
id: rule
attributes:
label: Rule
description: The sniff code from the PHPCS report.
placeholder: SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys
validations:
required: true

- type: textarea
id: code
attributes:
label: Code
description: The smallest piece of code that reproduces the problem.
render: php
validations:
required: true

- type: textarea
id: actual
attributes:
label: Actual behavior
description: What PHPCS reported, or what `phpcbf` changed.
render: shell
validations:
required: true

- type: textarea
id: expected
attributes:
label: Expected behavior
description: What you expected instead, and why.
validations:
required: true

- type: input
id: command
attributes:
label: Exact command you ran
placeholder: "vendor/bin/phpcs --standard=vendor/pekral/phpcs-rules/ruleset.xml src/"
validations:
required: true

- type: input
id: versions
attributes:
label: Versions
placeholder: "pekral/phpcs-rules 0.5.0, slevomat/coding-standard 8.x, PHP 8.4.x"
validations:
required: true
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: Report a security vulnerability
url: https://github.com/pekral/phpcs-rules/security/advisories/new
about: Please report security vulnerabilities privately instead of opening a public issue — see SECURITY.md.
- name: Bug in Slevomat Coding Standard itself
url: https://github.com/slevomat/coding-standard/issues
about: A sniff that crashes or misreports code regardless of configuration is an upstream bug. This repository only selects and configures which sniffs run.
39 changes: 39 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Security Policy

## What this package is

The package a project installs is a PHP_CodeSniffer standard: `ruleset.xml` selects and configures sniffs that
[Slevomat Coding Standard](https://github.com/slevomat/coding-standard) already provides. It ships no sniffs of
its own. The code under `src/` is the build tooling behind `composer check-unused-sniffs`; the ruleset does not
use it. The package is installed with `--dev` and is meant to run in development and CI, not in production.

That shape bounds what a vulnerability here could be. The realistic cases are a malicious change to
`ruleset.xml` (for example a rule reference or setting that makes PHPCS load something it should not), or a
compromised release of one of the two runtime dependencies, `slevomat/coding-standard` and
`dealerdirect/phpcodesniffer-composer-installer`.

## Supported versions

Fixes go into the latest release. Older tags are not patched.

## Reporting a vulnerability

Report privately through GitHub's
[**Report a vulnerability**](https://github.com/pekral/phpcs-rules/security/advisories/new) form, which opens
an advisory visible only to the maintainer.

Include the affected version and the steps to reproduce.

**Do not open a public issue for a vulnerability.** This is a single-maintainer project, so a public report
gives every consumer an exploit before there is a fix.

## Out of scope

- **A vulnerability in a sniff** belongs to
[Slevomat Coding Standard](https://github.com/slevomat/coding-standard) or
[PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). This repository only selects which sniffs
run and how they are configured.
- **A rule that reports or fixes your code incorrectly** is not a vulnerability. Open a regular issue, or report
it upstream if the sniff itself is wrong.
- **Development dependencies** (PHPUnit, PHPStan, Rector, and the rest of `require-dev`) are not installed in
projects that require this package.
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## What does this change?

<!-- One or two sentences. Link the issue it resolves: Closes #123 -->

## Rule changes

<!-- Delete this section if the pull request touches no rule. -->

| Sniff | Change in `ruleset.xml` | Reason |
| --- | --- | --- |
| | enabled / excluded / settings / path exclusion | |

## Checklist

- [ ] `composer build` passes.
- [ ] Every Slevomat sniff is either enabled or excluded in `ruleset.xml` (`composer check-unused-sniffs`).
- [ ] `Examples/` and `docs/rules.md` reflect the rule change, if any.
- [ ] A changelog entry was added to `CHANGELOG.md` under `## [Unreleased]`.
- [ ] The commit subject follows Conventional Commits and is written in English.
- [ ] The description says what PHPCS will now report differently in consuming projects, if anything.
Loading