-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.lintstagedrc.cjs
More file actions
38 lines (35 loc) · 1.5 KB
/
.lintstagedrc.cjs
File metadata and controls
38 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('node:fs');
const path = require('node:path');
const micromatch = require('micromatch');
module.exports = {
'{,scripts/**/,src/**/,test/**/}*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}': [
'node node_modules/.bin/eslint --fix',
'node node_modules/.bin/prettier --cache --write',
],
'./**/*.{cjs,css,cts,htm,html,java,js,json,json5,jsonc,jsx,md,mjs,mts,scss,ts,tsx,vue,yaml,yml}': (files) => {
let filteredFiles = files.filter(
(file) => !file.includes('/test-fixtures/') && !file.includes('/test/fixtures/') && !file.includes('/packages/')
);
filteredFiles = filteredFiles.map((file) => path.relative('', file));
filteredFiles = micromatch.not(filteredFiles, '{,scripts/**/,src/**/,test/**/}*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}');
filteredFiles = filteredFiles.map((file) => path.resolve(file));
if (filteredFiles.length === 0) return [];
const commands = [`node node_modules/.bin/prettier --cache --write ${filteredFiles.join(' ')}`];
if (filteredFiles.some((file) => file.endsWith('package.json'))) {
commands.push('node node_modules/.bin/sort-package-json');
}
return commands;
},
'./**/migration.sql': (files) => {
for (const file of files) {
const content = fs.readFileSync(file, 'utf8');
if (content.includes('Warnings:')) {
return [
`echo '!!! Migration SQL file (${path.relative('', file)}) contains warnings !!! Solve the warnings and commit again.'`,
'false',
];
}
}
return [];
},
};