Skip to content

Commit f77cefa

Browse files
iirojokonet
authored andcommitted
refactor: generateTasks is not async
1 parent 23019a5 commit f77cefa

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/generateTasks.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,38 @@ const isPathInside = (parent, child) => {
2929
* @param {boolean} [options.relative] - Whether filepaths to should be relative to gitDir
3030
* @returns {Promise}
3131
*/
32-
module.exports = async function generateTasks({
32+
module.exports = function generateTasks({
3333
config,
3434
cwd = process.cwd(),
3535
gitDir,
3636
files,
3737
relative = false
3838
}) {
3939
debug('Generating linter tasks')
40-
41-
const stagedFiles = files.map(file => path.resolve(gitDir, file))
42-
43-
return Object.keys(config).map(pattern => {
40+
return Object.entries(config).map(([pattern, commands]) => {
4441
const isParentDirPattern = pattern.startsWith('../')
45-
const commands = config[pattern]
46-
4742
const fileList = micromatch(
48-
stagedFiles
43+
files
4944
// Only worry about children of the CWD unless the pattern explicitly
5045
// specifies that it concerns a parent directory.
51-
.filter(file => isParentDirPattern || isPathInside(cwd, file))
52-
// Make the paths relative to CWD for filtering
53-
.map(file => path.relative(cwd, file)),
46+
.filter(file => {
47+
if (isParentDirPattern) return true
48+
const absolutePath = path.resolve(gitDir, file)
49+
return isPathInside(cwd, absolutePath)
50+
}),
5451
pattern,
5552
{
53+
cwd,
54+
dot: true,
5655
// If pattern doesn't look like a path, enable `matchBase` to
5756
// match against filenames in every directory. This makes `*.js`
5857
// match both `test.js` and `subdirectory/test.js`.
5958
matchBase: !pattern.includes('/'),
60-
dot: true
59+
posixSlashes: true
6160
}
6261
).map(file =>
6362
// Return absolute path after the filter is run
64-
relative ? path.normalize(file) : path.resolve(cwd, file)
63+
relative ? file : cwd + '/' + file
6564
)
6665

6766
const task = { pattern, commands, fileList }

src/runAll.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-com
6969
)
7070
}
7171

72-
const tasks = (await generateTasks({ config, cwd, gitDir, files, relative })).map(task => ({
72+
const tasks = generateTasks({ config, cwd, gitDir, files, relative }).map(task => ({
7373
title: `Running tasks for ${task.pattern}`,
7474
task: async () =>
7575
new Listr(

0 commit comments

Comments
 (0)