@modyqyw/fabric
Version:
Opinionated shareable specifications for git-based JavaScript/TypeScript projects.
89 lines (85 loc) • 3.03 kB
JavaScript
import { C as GLOB_EXCLUDE } from './fabric.DrBYK7XE.mjs';
import { f as filterFilenames } from './fabric.Cj4waNRr.mjs';
import { T as hasBiome, U as hasESLint, _ as hasMarkdownlintCli, V as hasOxlint, X as hasPrettier, W as hasStylelint } from './fabric.UWmAURsN.mjs';
function parseOptions(options = {}) {
const biome = options.biome ?? hasBiome;
return {
biome,
eslint: options.eslint ?? (hasESLint && !biome),
formatChangelog: options.formatChangelog ?? false,
lintJsonc: options.lintJsonc ?? true,
lintToml: options.lintToml ?? true,
lintYml: options.lintYml ?? true,
markdownlint: options.markdownlint ?? hasMarkdownlintCli,
oxlint: options.oxlint ?? (hasOxlint && !biome),
prettier: options.prettier ?? (hasPrettier && !biome),
stylelint: options.stylelint ?? (hasStylelint && !biome)
};
}
function lintStaged(options = {}, userConfig = {}) {
const {
biome: enableBiome,
eslint: enableESLint,
formatChangelog,
lintJsonc,
lintYml,
lintToml,
markdownlint: enableMarkdownlint,
oxlint: enableOxlint,
prettier: enablePrettier,
stylelint: enableStylelint
} = parseOptions(options);
const config = {};
if (enableBiome) {
config["*"] = "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true";
}
if (enableOxlint && enableESLint) {
config["*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}"] = (filenames) => {
const filtered = filterFilenames(filenames);
return [
`oxlint --fix ${filtered.join(" ")}`,
`eslint --fix --cache --no-error-on-unmatched-pattern ${filtered.join(" ")}`
];
};
} else if (enableOxlint) {
config["*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}"] = (filenames) => {
const filtered = filterFilenames(filenames);
return `oxlint --fix ${filtered.join(" ")}`;
};
} else if (enableESLint) {
config["*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}"] = "eslint --fix --cache --no-error-on-unmatched-pattern";
}
if (enableESLint) {
if (lintJsonc) {
config["*.{json,jsonc,json5}"] = "eslint --fix --cache --no-error-on-unmatched-pattern";
}
if (lintToml) {
config["*.toml"] = "eslint --fix --cache --no-error-on-unmatched-pattern";
}
if (lintYml) {
config["*.{yaml,yml}"] = "eslint --fix --cache --no-error-on-unmatched-pattern";
}
}
if (enableStylelint) {
config["*.{css,scss,vue}"] = "stylelint --fix --cache --aei --ignore-path=.gitignore";
}
if (enableMarkdownlint) {
config["*.{md,markdown}"] = "markdownlint --fix --ignore-path=.gitignore";
}
if (enablePrettier) {
config["*"] = (filenames) => {
const filtered = filterFilenames(
filenames,
formatChangelog ? GLOB_EXCLUDE.filter((e) => !e.toUpperCase().includes("CHANGELOG")) : GLOB_EXCLUDE
);
return filtered.map(
(f) => `prettier --ignore-unknown --write --cache ${f}`
);
};
}
return {
...config,
...userConfig
};
}
export { lintStaged as l, parseOptions as p };