diff --git a/README.md b/README.md index e3c5ce9ee..e70f97e88 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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... ``` +
+See asciinema video + [![asciicast](https://asciinema.org/a/199934.svg)](https://asciinema.org/a/199934) +
+ ## 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. diff --git a/lib/runAll.js b/lib/runAll.js index 04a80cf19..9c2556036 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -231,7 +231,7 @@ export const runAll = async ( const runner = new Listr( [ { - title: 'Preparing...', + title: 'Preparing lint-staged...', task: (ctx) => git.prepare(ctx), }, { @@ -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, }, @@ -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, diff --git a/test/integration.test.js b/test/integration.test.js index 5f2716f1a..cefe6e388 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -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] /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] /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 @@ -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] /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] /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!" `) }) @@ -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] /lint-staged — 1 file LOG [STARTED] *.js — 1 file LOG [STARTED] prettier --write @@ -838,13 +838,13 @@ describe('lint-staged', () => { LOG [SUCCESS] git add LOG [SUCCESS] *.js — 1 file LOG [SUCCESS] /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 @@ -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] /lint-staged — 1 file LOG [STARTED] *.js — 1 file LOG [STARTED] prettier --write LOG [SUCCESS] prettier --write LOG [SUCCESS] *.js — 1 file LOG [SUCCESS] /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 @@ -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] /lint-staged — 1 file LOG [STARTED] *.js — 1 file LOG [STARTED] prettier --write LOG [SUCCESS] prettier --write LOG [SUCCESS] *.js — 1 file LOG [SUCCESS] /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 @@ -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] /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] /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 diff --git a/test/runAll.spec.js b/test/runAll.spec.js index 6adfde7de..9560638fb 100644 --- a/test/runAll.spec.js +++ b/test/runAll.spec.js @@ -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..." `) }) @@ -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." `) @@ -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..." `) }) @@ -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..." `) })