astro
> ESLint flat config for Astro with TypeScript. Extends @jmlweb/eslint-config-base with eslint-plugin-astro rules for .astro files.
> โ
Recommended: Oxlint cannot lint .astro templates, so this package is the way to lint them. In a project migrated to Oxlint, lint everything else with @jmlweb/oxlint-config-base and only .astro files with ESLint; see the migration guide.
โจ Features
Section titled โโจ Featuresโ- ๐ Astro rules:
eslint-plugin-astrorecommended config - ๐
.astroparsing: TypeScript parser for frontmatter, with type-checked rules disabled where.astrohas no type info - ๐ Strict TypeScript: everything from
@jmlweb/eslint-config-basefor.tsand.tsx - ๐ฆ Import sorting: imports and exports sorted in
.astro,.tsand.tsx - ๐จ Prettier compatible: disables rules that conflict with Prettier
๐ฆ Installation
Section titled โ๐ฆ Installationโnpm install --save-dev @jmlweb/eslint-config-astro @jmlweb/eslint-config-base eslint @eslint/js typescript-eslint eslint-config-prettier eslint-plugin-simple-import-sort eslint-plugin-astro> ๐ก Upgrading? See the Migration Guide.
๐ Quick Start
Section titled โ๐ Quick Startโimport astroConfig from '@jmlweb/eslint-config-astro';
export default [ ...astroConfig, // Project-specific overrides];๐ก Examples
Section titled โ๐ก ExamplesโTest overrides and ignores
Section titled โTest overrides and ignoresโimport astroConfig from '@jmlweb/eslint-config-astro';
export default [ ...astroConfig, { files: ['**/*.test.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off', 'no-console': 'off', }, }, { ignores: ['dist/', '.astro/', 'node_modules/'], },];Tune Astro rules
Section titled โTune Astro rulesโimport astroConfig from '@jmlweb/eslint-config-astro';
export default [ ...astroConfig, { files: ['**/*.astro'], rules: { 'astro/no-unused-define-vars-in-style': 'warn', }, },];๐ Configuration Details
Section titled โ๐ Configuration Detailsโ| Files | Applied |
|---|---|
**/*.astro |
astro recommended, TypeScript parser, type-checked rules off, sorting |
**/*.ts, **/*.tsx |
Strict TypeScript from base, import and export sorting |
Included
Section titled โIncludedโ- โ
Everything from
@jmlweb/eslint-config-base - โ
eslint-plugin-astrorecommended rules - โ
.astrofiles parsed with@typescript-eslint/parserand.astroas an extra file extension - โ Prettier conflict resolution
Type-checked rules are disabled for .astro files because astro-eslint-parser provides no type information.
๐ Import Sorting
Section titled โ๐ Import SortingโImports are sorted and type-only imports are enforced.
Before:
import { Component } from './component';import type { User } from './types';import fs from 'fs';After eslint --fix:
import fs from 'fs';import type { User } from './types';import { Component } from './component';๐ฏ When to Use
Section titled โ๐ฏ When to Useโ- โ Astro projects written in TypeScript
- โ
Linting
.astrofiles alongside Oxlint in a migrated project - โ
Strict type-aware linting for
.tsfiles in Astro projects
For other TypeScript projects use @jmlweb/eslint-config-base, or @jmlweb/eslint-config-react for React.
๐ง Extending the Configuration
Section titled โ๐ง Extending the ConfigurationโSpread the config, then add objects after it. Later entries win.
import astroConfig from '@jmlweb/eslint-config-astro';
export default [ ...astroConfig, { files: ['src/pages/**/*.astro'], rules: { 'no-console': 'off', }, },];๐ Usage with Scripts
Section titled โ๐ Usage with Scriptsโ{ "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix" }}npm run lint๐ Requirements
Section titled โ๐ Requirementsโ- Node.js >= 22.12.0
- ESLint ^9.0.0 || ^10.0.0 (flat config)
- TypeScript project with a
tsconfig.json(versions supported by typescript-eslint 8)
๐ฆ Peer Dependencies
Section titled โ๐ฆ Peer Dependenciesโeslint(^9.0.0 || ^10.0.0)@eslint/js(^9.0.0 || ^10.0.0)typescript-eslint(^8.0.0)eslint-config-prettier(^9.1.0 || ^10.0.0)eslint-plugin-astro(^1.5.0 || ^2.0.0 || ^3.0.0)eslint-plugin-simple-import-sort(^12.0.0 || ^13.0.0 || ^14.0.0)@jmlweb/eslint-config-base(^3.0.3)
๐ Related Packages
Section titled โ๐ Related Packagesโ@jmlweb/eslint-config-base: TypeScript config (extended by this package, maintenance mode)@jmlweb/oxlint-config-base: Oxlint config for the non-.astrofiles@jmlweb/tsconfig-astro: TypeScript config for Astro@jmlweb/prettier-config-base: Prettier config (maintenance mode)
๐ Migration Guide
Section titled โ๐ Migration Guideโ1.x to 2.0
Section titled โ1.x to 2.0โNode.js 18 and 20 are end-of-life. Node.js >= 22.12.0 is now required: it is the first Node.js 22 release that can require() ES modules without a flag, which the CommonJS build needs to load ESM-only plugins. Peer ranges were also widened (eslint-plugin-astro 2 and 3, eslint-plugin-simple-import-sort 13 and 14).
- Upgrade Node.js to 22.12.0 or later.
- Update the package:
npm install --save-dev @jmlweb/eslint-config-astro@latest.
See the Changelog.
๐ License
Section titled โ๐ LicenseโMIT