Skip to content

Commit 1710f8c

Browse files
committed
Adds README section on integrating with ESLint and Stylelint
1 parent daf4135 commit 1710f8c

1 file changed

Lines changed: 77 additions & 5 deletions

File tree

README.md

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,86 @@ For format on save, add to `.vscode/settings.json`:
9999
}
100100
```
101101

102-
## Choosing Between Prettier and `@stylistic`
102+
## Using with ESLint and Stylelint
103103

104-
The HTML Academy Codeguide is implemented in two parallel ways:
104+
Prettier handles formatting; ESLint and Stylelint find bugs and enforce conventions. They can — and should — work together in one project, as long as you stop the linters from fighting Prettier over the same whitespace.
105105

106-
- **Prettier** (this package) — one formatter for every supported language, format on save, no per-rule reports.
107-
- **`@stylistic`** inside [`eslint-config-htmlacademy`](https://github.com/htmlacademy/eslint-config-htmlacademy) and [`stylelint-config-htmlacademy`](https://github.com/htmlacademy/stylelint-config-htmlacademy) — formatting rules reported alongside other linter rules, fixable with `eslint --fix` and `stylelint --fix`.
106+
**Install all three:**
108107

109-
Pick one. Running both at the same time will cause both to fight over the same files.
108+
```bash
109+
npm install -D \
110+
prettier prettier-config-htmlacademy \
111+
eslint eslint-config-htmlacademy eslint-config-prettier \
112+
stylelint stylelint-config-htmlacademy
113+
```
114+
115+
[`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) is the official package that turns off ESLint rules that conflict with Prettier.
116+
117+
**`prettier.config.js`:**
118+
119+
```js
120+
import preset from 'prettier-config-htmlacademy';
121+
export default preset;
122+
```
123+
124+
**`eslint.config.js`**`eslint-config-prettier/flat` must come last so it overrides formatting rules from the HTML Academy preset:
125+
126+
```js
127+
import vanilla from 'eslint-config-htmlacademy/vanilla';
128+
import prettier from 'eslint-config-prettier/flat';
129+
130+
export default [...vanilla, prettier];
131+
```
132+
133+
**`stylelint.config.js`** — turn off the `@stylistic` rules and empty-line spacing, keep everything else (including [`order/properties-order`](https://github.com/hudochenkov/stylelint-order) — Prettier doesn't reorder CSS properties):
134+
135+
```js
136+
import htmlacademy from 'stylelint-config-htmlacademy';
137+
138+
const stylisticOff = Object.fromEntries(
139+
Object.keys(htmlacademy.rules)
140+
.filter((rule) => rule.startsWith('@stylistic/'))
141+
.map((rule) => [rule, null]),
142+
);
143+
144+
export default {
145+
...htmlacademy,
146+
rules: {
147+
...htmlacademy.rules,
148+
...stylisticOff,
149+
'at-rule-empty-line-before': null,
150+
'rule-empty-line-before': null,
151+
},
152+
};
153+
```
154+
155+
**Add scripts to `package.json`:**
156+
157+
```json
158+
{
159+
"scripts": {
160+
"format": "prettier . --write",
161+
"lint:js": "eslint .",
162+
"lint:css": "stylelint \"**/*.{css,scss}\"",
163+
"lint": "npm run lint:js && npm run lint:css",
164+
"check": "prettier . --check && npm run lint"
165+
}
166+
}
167+
```
168+
169+
Day to day: Prettier formats on save in the editor; `npm run lint` and `npm run check` run in CI and before commits.
170+
171+
### Who does what
172+
173+
| Tool | Responsibility |
174+
|---|---|
175+
| Prettier | Indentation, quotes, semicolons, line breaks, trailing commas — JS, TS, JSX, CSS, HTML, MD, JSON, YAML |
176+
| ESLint | JavaScript and TypeScript correctness — unused variables, unsafe patterns, modern syntax, file naming |
177+
| Stylelint | CSS correctness — BEM class names, property ordering, modern color functions, max nesting, vendor prefixes |
178+
179+
### Alternative: linters only, without Prettier
180+
181+
If you would rather not add a third tool, skip this package and use `eslint-config-htmlacademy` and `stylelint-config-htmlacademy` on their own. Their built-in `@stylistic` rules cover the same formatting, with `eslint --fix` and `stylelint --fix` as your formatter.
110182

111183
## Links
112184

0 commit comments

Comments
 (0)