Skip to content

Linting, Formatting, and PHP CS

Josh Oakes edited this page Jun 20, 2024 · 6 revisions

Linting (ESLint)

Prettier formatting has been applied to Blocks Free. Here’s some information on how to set it up for VS Code:

  • Install Prettier extension
  • Open VS code settings and switch to “Workspace” tab
  • Search for Formatter and set Prettier as your default formatter.

The next two settings are optional but quite useful as they automatically format files whenever you switch files in VS Code, switch windows, or interact with terminal:

  • Search for “auto save” and change to “onFocusChange”
  • Search for “format on” and enable “Format on Save” and “Format on Paste”

Other notes

  • There is a .git-blame-ignore-revs file. You can add commit hashes here to exclude those commits from git blame. I’d recommend telling git to use this file; otherwise, git blame will show formatting changes for Prettier. To enable this, run git config --local blame.ignoreRevsFile .git-blame-ignore-revs.
  • Eslint is being run on commits now, which checks for prettier formatting. Not many other checks are done at this time. You can run es lint locally by running npm run lint-js ./ This will run faster if pointed at a specific file or directory by modifying the path at the end of the command.
  • I’ve excluded out internal components in /src/packages since these are in blocks pro too. We need to make sure these two codebases are in sync, then source them from the components repo.

Formatting (Prettier)

Waiting until AI is merged into master before applying to whole project

Example to format a file

npm run format ./src/blocks/tabs/edit.js

PHP CS

Example to run PHP CS on a file

./vendor/bin/phpcs -d memory_limit=2048M -p --runtime-set testVersion 7.4 --ignore=./vendor,./node_modules,./dist,./src/packages/icons/,./includes/assets/ --extensions=php --standard=./phpcs.xml ./

To auto apply fixes, run

./vendor/bin/phpcbf -d memory_limit=2048M -p --runtime-set testVersion 7.4 --ignore=./vendor,./node_modules,./dist,./src/packages/icons/,./includes/assets/ --extensions=php --standard=./phpcs.xml ./

Clone this wiki locally