|
| 1 | +# Git commit keyword validation |
| 2 | + |
| 3 | +## Purpose |
| 4 | +Every commit, blacklisted phrases are scanned within scanned files containing a specified file extension.\ |
| 5 | +The purpose of these checks is to prevent committing production-breaking or sensative system information. |
| 6 | + |
| 7 | +## Keywords used |
| 8 | +**_Note:_** some example configuration is below. Specific packages might override the default configuration. |
| 9 | + |
| 10 | +To prevent accidental commits of specific syntax that may cause issues, the testing suite sniffs\ |
| 11 | +several keywords in your commits. |
| 12 | + |
| 13 | +### Preventing production logs, debug statements and leaking sensitive system information |
| 14 | +```yaml |
| 15 | +- "die(" |
| 16 | +- "dd(" |
| 17 | +- "var_dump(" |
| 18 | +- "console.log(" |
| 19 | +- "alert(" |
| 20 | +- "print_r(" |
| 21 | +- "phpinfo(" |
| 22 | +``` |
| 23 | +
|
| 24 | +### Preventing accidental committing of merge conflicts |
| 25 | +```yaml |
| 26 | +- "<<<<<" |
| 27 | +- ">>>>>" |
| 28 | +- "=====" |
| 29 | +``` |
| 30 | +
|
| 31 | +### Preventing statements that have better alternatives |
| 32 | +```yaml |
| 33 | +- "<?php echo" |
| 34 | +``` |
| 35 | +
|
| 36 | +* The magento2 coding standards extend this with invocation of the ObjectManager. |
| 37 | +
|
| 38 | +## Files scanned |
| 39 | +The following files are scanned for blacklisted keywords in a default configuration. |
| 40 | +
|
| 41 | +**_Note:_** different project types might override the files scanned. |
| 42 | +```yaml |
| 43 | +- .php |
| 44 | +- .js |
| 45 | +``` |
| 46 | +* Magento2 project types extend this with .phtml files. |
| 47 | +* Pimcore project types extend this with .twig files. |
| 48 | +
|
| 49 | +## Override the configuration |
| 50 | +To override the default git blacklist with your own, override the configuration in the `grumphp.yml` file\ |
| 51 | +in your local project. An example configuration can be found below. |
| 52 | + |
| 53 | +Full details of available configuration options can be found [here](https://github.com/phpro/grumphp/blob/master/doc/tasks/git_blacklist.md). |
| 54 | + |
| 55 | +Note: configuration keys are **overwritten, not merged**. |
| 56 | + |
| 57 | +```yaml |
| 58 | +imports: |
| 59 | + - resource: 'vendor/youwe/testing-suite/config/default/grumphp.yml' |
| 60 | +
|
| 61 | +parameters: |
| 62 | + git_blacklist.keywords: |
| 63 | + - "die(" |
| 64 | + - "dd(" |
| 65 | + - "var_dump(" |
| 66 | + - "console.log(" |
| 67 | + - "alert(" |
| 68 | + - "print_r(" |
| 69 | + - "phpinfo(" |
| 70 | + - "exit;" |
| 71 | + - "<<<<<" |
| 72 | + - ">>>>>" |
| 73 | + - "=====" |
| 74 | + - "<?php echo" |
| 75 | + - "My additional keyword" |
| 76 | + git_blacklist.triggered_by: [ 'php', 'js', 'additional_file_extension_here' ] |
| 77 | +``` |
0 commit comments