Introduction
eslint-plugin-astro is ESLint plugin for Astro components.
You can check on the Online DEMO.


This plugin is in the experimental stages of development.
At least it works fine with a withastro/docs repository.
📛 What is this plugin?
ESLint plugin for Astro components.
📖 Documentation
See documents.
💿 Installation
npm install --save-dev eslint eslint-plugin-astro
If you write TypeScript in Astro components, you also need to install the @typescript-eslint/parser:
npm install --save-dev @typescript-eslint/parser
If you want to use the rules for checking accessibility (A11Y), you also need to install eslint-plugin-jsx-a11y additionally:
(It is used internally in the rules for A11Y.)
npm install --save-dev eslint-plugin-jsx-a11y
Requirements
- ESLint v7.0.0 and above
- Node.js v18.18, v20.9, v21.1 and above
📖 Usage
Configuration
New Config (eslint.config.js)
Use eslint.config.js file to configure rules. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
Example eslint.config.js:
import eslintPluginAstro from 'eslint-plugin-astro';
export default [
...eslintPluginAstro.configs.recommended,
{
rules: {
}
}
];
Example eslint.config.cjs:
const eslintPluginAstro = require('eslint-plugin-astro');
module.exports = [
...eslintPluginAstro.configs['flat/recommended'],
{
rules: {
}
}
];
This plugin provides configs:
*.configs['base'] ... Minimal configuration to enable correct Astro component linting.
*.configs['recommended'] ... Above, plus rules to prevent errors or unintended behavior.
*.configs['all'] ... Configuration enables all astro rules. It's meant for testing, not for production use because it changes with every minor and major version of the plugin. Use it at your own risk.
- Extension of sharable configuration provided by eslint-plugin-jsx-a11y. You need to install eslint-plugin-jsx-a11y to use it.
See the rule list to get the rules that this plugin provides.
Legacy Config (.eslintrc)
Use .eslintrc.* file to configure rules. See also: https://eslint.org/docs/latest/use/configure.
Example .eslintrc.js. When using the shareable configuration provided by the plugin:
module.exports = {
extends: [
"plugin:astro/recommended",
],
overrides: [
{
files: ["*.astro"],
parser: "astro-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
extraFileExtensions: [".astro"],
},
rules: {
},
},
],
}
If you do not use a shareable configuration, it is the same as the following configuration:
module.exports = {
overrides: [
{
files: ["*.astro"],
plugins: ["astro"],
env: {
node: true,
"astro/astro": true,
es2020: true,
},
parser: "astro-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
extraFileExtensions: [".astro"],
sourceType: "module",
},
rules: {
"astro/no-conflict-set-directives": "error",
"astro/no-unused-define-vars-in-style": "error",
},
},
{
files: ["**/*.astro/*.js", "*.astro/*.js"],
env: {
browser: true,
es2020: true,
},
parserOptions: {
sourceType: "module",
},
rules: {
"prettier/prettier": "off",
},
},
{
files: ["**/*.astro/*.ts", "*.astro/*.ts"],
env: {
browser: true,
es2020: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
project: null,
},
rules: {
"prettier/prettier": "off",
},
},
],
}
If you are writing client-side scripts in TypeScript and want to use @typescript-eslint/parser as the TypeScript parser, you will need to use client-side-ts processor and configure it as follows.
module.exports = {
extends: [
"plugin:astro/recommended",
],
overrides: [
{
files: ["*.astro"],
processor: "astro/client-side-ts",
rules: {
},
},
],
}
The pull request diff here is an example of introducing eslint-plugin-astro to the withastro/docs repository.
This plugin provides configs:
plugin:astro/base ... Minimal configuration to enable correct Astro component linting.
plugin:astro/recommended ... Above, plus rules to prevent errors or unintended behavior.
plugin:astro/all ... Configuration enables all astro rules. It's meant for testing, not for production use because it changes with every minor and major version of the plugin. Use it at your own risk.
- Extension of sharable configuration provided by eslint-plugin-jsx-a11y. You need to install eslint-plugin-jsx-a11y to use it.
See the rule list to get the rules that this plugin provides.
Parser Configuration
See https://github.com/ota-meshi/astro-eslint-parser#readme.
Resolving Error in JSX: Unsafe return of an any typed value
Astro supports JSX from multiple frameworks such as React, Preact, and Solid.js by defining JSX Elements as HTMLElement | any;. When a framework with a JSX type definition is not present in your project this any can cause the ESLint error @typescript-eslint/no-unsafe-return.
This can be resolved by overriding the astroHTML.JSX.Element definition with a *.d.ts file such as jsx.d.ts in your project root directory:
import "astro/astro-jsx";
declare global {
namespace JSX {
type Element = HTMLElement;
}
}
Add this *.d.ts to your tsconfig.eslint.json:
{
"extends": "./tsconfig.json",
"include": [
"jsx.d.ts"
]
}
Ensure that any necessary parserOptions in your .eslintrc.** have a project key also pointing to this config:
{
"overrides": [
{
"files": ["*.astro"],
"parser": "astro-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser",
"extraFileExtensions": [".astro"],
"project": "./tsconfig.eslint.json"
},
}
]}
Running ESLint from the command line
If you want to run eslint from the command line, make sure you include the .astro extension using a glob pattern, because ESLint targets only .js files by default.
Examples:
eslint "src/**/*.{js,astro}"
💻 Editor Integrations
Visual Studio Code
Use the dbaeumer.vscode-eslint extension that Microsoft provides officially.
You have to configure the eslint.validate option of the extension to check .astro files, because the extension targets only *.js or *.jsx files by default.
Example .vscode/settings.json:
{
"eslint.validate": [
"javascript",
"javascriptreact",
"astro",
"typescript",
"typescriptreact"
]
}
Zed
Zed has built-in support for ESLint. However, you need to configure ESLint to work with Astro files.
Example .zed/settings.json:
{
"languages": {
"Astro": {
"language_servers": ["eslint", "..."]
}
}
}
✅ Rules
The --fix option on the command line automatically fixes problems reported by rules which have a wrench 🔧 below.
The rules with the following star ⭐ are included in the plugin:astro/recommended configs.
Doesn't the rule you want exist? Share your idea of that rule with us.
Possible Errors
These rules relate to possible syntax or logic errors in Astro component code:
Security Vulnerability
These rules relate to security vulnerabilities in Astro component code:
Best Practices
These rules relate to better ways of doing things to help you avoid problems:
Stylistic Issues
These rules relate to style guidelines, and are therefore quite subjective:
A11Y Extension Rules
These rules extend the rules provided by eslint-plugin-jsx-a11y to work well in Astro component:
(You need to install eslint-plugin-jsx-a11y to use the rules.)
Extension Rules
These rules extend the rules provided by ESLint itself to work well in Astro component:
| astro/semi | Require or disallow semicolons instead of ASI | 🔧 |
🍻 Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
Development Tools
npm test runs tests and measures coverage.
npm run update runs in order to update readme and recommended configuration.
Working With Rules
This plugin uses astro-eslint-parser for the parser. Check here to find out about AST.
❤️ Supporting
If you are willing to see that this package continues to be maintained, please consider sponsoring me.

🔒 License
See the LICENSE file for license rights and limitations (MIT).