What is this?

In this guide we provide some simple examples for the usage of the auto-fix functionality. Crafty comes with some default linter configuration including among other

  • ESLint (JavaScript)
  • PostCSS (CSS)
  • Prettier (JavaScript + CSS)

When should you use it ?

When your build produces a lot of errors, you might want to automate the task of fixing the errors.

Some of them need to be fixed manually but most can be fixed automatically. Before diving into fixing 100 lines of code try these commands they come in handy.

Option 1 : Crafty jsLint, cssLint options

This command will lint all your JavaScript files inside the src folder.

crafty jsLint src/** --fix --preset recommended

This command will lint all your CSS files inside your src folder.

crafty cssLint src/** --fix --preset recommended

Option 2 : use Prettier directly

Before running yarn prettier you should run

yarn crafty ide

More information IDE Integration

This command will generate prettier configuration for your project.

Prettier is used internally with Crafty, you can also use Prettier directly to fix the formatting of your files without the linting:

npx prettier --write "**/*.js"
npx prettier --write "**/*.ts" "**/*.tsx" "**/*.mts" "**/*.cts"

Note the --write option will write the changes to disk. Omitting it will allow you to have a preview of the changes.

Example for linting TypeScript files:

npx prettier --write "**/*.ts" "**/*.tsx" "**/*.mts" "**/*.cts"

More options here: Prettier Configuration