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

Show more info in missing customSyntax warning #5611

Merged
merged 3 commits into from Oct 21, 2021
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
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