Skip to content

Commit

Permalink
fix: make console task titles more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jan 18, 2022
1 parent 90d1035 commit 1c94c27
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 75 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Run linters against staged git files and don't let :poop: slip into your code ba
```
$ git commit
βœ” Preparing...
❯ Running tasks...
βœ” Preparing lint-staged...
❯ Running tasks for staged files...
❯ packages/frontend/.lintstagedrc.json β€” 1 file
↓ *.js β€” no files [SKIPPED]
❯ *.{json,md} β€” 1 file
Expand All @@ -15,12 +15,17 @@ $ git commit
❯ *.js β€” 2 files
β Ό eslint --fix
↓ *.{json,md} β€” no files [SKIPPED]
β—Ό Applying modifications...
β—Ό Cleaning up...
β—Ό Applying modifications from tasks...
β—Ό Cleaning up temporary files...
```

<details>
<summary>See asciinema video</summary>

[![asciicast](https://asciinema.org/a/199934.svg)](https://asciinema.org/a/199934)

</details>

## Why

Linting makes more sense when run before committing your code. By doing so you can ensure no errors go into the repository and enforce code style. But running a lint process on a whole project is slow, and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.
Expand Down
8 changes: 4 additions & 4 deletions lib/runAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const runAll = async (
const runner = new Listr(
[
{
title: 'Preparing...',
title: 'Preparing lint-staged...',
task: (ctx) => git.prepare(ctx),
},
{
Expand All @@ -240,12 +240,12 @@ export const runAll = async (
enabled: hasPartiallyStagedFiles,
},
{
title: `Running tasks...`,
title: `Running tasks for staged files...`,
task: () => new Listr(listrTasks, { ...listrOptions, concurrent }),
skip: () => listrTasks.every((task) => task.skip()),
},
{
title: 'Applying modifications...',
title: 'Applying modifications from tasks...',
task: (ctx) => git.applyModifications(ctx),
skip: applyModificationsSkipped,
},
Expand All @@ -262,7 +262,7 @@ export const runAll = async (
skip: restoreOriginalStateSkipped,
},
{
title: 'Cleaning up...',
title: 'Cleaning up temporary files...',
task: (ctx) => git.cleanup(ctx),
enabled: cleanupEnabled,
skip: cleanupSkipped,
Expand Down
80 changes: 40 additions & 40 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,24 @@ describe('lint-staged', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Hiding unstaged changes to partially staged files...
LOG [SUCCESS] Hiding unstaged changes to partially staged files...
LOG [STARTED] Running tasks...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] <path>/lint-staged β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] prettier --list-different
LOG [SUCCESS] prettier --list-different
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] <path>/lint-staged β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Applying modifications...
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
LOG [SUCCESS] Applying modifications from tasks...
LOG [STARTED] Restoring unstaged changes to partially staged files...
LOG [SUCCESS] Restoring unstaged changes to partially staged files...
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Cleaning up..."
LOG [STARTED] Cleaning up temporary files...
LOG [SUCCESS] Cleaning up temporary files..."
`)

// Nothing is wrong, so a new commit is created and file is pretty
Expand Down Expand Up @@ -787,19 +787,19 @@ describe('lint-staged', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] <path>/lint-staged β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] git stash drop
LOG [SUCCESS] git stash drop
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] <path>/lint-staged β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Applying modifications...
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
LOG [SUCCESS] Applying modifications from tasks...
LOG [STARTED] Cleaning up temporary files...
ERROR [FAILED] lint-staged automatic backup is missing!"
`)
})
Expand Down Expand Up @@ -827,9 +827,9 @@ describe('lint-staged', () => {
"
WARN ⚠ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] <path>/lint-staged β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] prettier --write
Expand All @@ -838,13 +838,13 @@ describe('lint-staged', () => {
LOG [SUCCESS] git add
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] <path>/lint-staged β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
ERROR [FAILED] Prevented an empty git commit!
LOG [STARTED] Reverting to original state because of errors...
LOG [SUCCESS] Reverting to original state because of errors...
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Cleaning up...
LOG [STARTED] Cleaning up temporary files...
LOG [SUCCESS] Cleaning up temporary files...
WARN
⚠ lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration
Expand Down Expand Up @@ -977,18 +977,18 @@ describe('lint-staged', () => {
"
WARN ⚠ Skipping backup because \`--no-stash\` was used.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] <path>/lint-staged β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] prettier --write
LOG [SUCCESS] prettier --write
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] <path>/lint-staged β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Applying modifications..."
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
LOG [SUCCESS] Applying modifications from tasks..."
`)

// Nothing is wrong, so a new commit is created
Expand Down Expand Up @@ -1020,20 +1020,20 @@ describe('lint-staged', () => {
"
WARN ⚠ Skipping backup because \`--no-stash\` was used.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Hiding unstaged changes to partially staged files...
LOG [SUCCESS] Hiding unstaged changes to partially staged files...
LOG [STARTED] Running tasks...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] <path>/lint-staged β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] prettier --write <path>
LOG [SUCCESS] prettier --write <path>
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] <path>/lint-staged β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Applying modifications...
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
LOG [SUCCESS] Applying modifications from tasks...
LOG [STARTED] Restoring unstaged changes to partially staged files...
ERROR [FAILED] Unstaged changes could not be restored due to a merge conflict!
ERROR
Expand Down Expand Up @@ -1176,18 +1176,18 @@ describe('lintStaged', () => {
"
WARN ⚠ Skipping backup because there’s no initial commit yet.
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] <path>/lint-staged β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] prettier --list-different
LOG [SUCCESS] prettier --list-different
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] <path>/lint-staged β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Applying modifications..."
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
LOG [SUCCESS] Applying modifications from tasks..."
`)

// Nothing is wrong, so the initial commit is created
Expand Down
54 changes: 27 additions & 27 deletions test/runAll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,20 @@ describe('runAll', () => {
await runAll({ configObject: { '*.js': ['echo "sample"'] }, configPath })
expect(console.printHistory()).toMatchInlineSnapshot(`
"
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] echo \\"sample\\"
LOG [SUCCESS] echo \\"sample\\"
LOG [SUCCESS] *.js β€” 1 file
LOG [SUCCESS] β€” 1 file
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Applying modifications...
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Cleaning up..."
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
LOG [SUCCESS] Applying modifications from tasks...
LOG [STARTED] Cleaning up temporary files...
LOG [SUCCESS] Cleaning up temporary files..."
`)
})

Expand All @@ -170,14 +170,14 @@ describe('runAll', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
LOG [STARTED] Preparing...
LOG [STARTED] Preparing lint-staged...
ERROR [FAILED] test
LOG [STARTED] Running tasks...
INFO [SKIPPED] Running tasks...
LOG [STARTED] Applying modifications...
LOG [STARTED] Running tasks for staged files...
INFO [SKIPPED] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
INFO [SKIPPED]
[SKIPPED] βœ– lint-staged failed due to a git error.
LOG [STARTED] Cleaning up...
LOG [STARTED] Cleaning up temporary files...
INFO [SKIPPED]
[SKIPPED] βœ– lint-staged failed due to a git error."
`)
Expand All @@ -202,21 +202,21 @@ describe('runAll', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] echo \\"sample\\"
ERROR [FAILED] echo \\"sample\\" [1]
ERROR [FAILED] echo \\"sample\\" [1]
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
INFO [SKIPPED] Skipped because of errors from tasks.
LOG [STARTED] Reverting to original state because of errors...
LOG [SUCCESS] Reverting to original state because of errors...
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Cleaning up..."
LOG [STARTED] Cleaning up temporary files...
LOG [SUCCESS] Cleaning up temporary files..."
`)
})

Expand All @@ -241,21 +241,21 @@ describe('runAll', () => {

expect(console.printHistory()).toMatchInlineSnapshot(`
"
LOG [STARTED] Preparing...
LOG [SUCCESS] Preparing...
LOG [STARTED] Running tasks...
LOG [STARTED] Preparing lint-staged...
LOG [SUCCESS] Preparing lint-staged...
LOG [STARTED] Running tasks for staged files...
LOG [STARTED] β€” 1 file
LOG [STARTED] *.js β€” 1 file
LOG [STARTED] echo \\"sample\\"
ERROR [FAILED] echo \\"sample\\" [SIGINT]
ERROR [FAILED] echo \\"sample\\" [SIGINT]
LOG [SUCCESS] Running tasks...
LOG [STARTED] Applying modifications...
LOG [SUCCESS] Running tasks for staged files...
LOG [STARTED] Applying modifications from tasks...
INFO [SKIPPED] Skipped because of errors from tasks.
LOG [STARTED] Reverting to original state because of errors...
LOG [SUCCESS] Reverting to original state because of errors...
LOG [STARTED] Cleaning up...
LOG [SUCCESS] Cleaning up..."
LOG [STARTED] Cleaning up temporary files...
LOG [SUCCESS] Cleaning up temporary files..."
`)
})

Expand Down

0 comments on commit 1c94c27

Please sign in to comment.