Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devatreides/dump-linter
A php-cs-fixer custom rule for dump statement removal
https://github.com/devatreides/dump-linter
Last synced: 29 days ago
JSON representation
A php-cs-fixer custom rule for dump statement removal
- Host: GitHub
- URL: https://github.com/devatreides/dump-linter
- Owner: devatreides
- License: mit
- Created: 2023-01-12T17:49:20.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-22T04:31:10.000Z (almost 2 years ago)
- Last Synced: 2024-05-02T05:01:04.927Z (8 months ago)
- Language: PHP
- Size: 49.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
Sometimes you are debugging and end up deploying with your code a `dump`or a `var_dump` (if you're a Laravel dev, the infamous `dd`) and that could be annoying, so **Dump Linter** is a package that complements [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer), providing a rule to remove dump statements from the source code.
> ❗ IMPORTANT: the rule is considered risky by PHP-CS-Fixer metrics because technically `dump`/`var_dump` are not errors or bad writing, so be careful and use this rule if you're completely sure that you don't want them in the codebase.
## REQUIREMENTS
> **[PHP 8.1+](https://www.php.net/releases/)**
>
> **[PHP-CS-Fixer 3](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer)**## HOW TO INSTALL
To install the package, just use [composer](https://getcomposer.org):
```bash
composer require tombenevides/dump-linter
```## HOW TO USE
### Configuring PHP-CS-Fixer
After installing, you need to edit the `.php-cs-fixer.dist.php` file (or the file that you're chose), adding the custom rule using `registerCustomFixers()` function and then set the rule, as you can see below:
```php
$config = new PhpCsFixer\Config();return $config
->registerCustomFixers([
new \Tombenevides\DumpLinter\DumpRemovalFixer()
])
->setRules([
'@PSR12' => true,
'Tombenevides/dump_removal' => true,
...
])
```> List of dump statements that will be removed: `dump()`,`var_dump()`,`dd()`,`ray()` and `dumps()`.
More info or questions about PHP-CS-Fixer configuration file, just check [this link](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst).
### Running the linter with custom rule
Since this is a risky rule, the default command `php-cs-fixer fix -v` will not work. Therefore, to allow the rule to make the expected changes, you need to give the linter permission to perform risky actions. You do this by adding the `--allow-risky=yes` flag.
## LICENSE
**Dump Linter** is a software under the [MIT License](LICENSE)
## UPDATES
👋 Follow the author [@devatreides](https://twitter.com/devatreides) on Twitter to know more about the last updates and other projects. Say Hi!