jpi / cron-linter
Tool for linting cron files and expressions
Requires
- php: ^8.0
- symfony/console: ^5.0 || ^6.0 || ^7.0 || ^8.0
- symfony/yaml: ^5.0 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- jpi/codestyles: ^1.0
- phpunit/phpunit: ^12.0
README
Lint cron files. Based on the work of @Dave13h from https://github.com/Dave13h/php-censor-cronlint-plugin, just the PHPCensor aspect removed and made into a standalone package.
Installation
composer require --dev jpi/cron-linter
Add a .cronlinter.yml file to your project root that specifies a list of cron files to lint.
files: - /cron-1 - /cron-2
File paths can also include glob patterns to match multiple files at once.
files: - /etc/cron.d/* - /cron.*
Then run php vendor/bin/lintcron, which will list any errors found in the specified cron files. You can use a different config file location using the --config-file option.
You can also specify files to be linted using the --files option, providing a comma-separated list of file paths.
Or if you want to do it programmatically on files or content.
// Lint cron files // $files is an array of file paths for cron files to check // $baseDir (optional) is a string containing the base directory path for all file paths $linter = \JPI\CronLinter::lintFiles($files, $baseDir); // Lint cron content directly // $expression is a string containing one or more cron expressions (one per line) $linter = \JPI\CronLinter::lintContent($expression); // Both methods return a CronLinter instance // Call getErrors() to retrieve errors, grouped by file path (or empty string for content linting) // Returns an empty array if no errors found $errors = $linter->getErrors(); // Call getNumberOfFilesChecked() to retrieve the number of files that were checked $numberOfFilesChecked = $linter->getNumberOfFilesChecked();
Support
If you found this library interesting or useful please spread the word about this library: share on your socials, star on GitHub, etc.
If you find any issues or have any feature requests, you can open a issue or email me @ jahidulpabelislam.com 😏.
Authors
Licence
This module is licenced under the GNU General Public Licence - see the licence file for details