-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for flat config (#324)
* feat: add support for flat config * Create silly-balloons-double.md * fix * fix
- Loading branch information
Showing
17 changed files
with
481 additions
and
65 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": minor | ||
--- | ||
|
||
feat: add support for flat config |
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
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
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,19 @@ | ||
import recommended from "./recommended" | ||
import { rules } from "../../utils/rules" | ||
|
||
const all: Record<string, string> = {} | ||
for (const rule of rules.filter( | ||
(rule) => rule.meta.docs.available() && !rule.meta.deprecated, | ||
)) { | ||
all[rule.meta.docs.ruleId] = "error" | ||
} | ||
|
||
export default [ | ||
...recommended, | ||
{ | ||
rules: { | ||
...all, | ||
...recommended[recommended.length - 1].rules, | ||
}, | ||
}, | ||
] |
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,74 @@ | ||
// IMPORTANT! | ||
// This file has been automatically generated, | ||
// in order to update its content execute "npm run update" | ||
import globals from "globals" | ||
import type { ESLint } from "eslint" | ||
import * as parser from "astro-eslint-parser" | ||
import { tsESLintParser } from "../has-typescript-eslint-parser" | ||
import { environments } from "../../environments/index" | ||
export default [ | ||
{ | ||
plugins: { | ||
get astro(): ESLint.Plugin { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore | ||
return require("../../index") | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: ["*.astro", "**/*.astro"], | ||
languageOptions: { | ||
globals: { | ||
...globals.node, | ||
...environments.astro.globals, | ||
}, | ||
parser, | ||
// The script of Astro components uses ESM. | ||
sourceType: "module", | ||
parserOptions: { | ||
parser: tsESLintParser ?? undefined, | ||
extraFileExtensions: [".astro"], | ||
}, | ||
}, | ||
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"], | ||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
}, | ||
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"], | ||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
}, | ||
parser: tsESLintParser ?? undefined, | ||
sourceType: "module", | ||
parserOptions: { | ||
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", | ||
}, | ||
}, | ||
] |
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,19 @@ | ||
// IMPORTANT! | ||
// This file has been automatically generated, | ||
// in order to update its content execute "npm run update" | ||
import base from "./base" | ||
export default [ | ||
...base, | ||
{ | ||
rules: { | ||
// eslint-plugin-astro rules | ||
"astro/no-conflict-set-directives": "error", | ||
"astro/no-deprecated-astro-canonicalurl": "error", | ||
"astro/no-deprecated-astro-fetchcontent": "error", | ||
"astro/no-deprecated-astro-resolve": "error", | ||
"astro/no-deprecated-getentrybyslug": "error", | ||
"astro/no-unused-define-vars-in-style": "error", | ||
"astro/valid-compile": "error", | ||
}, | ||
}, | ||
] |
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
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,92 @@ | ||
import assert from "assert" | ||
import plugin from "../../../src/index" | ||
import { LegacyESLint, FlatESLint } from "../../utils/eslint-compat" | ||
|
||
const code = `--- | ||
const foo = 42 | ||
--- | ||
<style define:vars={{ foregroundColor, backgroundColor }}> | ||
h1 { | ||
background-color: var(--backgroundColor); | ||
color: var(--foreground); | ||
} | ||
</style> | ||
` | ||
describe("`recommended` config", () => { | ||
it("legacy `recommended` config should work. ", async () => { | ||
const linter = new LegacyESLint({ | ||
plugins: { | ||
toml: plugin as never, | ||
}, | ||
baseConfig: { | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
}, | ||
extends: ["plugin:astro/recommended"], | ||
}, | ||
useEslintrc: false, | ||
}) | ||
const result = await linter.lintText(code, { filePath: "test.astro" }) | ||
const messages = result[0].messages | ||
|
||
assert.deepStrictEqual( | ||
messages.map((m) => ({ | ||
ruleId: m.ruleId, | ||
line: m.line, | ||
message: m.message, | ||
})), | ||
[ | ||
{ | ||
line: 4, | ||
message: "'foregroundColor' is defined but never used.", | ||
ruleId: "astro/no-unused-define-vars-in-style", | ||
}, | ||
], | ||
) | ||
}) | ||
it("`flat/recommended` config should work. ", async () => { | ||
const linter = new FlatESLint({ | ||
// @ts-expect-error -- typing bug | ||
overrideConfigFile: true, | ||
// @ts-expect-error -- typing bug | ||
overrideConfig: [...plugin.configs["flat/recommended"]], | ||
}) | ||
const result = await linter.lintText(code, { filePath: "test.astro" }) | ||
const messages = result[0].messages | ||
|
||
assert.deepStrictEqual( | ||
messages.map((m) => ({ | ||
ruleId: m.ruleId, | ||
line: m.line, | ||
message: m.message, | ||
})), | ||
[ | ||
{ | ||
line: 4, | ||
message: "'foregroundColor' is defined but never used.", | ||
ruleId: "astro/no-unused-define-vars-in-style", | ||
}, | ||
], | ||
) | ||
}) | ||
it("`flat/recommended` config with *.js should work. ", async () => { | ||
const linter = new FlatESLint({ | ||
// @ts-expect-error -- typing bug | ||
overrideConfigFile: true, | ||
// @ts-expect-error -- typing bug | ||
overrideConfig: [...plugin.configs["flat/recommended"]], | ||
}) | ||
|
||
const result = await linter.lintText(";", { filePath: "test.js" }) | ||
const messages = result[0].messages | ||
|
||
assert.deepStrictEqual( | ||
messages.map((m) => ({ | ||
ruleId: m.ruleId, | ||
line: m.line, | ||
message: m.message, | ||
})), | ||
[], | ||
) | ||
}) | ||
}) |
Oops, something went wrong.