-
-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathlint-staged.config.js
More file actions
27 lines (24 loc) · 813 Bytes
/
lint-staged.config.js
File metadata and controls
27 lines (24 loc) · 813 Bytes
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
const fs = require('fs');
const path = require('path');
const findPackageJson = (dir) => {
const packageJsonPath = path.join(dir, 'package.json');
// eslint-disable-next-line node/no-sync
if (fs.existsSync(packageJsonPath)) {
return dir;
}
const parentDir = path.dirname(dir);
if (parentDir === dir) {
return null;
} // Reached the root directory
return findPackageJson(parentDir);
};
module.exports = {
'*.{js,jsx,ts,tsx}': (filenames) => {
return filenames.map((filename) => {
// Find the nearest package.json file to the changed file
const packageDir = findPackageJson(path.dirname(filename));
// Change to the package directory and run the commands
return `cd ${packageDir} && eslint --fix ${filename} && prettier --write ${filename}`;
});
},
};