🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Deployment••By Komal Nakrani

Astro ESLint and Prettier Setup with Flat Config

Set up Astro ESLint with eslint-plugin-astro and a flat config, format .astro files with prettier-plugin-astro, and run both in VS Code and CI without conflicts.

#Astro#ESLint#Prettier#Tooling

To lint Astro files with ESLint, install eslint and eslint-plugin-astro, then spread eslintPluginAstro.configs.recommended into an eslint.config.js flat config. For formatting, install prettier and prettier-plugin-astro and list the plugin in .prettierrc. ESLint then catches mistakes in .astro frontmatter and templates, and Prettier formats them like any other file.

Key Takeaways

  • eslint-plugin-astro adds a parser and rules for .astro files; use it with ESLint’s flat config.
  • Install @typescript-eslint/parser if your frontmatter uses TypeScript.
  • prettier-plugin-astro formats .astro files; add it to the plugins array.
  • Let Prettier handle formatting and ESLint handle correctness, so the two never fight.

Install

# Terminal
npm install --save-dev eslint eslint-plugin-astro @typescript-eslint/parser prettier prettier-plugin-astro

ESLint flat config

// eslint.config.js
import eslintPluginAstro from 'eslint-plugin-astro';

export default [
  ...eslintPluginAstro.configs.recommended,
  {
    ignores: ['dist/', '.astro/', 'node_modules/'],
  },
  {
    rules: {
      // add or override rules here
    },
  },
];

The recommended config registers the Astro parser for .astro files and turns on rules such as astro/no-conflict-set-directives and astro/no-unused-define-vars-in-style. If you also lint plain TypeScript files, add typescript-eslint’s configs to the same array. The ignores block stops ESLint from scanning build output and Astro’s generated types.

For accessibility checks in templates, eslint-plugin-astro also exposes a jsx-a11y based config once you install eslint-plugin-jsx-a11y. Check the plugin’s README for the exact config name in your installed version.

Prettier config

{
  "plugins": ["prettier-plugin-astro"],
  "overrides": [
    {
      "files": "*.astro",
      "options": { "parser": "astro" }
    }
  ],
  "singleQuote": true,
  "printWidth": 100
}

Save it as .prettierrc. The override makes the parser explicit, which avoids “No parser could be inferred” errors in some editors. Add a .prettierignore with dist, .astro and lock files.

If you use the Tailwind CSS Prettier plugin as well, list it after the Astro plugin: "plugins": ["prettier-plugin-astro", "prettier-plugin-tailwindcss"].

Scripts

{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix",
    "format": "prettier --write .",
    "format:check": "prettier --check ."
  }
}

Run npm run lint and npm run format:check in CI, alongside astro check for type errors. Our GitHub Actions workflows guide shows a job that runs all three, and the astro check tip explains what type checking covers that ESLint does not.

Editor setup

In VS Code, install the official Astro extension plus the ESLint and Prettier extensions, then tell ESLint to validate .astro files and set Prettier as the formatter:

{
  "eslint.validate": ["javascript", "typescript", "astro"],
  "[astro]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
  "editor.formatOnSave": true
}

Save this in .vscode/settings.json so everyone on the project shares it. Our VS Code setup guide covers the Astro extension in more depth.

Keep them from conflicting

Formatting rules in ESLint and Prettier’s output can disagree. The flat recommended config from eslint-plugin-astro contains correctness rules, not style rules, so conflicts are rare. If you add a style-heavy shared config, add eslint-config-prettier last in the array to switch off the overlapping rules.

Themes in our Astro theme catalog ship as plain Astro projects, so you can drop these files in without changing anything else. The eslint-plugin-astro user guide lists every rule.

FAQ

Does ESLint support .astro files?

Yes, through eslint-plugin-astro. It provides a parser for .astro files and Astro-specific rules. Add its recommended config to eslint.config.js.

How do I format .astro files with Prettier?

Install prettier-plugin-astro and add it to the plugins array in .prettierrc. Prettier then formats frontmatter, template markup, <style> and <script> blocks.

Do I need @typescript-eslint/parser for Astro?

If the frontmatter or scripts in your .astro files use TypeScript, yes. The Astro parser hands TypeScript code to it.

Should I use ESLint or astro check?

Both. astro check reports TypeScript and template type errors. ESLint finds code-quality problems such as unused variables and conflicting directives.