New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid stashing if no lint-staged files are changed (#570) #573
Changes from 4 commits
04aa58f
ec66acd
316a7ed
a106320
e7805f3
162a7ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,51 +62,56 @@ module.exports = function runAll(config) { | |
renderer | ||
} | ||
|
||
if (tasks.length) { | ||
// Do not terminate main Listr process on SIGINT | ||
process.on('SIGINT', () => {}) | ||
// If all of the configured "linters" should be skipped | ||
// avoid executing any lint-staged logic | ||
if (tasks.every(task => task.skip())) { | ||
console.log( | ||
'No linters executed. No staged files match any of provided globs in "lint-staged.linters".' | ||
) | ||
return 'No tasks to run.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m wondering if we’re using this return value anywhere and if we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was uncertain about this so I left it as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m not sure either. Let’s leave for now. |
||
} | ||
|
||
return new Listr( | ||
[ | ||
{ | ||
title: 'Stashing changes...', | ||
skip: async () => { | ||
const hasPSF = await git.hasPartiallyStagedFiles() | ||
if (!hasPSF) { | ||
return 'No partially staged files found...' | ||
} | ||
return false | ||
}, | ||
task: ctx => { | ||
ctx.hasStash = true | ||
return git.gitStashSave() | ||
// Do not terminate main Listr process on SIGINT | ||
process.on('SIGINT', () => {}) | ||
|
||
return new Listr( | ||
[ | ||
{ | ||
title: 'Stashing changes...', | ||
skip: async () => { | ||
const hasPSF = await git.hasPartiallyStagedFiles() | ||
if (!hasPSF) { | ||
return 'No partially staged files found...' | ||
} | ||
return false | ||
}, | ||
{ | ||
title: 'Running linters...', | ||
task: () => | ||
new Listr(tasks, { | ||
...listrBaseOptions, | ||
concurrent, | ||
exitOnError: !concurrent // Wait for all errors when running concurrently | ||
}) | ||
}, | ||
{ | ||
title: 'Updating stash...', | ||
enabled: ctx => ctx.hasStash, | ||
skip: ctx => | ||
ctx.hasErrors && 'Skipping stash update since some tasks exited with errors', | ||
task: () => git.updateStash() | ||
}, | ||
{ | ||
title: 'Restoring local changes...', | ||
enabled: ctx => ctx.hasStash, | ||
task: () => git.gitStashPop() | ||
task: ctx => { | ||
ctx.hasStash = true | ||
return git.gitStashSave() | ||
} | ||
], | ||
listrBaseOptions | ||
).run() | ||
} | ||
return 'No tasks to run.' | ||
}, | ||
{ | ||
title: 'Running linters...', | ||
task: () => | ||
new Listr(tasks, { | ||
...listrBaseOptions, | ||
concurrent, | ||
exitOnError: !concurrent // Wait for all errors when running concurrently | ||
}) | ||
}, | ||
{ | ||
title: 'Updating stash...', | ||
enabled: ctx => ctx.hasStash, | ||
skip: ctx => ctx.hasErrors && 'Skipping stash update since some tasks exited with errors', | ||
task: () => git.updateStash() | ||
}, | ||
{ | ||
title: 'Restoring local changes...', | ||
enabled: ctx => ctx.hasStash, | ||
task: () => git.gitStashPop() | ||
} | ||
], | ||
listrBaseOptions | ||
).run() | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s fix grammar here and it’s good to merge. I’d say drop the
No linters executed.
part. Also dropin “lint-staged.linters”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I figured if we were going to report an error message, we'd make it clear precisely what we mean by "provided globs", config key-wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the copy :)