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 inaccurate customSyntax inference #6645

Merged
merged 1 commit into from Feb 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-humans-hunt.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: inaccurate `customSyntax` inference
8 changes: 8 additions & 0 deletions lib/__tests__/overrides.test.js
Expand Up @@ -204,6 +204,7 @@ describe('single input file. all overrides are matching', () => {

// https://github.com/stylelint/stylelint/issues/5656
it('priority to apply overrides (scss): scss extends', async () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
const linted = await standalone({
files: [path.join(fixturesPath, 'style.scss')],
config: {
Expand All @@ -220,10 +221,14 @@ describe('single input file. all overrides are matching', () => {

expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(0);

expect(warn).toHaveBeenCalledWith(expect.stringMatching(/use the "customSyntax" option/));
warn.mockRestore();
});

// https://github.com/stylelint/stylelint/issues/5656
it('priority to apply overrides (scss): apply rules', async () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
const linted = await standalone({
files: [path.join(fixturesPath, 'style.scss')],
config: {
Expand All @@ -243,6 +248,9 @@ describe('single input file. all overrides are matching', () => {
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('at-rule-no-unknown');

expect(warn).toHaveBeenCalledWith(expect.stringMatching(/use the "customSyntax" option/));
warn.mockRestore();
});
});

Expand Down
22 changes: 2 additions & 20 deletions lib/getPostcssResult.js
Expand Up @@ -117,24 +117,6 @@ function getCustomSyntax(customSyntax, basedir) {
throw new Error('Custom syntax must be a string or a Syntax object');
}

/** @type {{ [key: string]: string }} */
const previouslyInferredExtensions = {
html: 'postcss-html',
js: '@stylelint/postcss-css-in-js',
jsx: '@stylelint/postcss-css-in-js',
less: 'postcss-less',
md: 'postcss-markdown',
sass: 'postcss-sass',
sss: 'sugarss',
scss: 'postcss-scss',
svelte: 'postcss-html',
ts: '@stylelint/postcss-css-in-js',
tsx: '@stylelint/postcss-css-in-js',
vue: 'postcss-html',
xml: 'postcss-html',
xst: 'postcss-html',
};

/**
* @param {StylelintInternalApi} stylelint
* @param {string|undefined} filePath
Expand All @@ -144,9 +126,9 @@ function cssSyntax(stylelint, filePath) {
const fileExtension = filePath ? path.extname(filePath).slice(1).toLowerCase() : '';
const extensions = ['css', 'pcss', 'postcss'];

if (previouslyInferredExtensions[fileExtension]) {
if (fileExtension && !extensions.includes(fileExtension)) {
console.warn(
`${filePath}: When linting something other than CSS, you should install an appropriate syntax, e.g. "${previouslyInferredExtensions[fileExtension]}", and use the "customSyntax" option`,
`${filePath}: you should use the "customSyntax" option when linting something other than CSS`,
);
}

Expand Down