From 02724a4703c8cbbed09410349f84fbf51c24ca7b Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Wed, 20 Oct 2021 22:34:27 +0200 Subject: [PATCH 1/3] Show more info in missing customSyntax warning --- lib/__tests__/standalone-syntax.test.js | 7 ++++- lib/getPostcssResult.js | 39 +++++++++++++------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/__tests__/standalone-syntax.test.js b/lib/__tests__/standalone-syntax.test.js index 8199377242..a8b2c2786f 100644 --- a/lib/__tests__/standalone-syntax.test.js +++ b/lib/__tests__/standalone-syntax.test.js @@ -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: { @@ -47,7 +50,9 @@ it('standalone with postcss-safe-parser', () => { return fs.writeFile(root.source.input.file, root.source.input.css); }), - ); + ).then(() => { + jest.restoreAllMocks(); + }); }); }); diff --git a/lib/getPostcssResult.js b/lib/getPostcssResult.js index fe48734af9..d97172510b 100644 --- a/lib/getPostcssResult.js +++ b/lib/getPostcssResult.js @@ -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 @@ -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: '@stylelint/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 @@ -160,9 +161,9 @@ function cssSyntax(stylelint, filePath) { const extensions = ['css', 'pcss', 'postcss']; - if (previouslyInferedExtensions.includes(fileExtension)) { + if (Object.keys(previouslyInferedExtensions).includes(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`, ); } From aeb7bf068ef1b4f8d33cea35b34e2fc362d1a8c4 Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Wed, 20 Oct 2021 23:27:03 +0200 Subject: [PATCH 2/3] Change markdown syntax --- lib/getPostcssResult.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/getPostcssResult.js b/lib/getPostcssResult.js index d97172510b..fa0720473a 100644 --- a/lib/getPostcssResult.js +++ b/lib/getPostcssResult.js @@ -134,7 +134,7 @@ const previouslyInferedExtensions = { js: '@stylelint/postcss-css-in-js', jsx: '@stylelint/postcss-css-in-js', less: 'postcss-less', - md: '@stylelint/postcss-markdown', + md: 'postcss-markdown', sass: 'postcss-sass', sss: 'sugarss', scss: 'postcss-scss', From a44d38b33352997ed76f4b1419189cbc67590bae Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Thu, 21 Oct 2021 00:31:16 +0200 Subject: [PATCH 3/3] Update lib/getPostcssResult.js Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- lib/getPostcssResult.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/getPostcssResult.js b/lib/getPostcssResult.js index fa0720473a..599fd2658c 100644 --- a/lib/getPostcssResult.js +++ b/lib/getPostcssResult.js @@ -161,7 +161,7 @@ function cssSyntax(stylelint, filePath) { const extensions = ['css', 'pcss', 'postcss']; - if (Object.keys(previouslyInferedExtensions).includes(fileExtension)) { + if (previouslyInferedExtensions[fileExtension]) { console.warn( `${filePath}: When linting something other than CSS, you should install an appropriate syntax, e.g. "${previouslyInferedExtensions[fileExtension]}", and use the "customSyntax" option`, );