Skip to content

Commit

Permalink
Add custom-property-empty-line-before test case by using custom syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Apr 9, 2023
1 parent 0d6af14 commit b1e2007
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/__tests__/fixtures/postcss-naive-css-in-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const postcss = require('postcss');

/**
* @type {postcss.Parser<postcss.Document>}
*/
function parse(css) {
const source = typeof css === 'string' ? css : css.toString();

const document = postcss.document({
source: {
input: new postcss.Input(source),
},
});

// E.g. "css` color: red; `;"
for (const match of source.matchAll(/\bcss`([^`]+)`;/g)) {
document.append(postcss.parse(match[1]));
}

return document;
}

/**
* @type {postcss.Stringifier}
*/
function stringify(node, builder) {
if (node.type === 'document') {
node.each((root) => {
builder(`css\`${root}\`;`, root);
});
}
}

module.exports = { parse, stringify };
14 changes: 14 additions & 0 deletions lib/rules/custom-property-empty-line-before/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const naiveCssInJs = require('../../../__tests__/fixtures/postcss-naive-css-in-js');

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -570,3 +572,15 @@ testRule({
},
],
});

testRule({
ruleName,
config: ['always', { except: ['first-nested'] }],
customSyntax: naiveCssInJs,

accept: [
{
code: 'css` --foo: 100px; `;',
},
],
});

0 comments on commit b1e2007

Please sign in to comment.