Skip to content

Commit

Permalink
fix: crash in ESM (#368)
Browse files Browse the repository at this point in the history
* fix: crash in esm

* Create late-roses-pull.md

* fix
  • Loading branch information
ota-meshi authored Apr 26, 2024
1 parent 43b808e commit d3cb2ef
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 138 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-roses-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-astro": patch
---

fix: crash in ESM
2 changes: 1 addition & 1 deletion eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
134 changes: 70 additions & 64 deletions src/configs/base.ts
Original file line number Diff line number Diff line change
@@ -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 `<script>` tag.
// Script in `<script>` is assigned a virtual file name with the `.js` extension.
files: ["**/*.astro/*.js", "*.astro/*.js"],
env: {
browser: true,
es2020: true,
},
parserOptions: {
sourceType: "module",
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a `.astro` file.
"prettier/prettier": "off",
},
},
{
// Define the configuration for `<script>` tag when using `client-side-ts` processor.
// Script in `<script>` is assigned a virtual file name with the `.ts` extension.
files: ["**/*.astro/*.ts", "*.astro/*.ts"],
env: {
browser: true,
es2020: true,
},
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
},
},
{
// Define the configuration for `<script>` tag.
// Script in `<script>` is assigned a virtual file name with the `.js` extension.
files: ["**/*.astro/*.js", "*.astro/*.js"],
env: {
browser: true,
es2020: true,
},
parserOptions: {
sourceType: "module",
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a `.astro` file.
"prettier/prettier": "off",
},
},
{
// Define the configuration for `<script>` tag when using `client-side-ts` processor.
// Script in `<script>` is assigned a virtual file name with the `.ts` extension.
files: ["**/*.astro/*.ts", "*.astro/*.ts"],
env: {
browser: true,
es2020: true,
},
parser: hasTypescriptEslintParser
? "@typescript-eslint/parser"
: undefined,
parserOptions: {
sourceType: "module",
project: null,
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a `.astro` file.
"prettier/prettier": "off",
parserOptions: {
sourceType: "module",
project: null,
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a `.astro` file.
"prettier/prettier": "off",
},
},
},
],
],
}
}
4 changes: 2 additions & 2 deletions src/plugin-config-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base from "./configs/base"
import { buildLegacyBase } from "./configs/base"
import recommended from "./configs/recommended"
import all from "./configs/all"
import flatBase from "./configs/flat/base"
Expand Down Expand Up @@ -75,7 +75,7 @@ type CJSConfigs = {
*/
export function buildCjsConfigs(): CJSConfigs {
const cjsConfigs: CJSConfigs = {
base: base as never,
base: buildLegacyBase(),
recommended: recommended as Linter.Config,
all: all as Linter.Config,
"jsx-a11y-strict": null as never as Linter.Config,
Expand Down
146 changes: 76 additions & 70 deletions tools/update-rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,89 @@ void formatAndSave(
* 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
${baseRules
.map((rule) => {
const conf = rule.meta.docs.default || "error"
return `"${rule.meta.docs.ruleId}": "${conf}"`
})
.join(",\n ")}
},
},
// 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 \`<script>\` tag.
// Script in \`<script>\` is assigned a virtual file name with the \`.js\` extension.
files: ["**/*.astro/*.js", "*.astro/*.js"],
env: {
browser: true,
es2020: true,
},
parserOptions: {
sourceType: "module",
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a \`.astro\` file.
"prettier/prettier": "off",
},
},
{
// Define the configuration for \`<script>\` tag when using \`client-side-ts\` processor.
// Script in \`<script>\` is assigned a virtual file name with the \`.ts\` extension.
files: ["**/*.astro/*.ts", "*.astro/*.ts"],
env: {
browser: true,
es2020: true,
},
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
${baseRules
.map((rule) => {
const conf = rule.meta.docs.default || "error"
return `"${rule.meta.docs.ruleId}": "${conf}"`
})
.join(",\n ")}
},
},
{
// Define the configuration for \`<script>\` tag.
// Script in \`<script>\` is assigned a virtual file name with the \`.js\` extension.
files: ["**/*.astro/*.js", "*.astro/*.js"],
env: {
browser: true,
es2020: true,
},
parserOptions: {
sourceType: "module",
parserOptions: {
sourceType: "module",
project: null,
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a \`.astro\` file.
"prettier/prettier": "off",
},
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a \`.astro\` file.
"prettier/prettier": "off",
},
},
{
// Define the configuration for \`<script>\` tag when using \`client-side-ts\` processor.
// Script in \`<script>\` is assigned a virtual file name with the \`.ts\` extension.
files: ["**/*.astro/*.ts", "*.astro/*.ts"],
env: {
browser: true,
es2020: true,
},
parser: hasTypescriptEslintParser
? "@typescript-eslint/parser"
: undefined,
parserOptions: {
sourceType: "module",
project: null,
},
rules: {
// If you are using "prettier/prettier" rule,
// you don't need to format inside <script> as it will be formatted as a \`.astro\` file.
"prettier/prettier": "off",
},
},
],
],
}
}
`,
)
Expand Down

0 comments on commit d3cb2ef

Please sign in to comment.