| title | Profanity |
|---|---|
| description | Pest's Profanity plugin scans your codebase for profanity in places like comments, constants, and properties, helping you keep things professional. |
Source code: github.com/pestphp/pest-plugin-profanity
The Profanity plugin scans your codebase for profanity in places like comments, constants, and properties, helping you maintain a more professional and respectful codebase. As developers, we've all faced moments of frustration — whether debugging a persistent issue or deciphering confusing code written by someone else. Those moments can sometimes lead to profanity slipping into your code.
To get started, require the plugin via Composer:
composer require pestphp/pest-plugin-profanity --devOnce the plugin is installed, you may use the --profanity option to generate a report of your profanity:
./vendor/bin/pest --profanityThe Profanity plugin does not require you to write any tests. Instead, it analyzes your codebase and generates a report of your profanity. This report will display a list of files and their corresponding profanity results:
If any of your files contain profanity, they will be highlighted in red and displayed with their respective line numbers and the profane word(s) that were found.
For example, pr31(fuck) means that the word "fuck" was found on line 31.
Often, a codebase is written in a single language, so you may wish to flag profanity only for that language. To do this, you may use the --language option:
./vendor/bin/pest --profanity --language=enIf needed, you may also pass in multiple comma-separated languages:
./vendor/bin/pest --profanity --language=en,daThe supported languages are ar, da, en, es, it, ja, nl, pt_BR, and ru. By default, en is used if no language is specified.
Sometimes you may wish to flag certain words specific to your application as profane. To do this, you may use the --include option:
./vendor/bin/pest --profanity --include=elephpantConversely, you may wish to exclude certain words from being flagged as profane. To do this, you may use the --exclude option:
./vendor/bin/pest --profanity --exclude=elephpantOften, when checking for profanity, you only want to see the files that actually contain it. To do this, you may use the --compact option:
./vendor/bin/pest --profanity --compactIn addition, Pest may report the profanity results to a specific file:
./vendor/bin/pest --profanity --output=my-report.jsonSometimes you may wish to exclude certain lines that contain profanity from being flagged, without excluding words from the whole application. In these cases, you may tell the checker to ignore specific lines:
const string Fuck; // @pest-ignore-profanityIn this chapter, we have discussed Pest's Profanity plugin and how it helps you maintain a professional codebase. In the next chapter, we will explore the additional CLI options that Pest provides: CLI API Reference