Skip to content

Commit

Permalink
fix: suppress warnings when using --quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 11, 2023
1 parent 21aeeb5 commit 105d901
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-ducks-invite.md
@@ -0,0 +1,5 @@
---
'lint-staged': patch
---

Suppress some warnings when using the "--quiet" flag
4 changes: 2 additions & 2 deletions lib/runAll.js
Expand Up @@ -108,7 +108,7 @@ export const runAll = async (
// Lint-staged will create a backup stash only when there's an initial commit,
// and when using the default list of staged files by default
ctx.shouldBackup = hasInitialCommit && stash
if (!ctx.shouldBackup) {
if (!ctx.shouldBackup && !quiet) {
logger.warn(skippingBackup(hasInitialCommit, diff))
}

Expand Down Expand Up @@ -242,7 +242,7 @@ export const runAll = async (
}
}

if (hasDeprecatedGitAdd) {
if (hasDeprecatedGitAdd && !quiet) {
logger.warn(DEPRECATED_GIT_ADD)
}

Expand Down
15 changes: 14 additions & 1 deletion test/unit/runAll.spec.js
Expand Up @@ -338,15 +338,28 @@ describe('runAll', () => {

it('should warn when "git add" was used in commands', async () => {
getStagedFiles.mockImplementationOnce(async () => ['sample.js'])
await runAll({ configObject: { '*.js': ['git add'] } }).catch(() => {})
await expect(runAll({ configObject: { '*.js': ['git add'] } })).rejects.toThrowError()
expect(console.printHistory()).toMatch('Some of your tasks use `git add` command')
})

it('should not warn about "git add" when --quiet was used', async () => {
getStagedFiles.mockImplementationOnce(async () => ['sample.js'])
await expect(
runAll({ configObject: { '*.js': ['git add'] }, quiet: true })
).rejects.toThrowError()
expect(console.printHistory()).toEqual('')
})

it('should warn when --no-stash was used', async () => {
await runAll({ configObject: { '*.js': ['echo "sample"'] }, stash: false })
expect(console.printHistory()).toMatch('Skipping backup because `--no-stash` was used')
})

it('should not warn when --no-stash was used together with --quiet', async () => {
await runAll({ configObject: { '*.js': ['echo "sample"'] }, stash: false, quiet: true })
expect(console.printHistory()).toEqual('')
})

it('should warn when --diff was used', async () => {
await runAll({ configObject: { '*.js': ['echo "sample"'] }, diff: 'branch1...branch2' })
expect(console.printHistory()).toMatch('Skipping backup because `--diff` was used')
Expand Down

0 comments on commit 105d901

Please sign in to comment.