-
Notifications
You must be signed in to change notification settings - Fork 6
/
.lintstagedrc.mjs
84 lines (80 loc) · 2.68 KB
/
.lintstagedrc.mjs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// import micromatch from 'micromatch';
import {ESLint} from 'eslint';
const removeIgnoredFiles = async (prefix, cfgFile, ignorePath, files) => {
const eslint = new ESLint({
overrideConfigFile: cfgFile,
ignorePath,
});
// console.log(eslint.calculateConfigForFile(files[0]));
const isIgnored = await Promise.all(
files.map(file => {
if (!file.startsWith(prefix)) {
console.error(
`ERROR in .lintstagedrc.mjs: ${file} doesn't start with ${prefix}`,
);
}
const f = file.slice(prefix.length);
return eslint.isPathIgnored(f);
}),
);
const filteredFiles = files.filter((_, i) => !isIgnored[i]);
// const ignoredFiles = files.filter((_, i) => isIgnored[i]);
// console.log('Ignored files:', ignoredFiles);
return filteredFiles;
};
const run = (command, files) => {
if (files.length === 0) {
return `echo "Skipping; no files to run ${command}"`;
}
const cmd = `${command} ${files.join(' ')}`;
return cmd;
};
const fullPathToContractsWorkspaceRelativePath = path => {
const contractsWorkspacePath = process.cwd() + '/contracts/';
return path.replace(contractsWorkspacePath, '');
};
export default {
'*': files => {
return run('prettier --write', files);
},
'contracts/**/*.sol': files => {
return run(
'yarn workspace @panther-core/contracts lint:solhint',
files.map(fullPathToContractsWorkspaceRelativePath),
);
},
'contracts/**/*.{js,ts}': async files => {
const prefix = process.cwd() + '/contracts/';
const toLint = await removeIgnoredFiles(
prefix,
'contracts/.eslintrc.json',
'contracts/.eslintignore',
files,
);
// const match = micromatch.not(files, '**/*.cli.js');
return run(
'yarn workspace @panther-core/contracts lint:eslint',
toLint,
);
},
'dapp/**/*.{js,jsx,ts,tsx}': async files => {
const prefix = process.cwd() + '/dapp/';
const toLint = await removeIgnoredFiles(
prefix,
'dapp/.eslintrc.json',
'dapp/.eslintignore',
files,
);
return run('yarn workspace @panther-core/dapp lint:eslint', toLint);
},
'circuits/**/*.*': async files => {
const prefix = process.cwd() + '/circuits/';
const toLint = await removeIgnoredFiles(
prefix,
'circuits/.eslintrc.json',
'circuits/.eslintignore',
files,
);
return run('yarn workspace @panther-core/circuits lint', toLint);
},
};