-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: client-side scripts not being able to linting in flat configs (#334
) * fix: client-side scripts not being able to linting in flat configs * Create moody-pumpkins-carry.md
- Loading branch information
Showing
5 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eslint-plugin-astro": patch | ||
--- | ||
|
||
fix: client-side scripts not being able to linting in flat configs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { ESLint } from "eslint" | ||
import astroPlugin from "../../../src/index" | ||
import assert from "assert" | ||
import Module from "module" | ||
import semver from "semver" | ||
|
||
describe("Integration test for client-side script", () => { | ||
// @ts-expect-error -- ignore | ||
const originalLoad = Module._load | ||
before(() => { | ||
// @ts-expect-error -- ignore | ||
Module._load = function (name, ...args) { | ||
if (name === "eslint-plugin-astro") { | ||
return astroPlugin | ||
} | ||
return originalLoad(name, ...args) | ||
} | ||
}) | ||
after(() => { | ||
// @ts-expect-error -- ignore | ||
Module._load = originalLoad | ||
}) | ||
it("should work with astro processor", async () => { | ||
const eslint = semver.lt(ESLint.version, "9.0.0-0") | ||
? new ESLint({ | ||
plugins: { | ||
astro: astroPlugin as any, | ||
}, | ||
useEslintrc: false, | ||
overrideConfig: { | ||
extends: ["plugin:astro/base"], | ||
rules: { | ||
"no-restricted-syntax": ["error", "Identifier[name='id']"], | ||
} as Record<string, any>, | ||
}, | ||
}) | ||
: new ESLint({ | ||
overrideConfigFile: true as any, | ||
// @ts-expect-error -- typing bug | ||
overrideConfig: [ | ||
...astroPlugin.configs["flat/base"], | ||
{ | ||
rules: { | ||
"no-restricted-syntax": ["error", "Identifier[name='id']"], | ||
} as Record<string, any>, | ||
}, | ||
], | ||
}) | ||
|
||
const result = await eslint.lintText( | ||
` | ||
<script> | ||
let id | ||
</script> | ||
`, | ||
{ filePath: "path/to/test.astro" }, | ||
) | ||
|
||
assert.deepStrictEqual( | ||
result | ||
.flatMap((r) => r.messages) | ||
.map((m) => ({ ruleId: m.ruleId, message: m.message })), | ||
[ | ||
{ | ||
message: "Using 'Identifier[name='id']' is not allowed.", | ||
ruleId: "no-restricted-syntax", | ||
}, | ||
], | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters