Skip to content

Commit

Permalink
Fix work with less files after #360 (#363)
Browse files Browse the repository at this point in the history
* add test for less (issue #362)

* fix issue #362
  • Loading branch information
dartess authored Jul 17, 2024
1 parent 646ed9a commit 9a92eb2
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 310 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const ruleFunction = (expectation, options, context) => {

let prettierSource;

const source = root.toString();
const source = root.toString(result.opts.syntax);
try {
prettierSource = await prettier.format(source, prettierOptions);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"eslint-plugin-prettier": "^5.0.0",
"postcss": "^8.4.25",
"postcss-html": "^1.5.0",
"postcss-less": "^6.0.0",
"postcss-markdown": "^1.2.0",
"postcss-scss": "^4.0.6",
"postcss-styled-syntax": "^0.5.0",
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/check.invalid.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.foo {
background-image: url("x");
}

@map: {
alpha: 10;
beta: 20;
gamma: 30
};

.node {
.someMixinName(value); // inline
}
4 changes: 4 additions & 0 deletions test/fixtures/stylelint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default {
files: ['**/*.scss'],
customSyntax: 'postcss-scss',
},
{
files: ['**/*.less'],
customSyntax: 'postcss-less',
},
{
files: ['**/*.{js,jsx,tsx}'],
customSyntax: 'postcss-styled-syntax',
Expand Down
14 changes: 14 additions & 0 deletions test/stylelint-prettier-e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ describe('E2E Tests', () => {
assert.strictEqual(result.status, 2);
});

test('LESS files', () => {
const result = runStylelint('*.less');

const expectedResult = `
::error file=check.invalid.less,line=2,col=25,endLine=2,endColumn=28,title=Stylelint problem::Replace ""x"" with "'x'" (prettier/prettier)
::error file=check.invalid.less,line=8,col=12,endLine=8,endColumn=13,title=Stylelint problem::Insert ";" (prettier/prettier)
::error file=check.invalid.less,line=12,col=1,endLine=12,endColumn=2,title=Stylelint problem::Insert "··" (prettier/prettier)
`.trim();

assert.strictEqual(result.output, '');
assert.strictEqual(result.error, expectedResult);
assert.strictEqual(result.status, 2);
});

/**
* Don't act upon html-like files, as prettier already handles them as whole
* files
Expand Down
Loading

0 comments on commit 9a92eb2

Please sign in to comment.