From d3cb2ef1ecad35a121a83e6b7ecc0bf85a00b414 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 26 Apr 2024 17:07:57 +0900 Subject: [PATCH] fix: crash in ESM (#368) * fix: crash in esm * Create late-roses-pull.md * fix --- .changeset/late-roses-pull.md | 5 ++ eslint.config.cjs | 2 +- package.json | 2 +- src/configs/base.ts | 134 ++++++++++++++++--------------- src/plugin-config-builder.ts | 4 +- tools/update-rulesets.ts | 146 ++++++++++++++++++---------------- 6 files changed, 155 insertions(+), 138 deletions(-) create mode 100644 .changeset/late-roses-pull.md diff --git a/.changeset/late-roses-pull.md b/.changeset/late-roses-pull.md new file mode 100644 index 00000000..73634b31 --- /dev/null +++ b/.changeset/late-roses-pull.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-astro": patch +--- + +fix: crash in ESM diff --git a/eslint.config.cjs b/eslint.config.cjs index c7fed0c1..da659565 100644 --- a/eslint.config.cjs +++ b/eslint.config.cjs @@ -2,7 +2,7 @@ const myPlugin = require("@ota-meshi/eslint-plugin") const tseslint = require("typescript-eslint") -const allConfig = require("eslint-plugin-astro").configs.all +const allConfig = require("./node_modules/eslint-plugin-astro").configs.all module.exports = [ { ignores: [ diff --git a/package.json b/package.json index 4bd93fca..23d8084e 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "esbuild-register": "^3.3.3", "eslint": "^9.0.0", "eslint-config-prettier": "^9.0.0", - "eslint-plugin-astro": "^0.34.0", + "eslint-plugin-astro": "^1.0.2", "eslint-plugin-eslint-plugin": "^6.0.0", "eslint-plugin-jsdoc": "^48.2.3", "eslint-plugin-json-schema-validator": "^5.0.0", diff --git a/src/configs/base.ts b/src/configs/base.ts index 27de33ef..4080d274 100644 --- a/src/configs/base.ts +++ b/src/configs/base.ts @@ -1,75 +1,81 @@ // IMPORTANT! // This file has been automatically generated, // in order to update its content execute "npm run update" +import type { Linter } from "eslint" import { hasTypescriptEslintParser } from "./has-typescript-eslint-parser" -export default { - plugins: ["astro"], - overrides: [ - { - // Define the configuration for `.astro` file. - files: ["*.astro"], - // Enable this plugin - plugins: ["astro"], - env: { - // Enables global variables available in Astro components. - node: true, - "astro/astro": true, - es2020: true, +/** + * Build legacy base config + */ +export function buildLegacyBase(): Linter.Config { + return { + plugins: ["astro"], + overrides: [ + { + // Define the configuration for `.astro` file. + files: ["*.astro"], + // Enable this plugin + plugins: ["astro"], + env: { + // Enables global variables available in Astro components. + node: true, + "astro/astro": true, + es2020: true, + }, + // Allows Astro components to be parsed. + parser: require.resolve("astro-eslint-parser"), + // Parse the script in `.astro` as TypeScript by adding the following configuration. + parserOptions: { + parser: hasTypescriptEslintParser + ? "@typescript-eslint/parser" + : undefined, + extraFileExtensions: [".astro"], + // The script of Astro components uses ESM. + sourceType: "module", + }, + rules: { + // eslint-plugin-astro rules + // Enable base rules + }, }, - // Allows Astro components to be parsed. - parser: require.resolve("astro-eslint-parser"), - // Parse the script in `.astro` as TypeScript by adding the following configuration. - parserOptions: { + { + // Define the configuration for `