Skip to content

Commit 9a92eb2

Browse files
authored
Fix work with less files after #360 (#363)
* add test for less (issue #362) * fix issue #362
1 parent 646ed9a commit 9a92eb2

File tree

6 files changed

+347
-310
lines changed

6 files changed

+347
-310
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const ruleFunction = (expectation, options, context) => {
106106

107107
let prettierSource;
108108

109-
const source = root.toString();
109+
const source = root.toString(result.opts.syntax);
110110
try {
111111
prettierSource = await prettier.format(source, prettierOptions);
112112
} catch (err) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"eslint-plugin-prettier": "^5.0.0",
4747
"postcss": "^8.4.25",
4848
"postcss-html": "^1.5.0",
49+
"postcss-less": "^6.0.0",
4950
"postcss-markdown": "^1.2.0",
5051
"postcss-scss": "^4.0.6",
5152
"postcss-styled-syntax": "^0.5.0",

test/fixtures/check.invalid.less

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.foo {
2+
background-image: url("x");
3+
}
4+
5+
@map: {
6+
alpha: 10;
7+
beta: 20;
8+
gamma: 30
9+
};
10+
11+
.node {
12+
.someMixinName(value); // inline
13+
}

test/fixtures/stylelint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export default {
1515
files: ['**/*.scss'],
1616
customSyntax: 'postcss-scss',
1717
},
18+
{
19+
files: ['**/*.less'],
20+
customSyntax: 'postcss-less',
21+
},
1822
{
1923
files: ['**/*.{js,jsx,tsx}'],
2024
customSyntax: 'postcss-styled-syntax',

test/stylelint-prettier-e2e.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ describe('E2E Tests', () => {
4444
assert.strictEqual(result.status, 2);
4545
});
4646

47+
test('LESS files', () => {
48+
const result = runStylelint('*.less');
49+
50+
const expectedResult = `
51+
::error file=check.invalid.less,line=2,col=25,endLine=2,endColumn=28,title=Stylelint problem::Replace ""x"" with "'x'" (prettier/prettier)
52+
::error file=check.invalid.less,line=8,col=12,endLine=8,endColumn=13,title=Stylelint problem::Insert ";" (prettier/prettier)
53+
::error file=check.invalid.less,line=12,col=1,endLine=12,endColumn=2,title=Stylelint problem::Insert "··" (prettier/prettier)
54+
`.trim();
55+
56+
assert.strictEqual(result.output, '');
57+
assert.strictEqual(result.error, expectedResult);
58+
assert.strictEqual(result.status, 2);
59+
});
60+
4761
/**
4862
* Don't act upon html-like files, as prettier already handles them as whole
4963
* files

0 commit comments

Comments
 (0)