|
| 1 | +# @pleaseai/eslint-config |
| 2 | + |
| 3 | +[](https://npmjs.com/package/@pleaseai/eslint-config) |
| 4 | + |
| 5 | +PleaseAI's shared ESLint config, built on top of [@antfu/eslint-config](https://github.com/antfu/eslint-config). |
| 6 | + |
| 7 | +- Based on `@antfu/eslint-config` with PleaseAI defaults |
| 8 | +- Auto fix for formatting (aimed to be used standalone **without** Prettier) |
| 9 | +- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily! |
| 10 | +- TypeScript, JSX, Vue, JSON, YAML, Markdown, etc. Out-of-box |
| 11 | +- Optional [React](#react), [Next.js](#nextjs), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Solid](#solid), [Angular](#angular) support |
| 12 | +- Optional [formatters](#formatters) support for CSS, HTML, XML, etc. |
| 13 | +- Includes [`eslint-plugin-package-json`](#package-json-linting) configs |
| 14 | +- Requires ESLint v9.10.0+ |
| 15 | + |
| 16 | +## PleaseAI Defaults |
| 17 | + |
| 18 | +This config wraps `@antfu/eslint-config` with the following defaults: |
| 19 | + |
| 20 | +| Option | Value | |
| 21 | +|--------|-------| |
| 22 | +| Indent | 2 spaces | |
| 23 | +| Quotes | Single | |
| 24 | +| Semicolons | No | |
| 25 | +| TypeScript | Enabled | |
| 26 | +| Gitignore | Enabled | |
| 27 | + |
| 28 | +Additionally, `test/prefer-lowercase-title` is disabled. |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +### Install |
| 33 | + |
| 34 | +```bash |
| 35 | +bun add -D @pleaseai/eslint-config eslint |
| 36 | +``` |
| 37 | + |
| 38 | +### Configure |
| 39 | + |
| 40 | +Create `eslint.config.ts` (or `eslint.config.mjs`) in your project root: |
| 41 | + |
| 42 | +```js |
| 43 | +import pleaseai from '@pleaseai/eslint-config' |
| 44 | + |
| 45 | +export default pleaseai() |
| 46 | +``` |
| 47 | + |
| 48 | +### Add scripts to `package.json` |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | + "scripts": { |
| 53 | + "lint": "eslint", |
| 54 | + "lint:fix": "eslint --fix" |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +## Customization |
| 60 | + |
| 61 | +The `pleaseai()` function accepts the same options as `antfu()`. All `@antfu/eslint-config` options are supported. |
| 62 | + |
| 63 | +```js |
| 64 | +import pleaseai from '@pleaseai/eslint-config' |
| 65 | + |
| 66 | +export default pleaseai({ |
| 67 | + // Override PleaseAI defaults |
| 68 | + stylistic: { |
| 69 | + indent: 4, |
| 70 | + }, |
| 71 | + |
| 72 | + // Enable framework support |
| 73 | + vue: true, |
| 74 | + react: true, |
| 75 | + |
| 76 | + // Add ignores |
| 77 | + ignores: [ |
| 78 | + '**/fixtures', |
| 79 | + ], |
| 80 | +}) |
| 81 | +``` |
| 82 | + |
| 83 | +You can also pass additional flat configs as extra arguments: |
| 84 | + |
| 85 | +```js |
| 86 | +import pleaseai from '@pleaseai/eslint-config' |
| 87 | + |
| 88 | +export default pleaseai( |
| 89 | + { |
| 90 | + // PleaseAI + antfu options |
| 91 | + typescript: true, |
| 92 | + }, |
| 93 | + // Additional ESLint flat configs |
| 94 | + { |
| 95 | + files: ['**/*.ts'], |
| 96 | + rules: { |
| 97 | + 'ts/consistent-type-definitions': ['error', 'interface'], |
| 98 | + }, |
| 99 | + }, |
| 100 | +) |
| 101 | +``` |
| 102 | + |
| 103 | +### Rules Overrides |
| 104 | + |
| 105 | +Use the `overrides` option in each integration: |
| 106 | + |
| 107 | +```js |
| 108 | +import pleaseai from '@pleaseai/eslint-config' |
| 109 | + |
| 110 | +export default pleaseai({ |
| 111 | + vue: { |
| 112 | + overrides: { |
| 113 | + 'vue/operator-linebreak': ['error', 'before'], |
| 114 | + }, |
| 115 | + }, |
| 116 | + typescript: { |
| 117 | + overrides: { |
| 118 | + 'ts/consistent-type-definitions': ['error', 'interface'], |
| 119 | + }, |
| 120 | + }, |
| 121 | +}) |
| 122 | +``` |
| 123 | + |
| 124 | +### Type Aware Rules |
| 125 | + |
| 126 | +Enable [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing `tsconfigPath`: |
| 127 | + |
| 128 | +```js |
| 129 | +import pleaseai from '@pleaseai/eslint-config' |
| 130 | + |
| 131 | +export default pleaseai({ |
| 132 | + typescript: { |
| 133 | + tsconfigPath: 'tsconfig.json', |
| 134 | + }, |
| 135 | +}) |
| 136 | +``` |
| 137 | + |
| 138 | +## Optional Configs |
| 139 | + |
| 140 | +### React |
| 141 | + |
| 142 | +```js |
| 143 | +import pleaseai from '@pleaseai/eslint-config' |
| 144 | + |
| 145 | +export default pleaseai({ |
| 146 | + react: true, |
| 147 | +}) |
| 148 | +``` |
| 149 | + |
| 150 | +```bash |
| 151 | +bun add -D @eslint-react/eslint-plugin eslint-plugin-react-refresh |
| 152 | +``` |
| 153 | + |
| 154 | +### Next.js |
| 155 | + |
| 156 | +```js |
| 157 | +import pleaseai from '@pleaseai/eslint-config' |
| 158 | + |
| 159 | +export default pleaseai({ |
| 160 | + nextjs: true, |
| 161 | +}) |
| 162 | +``` |
| 163 | + |
| 164 | +```bash |
| 165 | +bun add -D @next/eslint-plugin-next |
| 166 | +``` |
| 167 | + |
| 168 | +### Vue |
| 169 | + |
| 170 | +Vue support is auto-detected. You can also explicitly enable it: |
| 171 | + |
| 172 | +```js |
| 173 | +import pleaseai from '@pleaseai/eslint-config' |
| 174 | + |
| 175 | +export default pleaseai({ |
| 176 | + vue: true, |
| 177 | +}) |
| 178 | +``` |
| 179 | + |
| 180 | +### Svelte |
| 181 | + |
| 182 | +```js |
| 183 | +import pleaseai from '@pleaseai/eslint-config' |
| 184 | + |
| 185 | +export default pleaseai({ |
| 186 | + svelte: true, |
| 187 | +}) |
| 188 | +``` |
| 189 | + |
| 190 | +```bash |
| 191 | +bun add -D eslint-plugin-svelte |
| 192 | +``` |
| 193 | + |
| 194 | +### Astro |
| 195 | + |
| 196 | +```js |
| 197 | +import pleaseai from '@pleaseai/eslint-config' |
| 198 | + |
| 199 | +export default pleaseai({ |
| 200 | + astro: true, |
| 201 | +}) |
| 202 | +``` |
| 203 | + |
| 204 | +```bash |
| 205 | +bun add -D eslint-plugin-astro |
| 206 | +``` |
| 207 | + |
| 208 | +### Solid |
| 209 | + |
| 210 | +```js |
| 211 | +import pleaseai from '@pleaseai/eslint-config' |
| 212 | + |
| 213 | +export default pleaseai({ |
| 214 | + solid: true, |
| 215 | +}) |
| 216 | +``` |
| 217 | + |
| 218 | +```bash |
| 219 | +bun add -D eslint-plugin-solid |
| 220 | +``` |
| 221 | + |
| 222 | +### UnoCSS |
| 223 | + |
| 224 | +```js |
| 225 | +import pleaseai from '@pleaseai/eslint-config' |
| 226 | + |
| 227 | +export default pleaseai({ |
| 228 | + unocss: true, |
| 229 | +}) |
| 230 | +``` |
| 231 | + |
| 232 | +```bash |
| 233 | +bun add -D @unocss/eslint-plugin |
| 234 | +``` |
| 235 | + |
| 236 | +### Angular |
| 237 | + |
| 238 | +```js |
| 239 | +import pleaseai from '@pleaseai/eslint-config' |
| 240 | + |
| 241 | +export default pleaseai({ |
| 242 | + angular: true, |
| 243 | +}) |
| 244 | +``` |
| 245 | + |
| 246 | +```bash |
| 247 | +bun add -D @angular-eslint/eslint-plugin @angular-eslint/eslint-plugin-template @angular-eslint/template-parser |
| 248 | +``` |
| 249 | + |
| 250 | +### Formatters |
| 251 | + |
| 252 | +Use external formatters for files that ESLint cannot handle yet (`.css`, `.html`, etc): |
| 253 | + |
| 254 | +```js |
| 255 | +import pleaseai from '@pleaseai/eslint-config' |
| 256 | + |
| 257 | +export default pleaseai({ |
| 258 | + formatters: { |
| 259 | + css: true, |
| 260 | + html: true, |
| 261 | + markdown: 'prettier', |
| 262 | + }, |
| 263 | +}) |
| 264 | +``` |
| 265 | + |
| 266 | +```bash |
| 267 | +bun add -D eslint-plugin-format |
| 268 | +``` |
| 269 | + |
| 270 | +## Package JSON Linting |
| 271 | + |
| 272 | +This package also exports `eslint-plugin-package-json` configs: |
| 273 | + |
| 274 | +```js |
| 275 | +import { recommended, stylistic } from '@pleaseai/eslint-config/package-json' |
| 276 | +``` |
| 277 | + |
| 278 | +- `recommended` — `eslint-plugin-package-json` recommended-publishable config |
| 279 | +- `stylistic` — `eslint-plugin-package-json` stylistic config |
| 280 | + |
| 281 | +## IDE Support (auto fix on save) |
| 282 | + |
| 283 | +### VS Code |
| 284 | + |
| 285 | +Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and add the following to `.vscode/settings.json`: |
| 286 | + |
| 287 | +```jsonc |
| 288 | +{ |
| 289 | + // Disable the default formatter, use eslint instead |
| 290 | + "prettier.enable": false, |
| 291 | + "editor.formatOnSave": false, |
| 292 | + |
| 293 | + // Auto fix |
| 294 | + "editor.codeActionsOnSave": { |
| 295 | + "source.fixAll.eslint": "explicit", |
| 296 | + "source.organizeImports": "never" |
| 297 | + }, |
| 298 | + |
| 299 | + // Silent the stylistic rules in your IDE, but still auto fix them |
| 300 | + "eslint.rules.customizations": [ |
| 301 | + { "rule": "style/*", "severity": "off", "fixable": true }, |
| 302 | + { "rule": "format/*", "severity": "off", "fixable": true }, |
| 303 | + { "rule": "*-indent", "severity": "off", "fixable": true }, |
| 304 | + { "rule": "*-spacing", "severity": "off", "fixable": true }, |
| 305 | + { "rule": "*-spaces", "severity": "off", "fixable": true }, |
| 306 | + { "rule": "*-order", "severity": "off", "fixable": true }, |
| 307 | + { "rule": "*-dangle", "severity": "off", "fixable": true }, |
| 308 | + { "rule": "*-newline", "severity": "off", "fixable": true }, |
| 309 | + { "rule": "*quotes", "severity": "off", "fixable": true }, |
| 310 | + { "rule": "*semi", "severity": "off", "fixable": true } |
| 311 | + ], |
| 312 | + |
| 313 | + // Enable eslint for all supported languages |
| 314 | + "eslint.validate": [ |
| 315 | + "javascript", |
| 316 | + "javascriptreact", |
| 317 | + "typescript", |
| 318 | + "typescriptreact", |
| 319 | + "vue", |
| 320 | + "html", |
| 321 | + "markdown", |
| 322 | + "json", |
| 323 | + "jsonc", |
| 324 | + "yaml", |
| 325 | + "toml", |
| 326 | + "xml", |
| 327 | + "gql", |
| 328 | + "graphql", |
| 329 | + "astro", |
| 330 | + "svelte", |
| 331 | + "css", |
| 332 | + "less", |
| 333 | + "scss", |
| 334 | + "pcss", |
| 335 | + "postcss" |
| 336 | + ] |
| 337 | +} |
| 338 | +``` |
| 339 | + |
| 340 | +### Lint Staged |
| 341 | + |
| 342 | +```json |
| 343 | +{ |
| 344 | + "simple-git-hooks": { |
| 345 | + "pre-commit": "bun lint-staged" |
| 346 | + }, |
| 347 | + "lint-staged": { |
| 348 | + "*": "eslint --fix" |
| 349 | + } |
| 350 | +} |
| 351 | +``` |
| 352 | + |
| 353 | +```bash |
| 354 | +bun add -D lint-staged simple-git-hooks |
| 355 | +npx simple-git-hooks |
| 356 | +``` |
| 357 | + |
| 358 | +## View Enabled Rules |
| 359 | + |
| 360 | +Use [@eslint/config-inspector](https://github.com/eslint/config-inspector) to visualize what rules are enabled: |
| 361 | + |
| 362 | +```bash |
| 363 | +npx @eslint/config-inspector |
| 364 | +``` |
| 365 | + |
| 366 | +## Plugins Renaming |
| 367 | + |
| 368 | +This config inherits `@antfu/eslint-config`'s plugin renaming for a consistent DX: |
| 369 | + |
| 370 | +| New Prefix | Original Prefix | Source Plugin | |
| 371 | +|------------|-----------------|---------------| |
| 372 | +| `import/*` | `import-lite/*` | [eslint-plugin-import-lite](https://github.com/9romise/eslint-plugin-import-lite) | |
| 373 | +| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) | |
| 374 | +| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) | |
| 375 | +| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) | |
| 376 | +| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) | |
| 377 | +| `test/*` | `vitest/*` | [@vitest/eslint-plugin](https://github.com/vitest-dev/eslint-plugin-vitest) | |
| 378 | + |
| 379 | +## Re-exports |
| 380 | + |
| 381 | +All exports from `@antfu/eslint-config` are re-exported, so you can import fine-grained configs directly: |
| 382 | + |
| 383 | +```js |
| 384 | +import { combine, javascript, typescript, vue } from '@pleaseai/eslint-config' |
| 385 | +``` |
| 386 | + |
| 387 | +## License |
| 388 | + |
| 389 | +[MIT](./LICENSE) |
0 commit comments