khalyomede / php-typo
A command line tool to validate files do not have English typo in variables, methods, functions, ...
Requires
- php: >=8.2.0
- aminnairi/string-extra: 0.1.0
- nikic/php-parser: 4.17.1
- symfony/console: 6.3.8
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.40.0
- pestphp/pest: 2.25.0
- phpstan/phpstan: 1.10.46
- phpstan/phpstan-strict-rules: 1.5.2
- rector/rector: 0.18.11
This package is auto-updated.
Last update: 2024-10-28 23:06:06 UTC
README
A command line tool to validate files do not have English typo in variables, methods, functions, ...
Summary
About
I searched for a tool to correct english typos across a code base, but only ended up finding VSCode plugins. I know there is PHPStorm plugins as well (and probably similar tools on others code editors), but I need a single, unique way to correct my english typos so that other contributors to my code base will also have the same results, and do not need to install anything on their editor.
English words list based on dwyl/english-words.
Features
- Validates your code do not have typos in
- class names and their properties, methods and their parameters
- interfaces names
- enum names and their cases
- variables names
- function names and their parameters
- constants and class constants
- Shipped with a list of known english words for fast quick start
- Dead simple way to ignore/whitelist additional words
Installation
On your root folder, on the terminal type this command:
./vendor/bin/php-typo init
This will create a file php-typo.json
at the root of your folder with the following content:
{ "include": [ "src" ], "exclude": [], "whitelist": [ "vendor/khalyomede/php-typo/src/words/english.json" ] }
Examples
1. Run your first check
In this example, we will just run the command, which by default will search on the files you specified in your "php-typo.json" config file.
We will assume we have the following file content in "src/index.php":
require __DIR__ . "/../vendor/autoload.php"; $gretingMessage = "Hello, world"; echo $gretingMessage . PHP_EOL;
Run the command:
khalyomede@ubuntu:~/programming/php-typo$ ./vendor/bin/php-typo check Getting config... Config found (0.08 ms.). Getting file list... File list found with 1 files to scan (0.26 ms.). Scanning... public/index.php:3 variable "gretingMessage" contains an unknown word "greting". public/index.php:5 variable "gretingMessage" contains an unknown word "greting". Total typos 2 Total files 1 Time spent 125.94 ms. Memory used 98.18 MB
2. Add more words/whitelist words
In this example, we will use an additional list of English words to extend the base list of words shipped with this package. This is equivalent to "ignoring" some words.
In the config file at "php-typo.json", add your custom JSON word list:
{ "include": [ "src" ], "exclude": [], "whitelist": [ "vendor/khalyomede/php-typo/src/words/english.json", "custom.json" ] }
The list of words should be an array of strings. Here is what you could have in your file "custom.json":
[ "greting", "php" ]
On the next check, the words "greting" and "php" will be counted as correct words.
Tests
composer run test
composer run analyse
composer run lint
composer run updates
composer run scan
composer run check
Or
composer run all