From ffb209267005fc86bdd23eb32ddcd894f9afcf11 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Thu, 7 Jul 2022 22:07:04 +0900 Subject: [PATCH] Add support for astro component (#22) * Add support astro component * update --- README.md | 6 ++++- astro.js | 14 +++++++++++ index.js | 1 + package.json | 1 + .../integrations/stylelint/package.json | 2 +- .../integrations/stylelint/src/invalid.astro | 6 +++++ .../integrations/stylelint/src/invalid.svelte | 4 ++++ .../integrations/stylelint/src/valid.astro | 6 +++++ tests/lib/index.js | 23 +++++++++++++++++-- 9 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 astro.js create mode 100644 tests/fixtures/integrations/stylelint/src/invalid.astro create mode 100644 tests/fixtures/integrations/stylelint/src/invalid.svelte create mode 100644 tests/fixtures/integrations/stylelint/src/valid.astro diff --git a/README.md b/README.md index 9906ec9..139b011 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ > The shareable HTML (and HTML-like) config for [Stylelint]. This config bundles the [`postcss-html` custom syntax](https://github.com/ota-meshi/postcss-html) and configures it. -If you use this config in your Stylelint config, HTML, XML, [Vue], [Svelte] and [PHP] files will be parsable. The Stylelint rules you have configured will be able to check these files. +If you use this config in your Stylelint config, HTML, XML, [Vue], [Svelte], [Astro], and [PHP] files will be parsable. The Stylelint rules you have configured will be able to check these files. > **Requirements** > @@ -59,6 +59,7 @@ If you want to enable parsing for only specific language, use each language conf "stylelint-config-html/xml", "stylelint-config-html/vue", "stylelint-config-html/svelte", + "stylelint-config-html/astro", "stylelint-config-html/php" ] } @@ -84,6 +85,8 @@ Example **.vscode/settings.json**: "vue", // ↓ Add "svelte" language. "svelte", + // ↓ Add "astro" language. + "astro", ] ``` @@ -94,5 +97,6 @@ See the [LICENSE](LICENSE) file for license rights and limitations (MIT). [Stylelint]: https://stylelint.io/ [Vue]: https://v3.vuejs.org/guide/single-file-component.html [Svelte]: https://svelte.dev/docs#Component_format +[Astro]: https://docs.astro.build/core-concepts/astro-components/ [PHP]: https://www.php.net/manual/en/intro-whatis.php [PostCss]: https://github.com/postcss/postcss diff --git a/astro.js b/astro.js new file mode 100644 index 0000000..c5a40f0 --- /dev/null +++ b/astro.js @@ -0,0 +1,14 @@ +"use strict"; + +const extensions = [ + // https://github.com/withastro/language-tools/blob/main/packages/vscode/package.json + ".astro", +]; +module.exports = { + overrides: [ + { + files: extensions.flatMap((ext) => [`*${ext}`, `**/*${ext}`]), + customSyntax: "postcss-html", + }, + ], +}; diff --git a/index.js b/index.js index c9fd8ce..d5f411c 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ module.exports = { require.resolve("./vue.js"), require.resolve("./php.js"), require.resolve("./svelte.js"), + require.resolve("./astro.js"), require.resolve("./xml.js"), ], }; diff --git a/package.json b/package.json index d97aca7..3a31869 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "html.js", "vue.js", "svelte.js", + "astro.js", "php.js", "xml.js" ], diff --git a/tests/fixtures/integrations/stylelint/package.json b/tests/fixtures/integrations/stylelint/package.json index 7676b09..f760a43 100644 --- a/tests/fixtures/integrations/stylelint/package.json +++ b/tests/fixtures/integrations/stylelint/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "description": "", "devDependencies": { - "postcss-html": "^1.0.1", + "postcss-html": "^1.5.0", "stylelint": "^14.0.0-0", "stylelint-config-html": "file:../../../../", "stylelint-config-recommended": "^6.0.0-0" diff --git a/tests/fixtures/integrations/stylelint/src/invalid.astro b/tests/fixtures/integrations/stylelint/src/invalid.astro new file mode 100644 index 0000000..3082465 --- /dev/null +++ b/tests/fixtures/integrations/stylelint/src/invalid.astro @@ -0,0 +1,6 @@ +--- +let value, input, style, bar +const foo = 100 42 +--- + + 100 ? 'over-100' : ''}`} style="color: #00;" /> diff --git a/tests/fixtures/integrations/stylelint/src/invalid.svelte b/tests/fixtures/integrations/stylelint/src/invalid.svelte new file mode 100644 index 0000000..e8cab4f --- /dev/null +++ b/tests/fixtures/integrations/stylelint/src/invalid.svelte @@ -0,0 +1,4 @@ + + 100) ) } bind:value={value} style="color: #ff"> diff --git a/tests/fixtures/integrations/stylelint/src/valid.astro b/tests/fixtures/integrations/stylelint/src/valid.astro new file mode 100644 index 0000000..0a98079 --- /dev/null +++ b/tests/fixtures/integrations/stylelint/src/valid.astro @@ -0,0 +1,6 @@ +--- +let value, input, style, bar +const foo = 100 42 +--- + + 100 ? 'over-100' : ''}`} style="color: #000;" /> diff --git a/tests/lib/index.js b/tests/lib/index.js index 8419adc..f7b78b0 100644 --- a/tests/lib/index.js +++ b/tests/lib/index.js @@ -29,6 +29,9 @@ describe("Integration with stylelint", () => { it("should lint without errors with svelte", () => { cp.execSync(`${STYLELINT} src/valid.svelte`, { stdio: "inherit" }); }); + it("should lint without errors with astro", () => { + cp.execSync(`${STYLELINT} src/valid.astro`, { stdio: "inherit" }); + }); it("should lint without errors with php", () => { cp.execSync(`${STYLELINT} src/valid.php`, { stdio: "inherit" }); }); @@ -37,7 +40,7 @@ describe("Integration with stylelint", () => { cp.execSync(`${STYLELINT} src/invalid.html`, { stdio: "inherit" }); fail("Expect an error, but without errors"); } catch { - // Expected!s + // Expected! } }); it("should lint with errors with vue", () => { @@ -45,7 +48,23 @@ describe("Integration with stylelint", () => { cp.execSync(`${STYLELINT} src/invalid.vue`, { stdio: "inherit" }); fail("Expect an error, but without errors"); } catch { - // Expected!s + // Expected! + } + }); + it("should lint with errors with svelte", () => { + try { + cp.execSync(`${STYLELINT} src/invalid.svelte`, { stdio: "inherit" }); + fail("Expect an error, but without errors"); + } catch { + // Expected! + } + }); + it("should lint with errors with astro", () => { + try { + cp.execSync(`${STYLELINT} src/invalid.astro`, { stdio: "inherit" }); + fail("Expect an error, but without errors"); + } catch { + // Expected! } }); });