@modyqyw/fabric
Version:
Opinionated shareable specifications for git-based JavaScript/TypeScript projects.
92 lines (87 loc) • 3.01 kB
JavaScript
;
const constants = require('./fabric.Bxa-91bp.cjs');
const utils = require('./fabric.Ch5WLaHx.cjs');
const env = require('./fabric.B2dPjHjl.cjs');
function parseOptions(options = {}) {
const biome = options.biome ?? env.hasBiome;
return {
biome,
eslint: options.eslint ?? (env.hasESLint && !biome),
formatChangelog: options.formatChangelog ?? false,
lintJsonc: options.lintJsonc ?? true,
lintToml: options.lintToml ?? true,
lintYml: options.lintYml ?? true,
markdownlint: options.markdownlint ?? env.hasMarkdownlintCli,
oxlint: options.oxlint ?? (env.hasOxlint && !biome),
prettier: options.prettier ?? (env.hasPrettier && !biome),
stylelint: options.stylelint ?? (env.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 = utils.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 = utils.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 = utils.filterFilenames(
filenames,
formatChangelog ? constants.GLOB_EXCLUDE.filter((e) => !e.toUpperCase().includes("CHANGELOG")) : constants.GLOB_EXCLUDE
);
return filtered.map(
(f) => `prettier --ignore-unknown --write --cache ${f}`
);
};
}
return {
...config,
...userConfig
};
}
exports.lintStaged = lintStaged;
exports.parseOptions = parseOptions;