Skip to content

Expand Coding Standard Tutorial to show how to write a fixer for a sniff #12

@rodrigoprimo

Description

@rodrigoprimo

The Coding Standard Tutorial page, among other things, teaches sniff developers how to create a sniff. I would like to suggest that we expand this section of the page to show how to create a sniff that can fix the violations automatically.

IMO, the sniff used as an example on that page, DisallowHashCommentsSniff.php, could be expanded to include the fixer code. I would also suggest a separate section detailing the main methods to use when creating a fixer.

If this is approved, I can work on this change to the documentation, but only in a few weeks from now. I don't mind if someone else claims this issue. I will make sure to leave a comment here when I start working on it.

Activity

jrfnl

jrfnl commented on Aug 30, 2024

@jrfnl
Member

Happy to accept such additions.

Text for this can be posted in a comment here (as the wiki is not publicly editable) and added to the wiki by an editor once reviewed and approved.

I would also suggest a separate section detailing the main methods to use when creating a fixer.

Regarding the methods available: when I first started working with the fixer, I used the phpDoc generated docs published on the PEAR website as a reference: https://pear.php.net/package/PHP_CodeSniffer/docs/3.5.2/apidoc/PHP_CodeSniffer/Fixer.html
Those haven't been updated for a while (and the generation for the last dozen versions released via PEAR was broken already), but not that much has changed in the Fixer class, so the info there should still be a good basis for the method reference.

Mind: while the methods are all public, some of them probably shouldn't have been and are intended only for internal use, so I don't think all methods need to be documented, only the typical public API.

jrfnl

jrfnl commented on Jul 14, 2025

@jrfnl
Member

This issue can now be addressed via a PR to this repo (though please wait a few days as I have a lot of "clean up" commits lined up and I would like to prevent merge conflicts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rodrigoprimo@jrfnl

        Issue actions

          Expand Coding Standard Tutorial to show how to write a fixer for a sniff · Issue #12 · PHPCSStandards/PHP_CodeSniffer-documentation