|
| 1 | +# Contributing to the PHP_CodeSniffer documentation |
| 2 | + |
| 3 | +## PHP_CodeSniffer Wiki |
| 4 | + |
| 5 | +For now, the documentation for the PHP_CodeSniffer project is available via the [project Wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki). |
| 6 | + |
| 7 | +### How does the wiki get updated ? |
| 8 | + |
| 9 | +* The source of the Wiki was imported into this repository to maintain the commit history. |
| 10 | +* A [GitHub Actions workflow](https://github.com/PHPCSStandards/PHP_CodeSniffer-documentation/blob/main/.github/workflows/publish-wiki.yml) was added to automatically push changes made in the Wiki files in this repository to the upstream Wiki repo. |
| 11 | +* Prior to pushing the changes, the workflow will pre-process the files and make the following changes: |
| 12 | + * Replace `{{COMMAND-OUTPUT ...}}` command-line output placeholders with actual command-line output from either `phpcs` or `phpcbf`. |
| 13 | + The code samples used for generating some of this output can be found in the `build/wiki/code-samples` directory. |
| 14 | + * Replace `<!-- START doctoc --> <!-- END doctoc -->` placeholders with a Table of Contents for the page in Markdown. |
| 15 | + * Add a prominent (hidden) warning at the top of each wiki file to warn people against editing the wiki files via the GitHub wiki editing interface. |
| 16 | + |
| 17 | + |
| 18 | +### Contributing to the Wiki |
| 19 | + |
| 20 | +If you would like to improve the documentation: |
| 21 | +1. Fork this repository. |
| 22 | +2. Create a new branch off the `main` branch. |
| 23 | +3. Make your changes. The Wiki source files are in the `/wiki` subdirectory. |
| 24 | +4. Commit your changes with a meaningful commit message. |
| 25 | +5. Push your changes to your fork. |
| 26 | +6. Submit a pull request from your fork to this repository. |
| 27 | +7. Please ensure your pull requests passes all automated quality checks. |
| 28 | +8. If you updated anything which will be auto-replaced via the preprocessing: |
| 29 | + * The GitHub Actions workflow will do a "dry-run" for every PR (pre-process only, no push to the wiki). |
| 30 | + * Please download the artifact which was created via this dry-run and verify the preprocessing replaced the output in the way you expected. |
| 31 | + |
| 32 | +When in doubt, open an issue first to discuss your change proposal. |
| 33 | + |
| 34 | + |
| 35 | +### Guidelines for updating the wiki files |
| 36 | + |
| 37 | +* Small PRs fixing only one thing will be better received than larger PRs fixing a lot of things in one go. |
| 38 | +* Always use fully qualified links. This ensures that the links will work when pages are viewed/edited in this repo, as well as when the pages are viewed from the PHPCS wiki. |
| 39 | +* Add table of contents markers if appropriate. |
| 40 | + The start of a page containing a table of contents should look like this: |
| 41 | + ```md |
| 42 | + ## Table of contents |
| 43 | + |
| 44 | + <!-- START doctoc --> |
| 45 | + <!-- END doctoc --> |
| 46 | + |
| 47 | + *** |
| 48 | + |
| 49 | + ... the actual page ... |
| 50 | + ``` |
| 51 | +* Regarding command replacement markers ... |
| 52 | + * A marker MUST look like `{{COMMAND-OUTPUT ...}}` with `...` being replacement with a quoted `phpcs` or `phpcbf` command. |
| 53 | + * A marker MUST be at the start of a line. |
| 54 | + * A marker MUST be on a line by itself. |
| 55 | + * Commands will be run from the project root directory. Keep this in mind when adding a command replacement marker to a wiki file. |
| 56 | +* The command replacement will not add markdown code fence syntax, so make sure to do this yourself. |
| 57 | +* If a code sample is needed to generate the desired output, place the code sample in a file in the `build/wiki-code-samples` directory. |
| 58 | + |
| 59 | + |
| 60 | +#### Running the pre-processing locally |
| 61 | + |
| 62 | +As noted above, you don't _need_ to run the pre-processing locally, a dry-run will be done via GitHub Actions for each PR. |
| 63 | +However, if you are making extensive changes, you may still want to test things locally before submitting your PR. |
| 64 | + |
| 65 | +> [!IMPORTANT] |
| 66 | +> Run the bash script first, only run the TOC replacement after. |
| 67 | + |
| 68 | +The bash script used for the command replacements can be run locally from the project root directory by invoking: |
| 69 | + |
| 70 | +```bash |
| 71 | +build/wiki-command-replacer.sh |
| 72 | +``` |
| 73 | + |
| 74 | +Notes: |
| 75 | +* For the bash script to succeed, the `phpcs` and `phpcbf` commands need to be available in the `PATH` for your OS. |
| 76 | +* The bash script will copy the wiki files to the `_wiki` directory before making any replacements to prevent anyone accidentally committing the processed files. |
| 77 | + |
| 78 | +The table of contents generation can be tested locally by installing the `doctoc` tool and running this locally like so: |
| 79 | + |
| 80 | +```bash |
| 81 | +npm install -g doctoc |
| 82 | +doctoc ./_wiki/ --github --maxlevel 4 --update-only |
| 83 | +doctoc ./_wiki/Version-4.0-User-Upgrade-Guide.md --github --maxlevel 3 --update-only |
| 84 | +``` |
| 85 | + |
| 86 | +Note that this presumes the command replacer has already run and the files have already been copied to the `_wiki` directory. |
| 87 | + |
| 88 | +If you only want to test the TOC generation, make sure you copy the wiki files to the `_wiki` directory before running these commands. |
| 89 | + |
| 90 | + |
| 91 | +#### Running code quality checks locally |
| 92 | + |
| 93 | +All used code quality checks can be run locally. |
| 94 | +Configuration files have been committed to the repository to ensure you will locally get the same results as when the tooling runs in CI. |
| 95 | + |
| 96 | +To run the quality checks locally, install the following tooling: |
| 97 | +* [Yamllint](https://github.com/adrienverge/yamllint) |
| 98 | + * [Installation instructions](https://yamllint.readthedocs.io/en/stable/quickstart.html) |
| 99 | + * Run it like so: `yamllint . --format colored --strict --list-files` |
| 100 | +* [Actionlint](https://github.com/rhysd/actionlint) |
| 101 | + * [Installation instructions](https://github.com/rhysd/actionlint/blob/main/docs/install.md) |
| 102 | + * Run it like so: `actionlint -verbose` |
| 103 | +* [Markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) |
| 104 | + * [Installation instructions](https://github.com/DavidAnson/markdownlint-cli2#install) |
| 105 | + * Run it like so: `markdownlint-cli2` |
| 106 | +* [Lychee](https://github.com/lycheeverse/lychee) |
| 107 | + * [Installation instructions](https://github.com/lycheeverse/lychee?tab=readme-ov-file#installation) |
| 108 | + * Run it like so: `lychee "./**/*.md"` |
| 109 | + Note: this command will show "false positives" locally for the `_Sidebar.md` file. These can be ignored. |
| 110 | +* [CSpell](https://cspell.org/) |
| 111 | + * [Installation instructions](https://cspell.org/docs/installation) |
| 112 | + * Run it like so: `cspell "**/*.md"` |
| 113 | +* [Shellcheck](https://www.shellcheck.net/) |
| 114 | + * [Installation instructions](https://github.com/koalaman/shellcheck?tab=readme-ov-file#installing) |
| 115 | + * Run it like so: `shellcheck ./build/wiki-command-replacer.sh` |
| 116 | + |
| 117 | + |
| 118 | +### Frequently Asked Questions |
| 119 | + |
| 120 | +#### Why not make the Wiki publicly editable ? |
| 121 | + |
| 122 | +Publicly editable Wiki pages for big projects get vandalized pretty often and we don't want to risk this type of vandalism leading to users getting incorrect information. |
| 123 | + |
| 124 | +As a secondary reason, there are parts of the wiki (especially the output examples), which were pretty out of date. |
| 125 | +By having the wiki source in this repository, it allows for automating certain updates which would otherwise have to be done manually. |
0 commit comments