BREAKING CHANGE: Strict lint enforcement is now ACTIVE Pre-commit hooks now block commits if: - Affected package has ANY lint errors or warnings - Affected package has ANY type errors Impact: If you touch a file in a package with existing violations, you MUST fix ALL violations in that package before committing. This forces incremental cleanup: - Work in @mosaic/shared → Fix all @mosaic/shared violations - Work in @mosaic/api → Fix all @mosaic/api violations - Work in clean packages → No extra work required Fixed regex to handle absolute paths from lint-staged. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
// Monorepo-aware lint-staged configuration
|
|
// STRICT ENFORCEMENT ENABLED: Blocks commits if affected packages have violations
|
|
//
|
|
// IMPORTANT: This lints ENTIRE packages, not just changed files.
|
|
// If you touch ANY file in a package with violations, you must fix the whole package.
|
|
// This forces incremental cleanup - work in a package = clean up that package.
|
|
//
|
|
export default {
|
|
// TypeScript files - lint and typecheck affected packages
|
|
'**/*.{ts,tsx}': (filenames) => {
|
|
const commands = [];
|
|
|
|
// 1. Format first (auto-fixes what it can)
|
|
commands.push(`prettier --write ${filenames.join(' ')}`);
|
|
|
|
// 2. Extract affected packages from absolute paths
|
|
// lint-staged passes absolute paths, so we need to extract the relative part
|
|
const packages = [...new Set(filenames.map(f => {
|
|
// Match either absolute or relative paths: .../packages/shared/... or packages/shared/...
|
|
const match = f.match(/(?:^|\/)(apps|packages)\/([^/]+)\//);
|
|
if (!match) return null;
|
|
// Return package name format for turbo (e.g., "@mosaic/api")
|
|
return `@mosaic/${match[2]}`;
|
|
}))].filter(Boolean);
|
|
|
|
if (packages.length === 0) {
|
|
return commands;
|
|
}
|
|
|
|
// 3. Lint entire affected packages via turbo
|
|
// --max-warnings=0 means ANY warning/error blocks the commit
|
|
packages.forEach(pkg => {
|
|
commands.push(`pnpm turbo run lint --filter=${pkg} -- --max-warnings=0`);
|
|
});
|
|
|
|
// 4. Type-check affected packages
|
|
packages.forEach(pkg => {
|
|
commands.push(`pnpm turbo run typecheck --filter=${pkg}`);
|
|
});
|
|
|
|
return commands;
|
|
},
|
|
|
|
// Format all other files
|
|
'**/*.{js,jsx,json,md,yml,yaml}': [
|
|
'prettier --write',
|
|
],
|
|
};
|