Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix work with less files after #360 #363

Merged
merged 2 commits into from
Jul 17, 2024
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
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