Skip to content

Commit

Permalink
Show more info in missing customSyntax warning (#5611)
Browse files Browse the repository at this point in the history
* Show more info in missing customSyntax warning

* Change markdown syntax

* Update lib/getPostcssResult.js

Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>

Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
  • Loading branch information
hudochenkov and ybiquitous committed Oct 21, 2021
1 parent 2eee0a9 commit 8dca498
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
7 changes: 6 additions & 1 deletion lib/__tests__/standalone-syntax.test.js
Expand Up @@ -9,6 +9,9 @@ const { promises: fs } = require('fs');
const fixturesPath = replaceBackslashes(path.join(__dirname, 'fixtures'));

it('standalone with postcss-safe-parser', () => {
// Hide “When linting something other than CSS...” warning from test
jest.spyOn(console, 'warn').mockImplementation(() => {});

return standalone({
files: `${fixturesPath}/syntax_error.*`,
config: {
Expand Down Expand Up @@ -47,7 +50,9 @@ it('standalone with postcss-safe-parser', () => {

return fs.writeFile(root.source.input.file, root.source.input.css);
}),
);
).then(() => {
jest.restoreAllMocks();
});
});
});

Expand Down
39 changes: 20 additions & 19 deletions lib/getPostcssResult.js
Expand Up @@ -13,23 +13,6 @@ const { promises: fs } = require('fs');

const postcssProcessor = postcss();

const previouslyInferedExtensions = [
'html',
'js',
'jsx',
'less',
'md',
'sass',
'sss',
'scss',
'svelte',
'ts',
'tsx',
'vue',
'xml',
'xst',
];

/**
* @param {StylelintInternalApi} stylelint
* @param {GetPostcssOptions} options
Expand Down Expand Up @@ -145,6 +128,24 @@ function getCustomSyntax(customSyntax) {
throw new Error(`Custom syntax must be a string or a Syntax object`);
}

/** @type {{ [key: string]: string }} */
const previouslyInferedExtensions = {
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 @@ -160,9 +161,9 @@ function cssSyntax(stylelint, filePath) {

const extensions = ['css', 'pcss', 'postcss'];

if (previouslyInferedExtensions.includes(fileExtension)) {
if (previouslyInferedExtensions[fileExtension]) {
console.warn(
'When linting something other than CSS, you should install an appropriate syntax, e.g. postcss-scss, and use the "customSyntax" option',
`${filePath}: When linting something other than CSS, you should install an appropriate syntax, e.g. "${previouslyInferedExtensions[fileExtension]}", and use the "customSyntax" option`,
);
}

Expand Down

0 comments on commit 8dca498

Please sign in to comment.