Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chubby-donkeys-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Added: support for `customSyntax` with function export
13 changes: 13 additions & 0 deletions lib/__tests__/standalone-syntax.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ it('standalone with custom syntax as npm package', async () => {
expect(results[0].warnings[0]).toMatchObject({ line: 2, column: 3, rule: 'block-no-empty' });
});

it('standalone with custom syntax as npm package and function export', async () => {
const { results } = await standalone({
config: config(),
customSyntax: (await import('postcss-html')).default,
code: '<style>foo {}</style>',
formatter: stringFormatter,
});

expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0]).toMatchObject({ line: 1, column: 12, rule: 'block-no-empty' });
});

it('rejects on unknown custom syntax option', async () => {
await expect(
standalone({
Expand Down
2 changes: 1 addition & 1 deletion lib/getPostcssResult.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/getPostcssResult.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async function getCustomSyntax(customSyntax, basedir) {
return resolved;
}

if (typeof customSyntax === 'object') {
if (typeof customSyntax === 'object' || typeof customSyntax === 'function') {
if (typeof customSyntax.parse === 'function') {
return { ...customSyntax };
}
Expand Down
Loading