Skip to content

Commit 4fa05f6

Browse files
committed
Support custom fixers commited into a .autofix/fixers/ directory
1 parent 8f6eb89 commit 4fa05f6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ Tier 2 (experimental, use with caution):
102102

103103
Tier 3 (you probably don't want to run these):
104104
- [ ] TODO
105+
106+
## Custom fixers
107+
108+
You can also implement your own fixers (similar to the ones found in the [./fixers/](./fixers/) directory) and commit them to your repository under a `.autofix/fixers/` directory. Autofix will automatically pick them up; run them on your codebase; and commit new fixes when relevant.

autofix.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ const tiers = String(argv.tiers || 0).split(',').map(tier => parseInt(tier, 10))
1313
// Detect and register available fixer modules.
1414
const fixers = [ [], [], [], [] ];
1515
console.log(`Registering fixer modules`);
16-
Promise.all(fs.readdirSync(`${__dirname}/fixers`).map(path => Object.assign(require(`${__dirname}/fixers/${path}`), {path})).map(async (fixer) => {
16+
const loadFixers = (directory) => {
17+
return !fs.existsSync(directory) ? [] :
18+
fs.readdirSync(directory).map(fixerPath => Object.assign(require(`${directory}/${fixerPath}`), { path: fixerPath }));
19+
}
20+
const coreFixers = loadFixers(`${__dirname}/fixers`);
21+
const customFixers = loadFixers(`${process.cwd()}/.autofix/fixers`);
22+
Promise.all([...coreFixers, ...customFixers].map(async (fixer) => {
1723
try {
1824
if (argv.verbose) {
1925
console.log(` Registering ${fixer.path}...`);

0 commit comments

Comments
 (0)