Skip to content

Commit

Permalink
[stylelint#6452] feat: enable passing plugin functions as config value
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenisx committed Nov 18, 2022
1 parent d1705d0 commit 1501723
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/augmentConfig.js
Expand Up @@ -150,7 +150,13 @@ function absolutizePaths(config, configDir, cwd) {
}

if (config.plugins) {
config.plugins = [config.plugins].flat().map((lookup) => getModulePath(configDir, lookup, cwd));
config.plugins = [config.plugins].flat().map((lookup) => {
if (typeof lookup === 'string') {
return getModulePath(configDir, lookup, cwd);
}

return lookup;
});
}

if (config.processors) {
Expand Down Expand Up @@ -322,7 +328,13 @@ function addPluginFunctions(config) {
const pluginFunctions = {};

for (const pluginLookup of normalizedPlugins) {
let pluginImport = require(pluginLookup);
let pluginImport;

if (typeof pluginLookup === 'string') {
pluginImport = require(pluginLookup);
} else {
pluginImport = pluginLookup;
}

// Handle either ES6 or CommonJS modules
pluginImport = pluginImport.default || pluginImport;
Expand Down
5 changes: 4 additions & 1 deletion types/stylelint/index.d.ts
Expand Up @@ -7,7 +7,10 @@ declare module 'stylelint' {
export type Severity = 'warning' | 'error';

export type ConfigExtends = string | string[];
export type ConfigPlugins = string | string[];
export type PluginImportType =
| { default?: { ruleName: string; rule: Rule } }
| { ruleName: string; rule: Rule };
export type ConfigPlugins = string | string[] | PluginImportType | PluginImportType[];
export type ConfigProcessor = string | [string, Object];
export type ConfigProcessors = string | ConfigProcessor[];
export type ConfigIgnoreFiles = string | string[];
Expand Down

0 comments on commit 1501723

Please sign in to comment.