Created
January 12, 2021 18:06
-
-
Save mantoni/facc4b06f88379564bf9e8163669ef92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
module.exports = { | |
'*.js': [ | |
'eslint --fix', | |
(files) => { | |
const tests = findTests(files); | |
return tests.length ? `npm run test:files -- ${tests.join(' ')}` : 'echo'; | |
} | |
], | |
'*.{js,css,md}': 'prettier --write' | |
}; | |
function findTests(files) { | |
const tests = new Set(); | |
files.forEach((file) => { | |
if (file.endsWith('.test.js')) { | |
tests.add(file); | |
return; | |
} | |
const test = file.replace(/\.js$/, '.test.js'); | |
try { | |
fs.accessSync(test); // eslint-disable-line node/no-sync | |
} catch (e) { | |
return; | |
} | |
tests.add(test); | |
}); | |
return Array.from(tests); | |
} |
Author
mantoni
commented
Jan 12, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment