mirror of
https://github.com/jlengrand/open-wc.git
synced 2026-03-10 08:31:19 +00:00
- @open-wc/building-rollup@0.3.1 - @open-wc/building-webpack@1.3.3 - @open-wc/chai-dom-equals@0.11.4 - @open-wc/create@0.8.0 - @open-wc/demoing-storybook@0.2.1 - @open-wc/eslint-config@0.4.3 - @open-wc/prettier-config@0.1.10 - @open-wc/semantic-dom-diff@0.10.4 - @open-wc/testing-helpers@0.8.8 - @open-wc/testing-karma-bs@1.0.5 - @open-wc/testing-karma@1.1.1 - @open-wc/testing@0.11.4
Linting Prettier
Use Prettier to format your JS, CSS and HTML code.
::: tip This is part of the default open-wc recommendation :::
Setup
npm init @open-wc
# Upgrade > Linting
Manual
- Install
@open-wc/prettier-config.yarn add --dev @open-wc/prettier-config - Create
prettier.config.jsin the root directory of your project.module.exports = require('@open-wc/prettier-config'); - Add the following scripts to your package.json
"scripts": { "lint:prettier": "prettier \"**/*.js\" --list-different || (echo '↑↑ these files are not prettier formatted ↑↑' && exit 1)", "format:prettier": "prettier \"**/*.js\" --write", }, - Update your
.eslintrc.jsto look like this:module.exports = { extends: [ '@open-wc/eslint-config', 'eslint-config-prettier' ].map(require.resolve), };
What you get
- Apply formatting to JS files
- Apply formatting to HTML inside of
htmltagged template literals used by lit-html - Apply formatting to CSS inside of
csstagged template literals used by lit-css - Integration with ESLint to prevent potentially conflicting rules
Usage
Run:
npm run lint:prettierto check if your files are correctly formattednpm run format:prettierto auto format your files
Linting Error Examples
$ npm run lint:prettier
test/set-card.test.js
test/set-game.test.js
↑↑ these files are not prettier formatted ↑↑
Simply run npm run format:prettier to format your files automatically.