Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 2.67 KB

coding-standards.md

File metadata and controls

58 lines (42 loc) · 2.67 KB

Coding Standards

We enforce best coding practices as recommended by community leaders. This projects uses the following tools to ensure best coding practices are being followed.

Husky & Lint-Staged

Husky helps to trigger git hooks. We use the pre-commit hook to run code fixers to fix errors that violates our coding standards. Lint staged helps Husky triggers to run only on files modified in the commit and avoid running on the whole codebase. More information can be found in package.json file.

Note: Your commit may fail if the automatic fixes fails. In such case, you can fix the errors manually and then commit again.

Run the code fixers on the staged files manually using:

npx lint-staged

PHP CS Fixer

PHP CS Fixer is a tool to automatically fix PHP code style issues. PHP CS Fixer coding rules are defined in .php-cs-fixer.php file in the root of the project.

✅ It is automatically triggered during git commit. The automatic fixer may not resolve 100% of the errors. Manual intervention may be needed.

See the files that violates PHP coding rules using:

php ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.php --dry-run --verbose --diff

To trigger automatic fixer manually, run the following command:

php ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.php --diff

Larastan

Larastan is a Static Code Analyzer that finds errors in the code without actually running it. Larastan runs on top of PHPStan. Larastan configurations are stored in file phpstan.neon in the root of the project.

❌ It is NOT automatically triggered during git commit.

Analyze the codebase using:

./vendor/bin/phpstan analyse

ESLint

ESLint is used to validate the JS and VueJS files. ESLint rules are defined in .eslintrc.json file in the root of the project.

✅ It is automatically triggered during git commit. The automatic fixer may not resolve 100% of the errors. Manual intervention may be needed.

Check the ESLint errors in the codebase using:

./node_modules/.bin/eslint resources/js/ Modules/*/Resources/assets/js/ --ext .js,.vue

To trigger automatic fixer manually, use the --fix flag:

./node_modules/.bin/eslint resources/js/ Modules/*/Resources/assets/js/ --ext .js,.vue --fix