Skip to content

Commit

Permalink
Add support for astro component (ota-meshi#22)
Browse files Browse the repository at this point in the history
* Add support astro component

* update
  • Loading branch information
ota-meshi authored Jul 7, 2022
1 parent d287517 commit ffb2092
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
>
Expand Down Expand Up @@ -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"
]
}
Expand All @@ -84,6 +85,8 @@ Example **.vscode/settings.json**:
"vue",
// ↓ Add "svelte" language.
"svelte",
// ↓ Add "astro" language.
"astro",
]
```
Expand All @@ -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
14 changes: 14 additions & 0 deletions astro.js
Original file line number Diff line number Diff line change
@@ -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",
},
],
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"html.js",
"vue.js",
"svelte.js",
"astro.js",
"php.js",
"xml.js"
],
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/integrations/stylelint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/integrations/stylelint/src/invalid.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
let value, input, style, bar
const foo = 100 <input &&( style="color: #fff;" )&& bar > 42
---

<input class={`${value > 100 ? 'over-100' : ''}`} style="color: #00;" />
4 changes: 4 additions & 0 deletions tests/fixtures/integrations/stylelint/src/invalid.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script>
let value
</script>
<input class:over-100={ ((value > 100) ) } bind:value={value} style="color: #ff">
6 changes: 6 additions & 0 deletions tests/fixtures/integrations/stylelint/src/valid.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
let value, input, style, bar
const foo = 100 <input &&( style="color: #ff;" )&& bar > 42
---

<input class={`${value > 100 ? 'over-100' : ''}`} style="color: #000;" />
23 changes: 21 additions & 2 deletions tests/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
});
Expand All @@ -37,15 +40,31 @@ 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", () => {
try {
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!
}
});
});

0 comments on commit ffb2092

Please sign in to comment.