Skip to content

Commit

Permalink
refactor(plugin): refactor lintFilePatterns to extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip9587 committed Apr 12, 2024
1 parent faa0320 commit 3bffadd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions nx-stylelint/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getInputConfigFiles } from '../utils/config-file';

export interface StylelintPluginOptions {
targetName?: string;
lintFilePatterns?: string | string[];
extensions?: string[];
}

const cachePath = nodePath.join(cacheDir, 'stylelint.hash');
Expand Down Expand Up @@ -67,7 +67,7 @@ export const createNodes: CreateNodes<StylelintPluginOptions> = [
async function buildStylelintTargets(
configFilePath: string,
projectRoot: string,
options: NormalizedStylelintPluginOptions,
options: Required<StylelintPluginOptions>,
): Promise<Record<string, TargetConfiguration>> {
const inputConfigFiles = await getInputConfigFiles(configFilePath, projectRoot);

Expand All @@ -77,21 +77,21 @@ async function buildStylelintTargets(
cache: true,
options: {
cwd: projectRoot,
args: [...options.lintFilePatterns.map((pattern) => `"${pattern}"`)],
args: [`"${getLintFileGlob(options.extensions)}"`],
},
inputs: ['default', ...inputConfigFiles, { externalDependencies: ['stylelint'] }],
},
};
}

interface NormalizedStylelintPluginOptions {
targetName: string;
lintFilePatterns: string[];
}

function normalizeOptions(options: StylelintPluginOptions | undefined): NormalizedStylelintPluginOptions {
function normalizeOptions(options: StylelintPluginOptions | undefined): Required<StylelintPluginOptions> {
return {
targetName: options?.targetName ?? 'stylelint',
lintFilePatterns: options?.lintFilePatterns ? [options?.lintFilePatterns].flat() : ['**/*.css'],
extensions: [...new Set(options?.extensions ?? ['css'])].filter(Boolean),
};
}

function getLintFileGlob(extensions: string[]): string {
if (extensions.length === 1) return `**/*.${extensions[0]}`;
return `**/*.{${extensions.join(',')}}`;
}

0 comments on commit 3bffadd

Please sign in to comment.