This is the standard code checker for Magento 2 in ICUBE.
Clone this project
git clone https://github.com/icubeus/m2-codechecker.gitCopy these folders and files to your project folder.
.github/
eslint/
package.jsonModify .github/workflows/main.yml according to your project.
- Line 27 (composer_name)
composer_name: nameof/repositoryexample
composer_name: icube-mage/magento2-focusnusantara- Line 44 (destination folder to scan for jslint)
run: npm run eslint -- foldernameexample
run: npm run eslint -- srcYou can comment out the whole js code checking job if there's no js code in your repository, because the job will mark as failed if there's no js code in the scanned folders.
- Line 4-5 (branches). You can specify which action will be the trigger for the jobs to be run.
pull_request:
branches: [ master, staging, develop ]This means that every time pull request is created on branch master/staging/develop, the workflow will run. If there is a new commit added to the branch that's being pull requested (not merged yet), it will retrigger the workflow to run. You can also trigger the workflow on every push on a branch. Example:
pull_request:
branches: [ master, staging, develop ]
push:
branches: [ develop ](run these commands from the magento root folder)
PHP Unit Testing
vendor/bin/phpunit path/to/folderMagento Coding Standard Scan
vendor/bin/phpcs --standard=vendor/magento/magento-coding-standard/Magento2 path/to/folder
vendor/bin/phpcs --standard=vendor/magento/magento-coding-standard/Magento2Framework path/to/folderMagento Coding Standard General Fixing
vendor/bin/phpcbf --standard=Magento2 path/to/folderIf you get this error,
ERROR: the "Magento2" coding standard is not installed. The installed coding standards are PSR12, Zend, PSR1, PSR2, PEAR, MySource and Squizcopy the Magento2 folder to your project root folder and try to rerun the command. If you then receive this error,
ERROR: Referenced sniff "PHPCompatibility.FunctionUse.RemovedFunctions" does not existrun this command
vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../phpcompatibility/php-compatibilitythen rerun the cbf command.
JS Eslint Checker
eslint -- app/code/IcubeAdditional: Code Sniffer
vendor/bin/rector process path/to/folder --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/phpcompatibility/php-compatibility/PHPCSAliases.php