Astro component parser for ESLint
88
stars
544
commits
TypeScript
primary language
Sep 10, 2026
updated
Astro component parser for ESLint.
You can check it on Online DEMO.
This parser is in the experimental stages of development.
At least it works fine with a withastro/docs repository.
This parser allows us to lint the script of .astro files.
Note that this parser alone will not lint the scripts inside the
<script>tag. Use eslint-plugin-astro to lint the script inside the<script>tag as well.
ESLint plugin for Astro component.
npm install --save-dev eslint astro-eslint-parser
This package is ESM-only. Use import to load it from JavaScript config files.
CommonJS require("astro-eslint-parser") is not supported.
First, we recommend using eslint-plugin-astro rather than just the parser.
The following examples are for introducing only the parser. This is not useful for most people. It can be useful if you create your own plugin.
Configure languageOptions.parser for .astro files in your eslint.config.* file.
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
},
},
]
If you have specified the extension in the CLI, add .astro as well.
$ eslint "src/**/*.{js,astro}"
# or
$ eslint src --ext .js,.astro
The commit diff here is an example of introducing this parser to the astro.build repository.
Import this package from the package root:
import * as astroParser from "astro-eslint-parser"
parserOptions has the same properties as what espree, the default parser of ESLint, is supporting.
For example:
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
sourceType: "module",
ecmaVersion: 2021,
ecmaFeatures: {
globalReturn: false,
impliedStrict: false,
jsx: false,
},
},
},
},
]
You can use parserOptions.parser property to specify a custom parser to parse scripts.
Other properties than parser would be given to the specified parser.
For example:
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: "@typescript-eslint/parser",
},
},
},
]
For example, if you are using the "@typescript-eslint/parser", and if you want to use TypeScript in .astro, you need to add more parserOptions configuration.
import tsParser from "@typescript-eslint/parser"
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: tsParser,
project: "path/to/your/tsconfig.json",
extraFileExtensions: [".astro"],
},
},
},
]
You can also give different parsers for different languages.
import tsParser from "@typescript-eslint/parser"
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: {
ts: tsParser,
js: "espree",
},
},
},
},
]
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"
]
}
Most of the rules in the ESLint core work for the script part, but some rules are incompatible.
This parser will generate a JSX compatible AST for most of the HTML part of the Astro component. Therefore, some rules of eslint-plugin-react may work.
For example, the react/jsx-no-target-blank rule works fine.
If this parser is used with @typescript-eslint/parser and parserOptions.project is set, it will temporarily create a .tsx file to parse the .astro file.
This parser works by converting the .astro file to JSX and letting the JavaScript parser parse it.
Since @typescript-eslint/parser can only parse files with the extension .tsx as JSX, it is necessary to temporarily create a .tsx file. Temporarily created files will try to be deleted after parses, but if the parsing takes a long time, the files may be visible to you.
See also @typescript-eslint/parser readme.
Welcome contributing!
Please use GitHub's Issues/PRs.
If you are willing to see that this package continues to be maintained, please consider sponsoring me.
See the LICENSE file for license rights and limitations (MIT).
TypeScript
78.3%
JavaScript
11.7%
Svelte
7.4%
Astro
1.8%
Astro component parser for ESLint
88
stars
544
commits
TypeScript
primary language
Sep 10, 2026
updated
Astro component parser for ESLint.
You can check it on Online DEMO.
This parser is in the experimental stages of development.
At least it works fine with a withastro/docs repository.
This parser allows us to lint the script of .astro files.
Note that this parser alone will not lint the scripts inside the
<script>tag. Use eslint-plugin-astro to lint the script inside the<script>tag as well.
ESLint plugin for Astro component.
npm install --save-dev eslint astro-eslint-parser
This package is ESM-only. Use import to load it from JavaScript config files.
CommonJS require("astro-eslint-parser") is not supported.
First, we recommend using eslint-plugin-astro rather than just the parser.
The following examples are for introducing only the parser. This is not useful for most people. It can be useful if you create your own plugin.
Configure languageOptions.parser for .astro files in your eslint.config.* file.
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
},
},
]
If you have specified the extension in the CLI, add .astro as well.
$ eslint "src/**/*.{js,astro}"
# or
$ eslint src --ext .js,.astro
The commit diff here is an example of introducing this parser to the astro.build repository.
Import this package from the package root:
import * as astroParser from "astro-eslint-parser"
parserOptions has the same properties as what espree, the default parser of ESLint, is supporting.
For example:
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
sourceType: "module",
ecmaVersion: 2021,
ecmaFeatures: {
globalReturn: false,
impliedStrict: false,
jsx: false,
},
},
},
},
]
You can use parserOptions.parser property to specify a custom parser to parse scripts.
Other properties than parser would be given to the specified parser.
For example:
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: "@typescript-eslint/parser",
},
},
},
]
For example, if you are using the "@typescript-eslint/parser", and if you want to use TypeScript in .astro, you need to add more parserOptions configuration.
import tsParser from "@typescript-eslint/parser"
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: tsParser,
project: "path/to/your/tsconfig.json",
extraFileExtensions: [".astro"],
},
},
},
]
You can also give different parsers for different languages.
import tsParser from "@typescript-eslint/parser"
import * as astroParser from "astro-eslint-parser"
export default [
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: {
ts: tsParser,
js: "espree",
},
},
},
},
]
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"
]
}
Most of the rules in the ESLint core work for the script part, but some rules are incompatible.
This parser will generate a JSX compatible AST for most of the HTML part of the Astro component. Therefore, some rules of eslint-plugin-react may work.
For example, the react/jsx-no-target-blank rule works fine.
If this parser is used with @typescript-eslint/parser and parserOptions.project is set, it will temporarily create a .tsx file to parse the .astro file.
This parser works by converting the .astro file to JSX and letting the JavaScript parser parse it.
Since @typescript-eslint/parser can only parse files with the extension .tsx as JSX, it is necessary to temporarily create a .tsx file. Temporarily created files will try to be deleted after parses, but if the parsing takes a long time, the files may be visible to you.
See also @typescript-eslint/parser readme.
Welcome contributing!
Please use GitHub's Issues/PRs.
If you are willing to see that this package continues to be maintained, please consider sponsoring me.
See the LICENSE file for license rights and limitations (MIT).
TypeScript
78.3%
JavaScript
11.7%
Svelte
7.4%
Astro
1.8%