lint-staged 16.2.1 → 16.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { Option, program } from 'commander'
6
6
 
7
7
  import { createDebug, enableDebug } from '../lib/debug.js'
8
8
  import lintStaged from '../lib/index.js'
9
- import { CONFIG_STDIN_ERROR, RESTORE_STASH_EXAMPLE } from '../lib/messages.js'
9
+ import { CONFIG_STDIN_ERROR, restoreStashExample } from '../lib/messages.js'
10
10
  import { readStdin } from '../lib/readStdin.js'
11
11
  import { getVersion } from '../lib/version.js'
12
12
 
@@ -120,7 +120,7 @@ program
120
120
  ).default(false)
121
121
  )
122
122
 
123
- .addHelpText('afterAll', '\n' + RESTORE_STASH_EXAMPLE)
123
+ .addHelpText('afterAll', '\n' + restoreStashExample())
124
124
 
125
125
  const cliOptions = program.parse(process.argv).opts()
126
126
 
@@ -9,7 +9,7 @@ import { getDiffCommand } from './getDiffCommand.js'
9
9
  import { parseGitZOutput } from './parseGitZOutput.js'
10
10
  import {
11
11
  ApplyEmptyCommitError,
12
- ExitCodeError,
12
+ FailOnChangesError,
13
13
  GetBackupStashError,
14
14
  GitError,
15
15
  HideUnstagedChangesError,
@@ -317,7 +317,7 @@ export class GitWorkflow {
317
317
  const diffSha256 = calculateSha256(diff)
318
318
  debugLog('SHA-256 hash of changes after tasks is %S', this.diffSha256)
319
319
  if (this.unstagedDiffSha256 !== diffSha256) {
320
- ctx.errors.add(ExitCodeError)
320
+ ctx.errors.add(FailOnChangesError)
321
321
  throw new Error('Tasks modified files and --fail-on-changes was used!')
322
322
  }
323
323
  }
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  NO_CONFIGURATION,
7
7
  PREVENTED_EMPTY_COMMIT,
8
8
  PREVENTED_TASK_MODIFICATIONS,
9
- RESTORE_STASH_EXAMPLE,
9
+ restoreStashExample,
10
10
  UNSTAGED_CHANGES_BACKUP_STASH_LOCATION,
11
11
  } from './messages.js'
12
12
  import { printTaskOutput } from './printTaskOutput.js'
@@ -15,7 +15,7 @@ import { cleanupSkipped } from './state.js'
15
15
  import {
16
16
  ApplyEmptyCommitError,
17
17
  ConfigNotFoundError,
18
- ExitCodeError,
18
+ FailOnChangesError,
19
19
  GetBackupStashError,
20
20
  GitError,
21
21
  RestoreUnstagedChangesError,
@@ -155,8 +155,9 @@ const lintStaged = async (
155
155
  logger.error(NO_CONFIGURATION)
156
156
  } else if (ctx.errors.has(ApplyEmptyCommitError)) {
157
157
  logger.warn(PREVENTED_EMPTY_COMMIT)
158
- } else if (ctx.errors.has(ExitCodeError)) {
159
- logger.warn(PREVENTED_TASK_MODIFICATIONS)
158
+ } else if (ctx.errors.has(FailOnChangesError)) {
159
+ logger.warn(PREVENTED_TASK_MODIFICATIONS + '\n')
160
+ logger.warn(restoreStashExample(ctx.backupHash))
160
161
  } else if (ctx.errors.has(RestoreUnstagedChangesError)) {
161
162
  logger.warn(UNSTAGED_CHANGES_BACKUP_STASH_LOCATION)
162
163
  logger.warn(ctx.unstagedPatch)
@@ -167,7 +168,7 @@ const lintStaged = async (
167
168
  logger.error(GIT_ERROR)
168
169
  if (ctx.shouldBackup) {
169
170
  // No sense to show this if the backup stash itself is missing.
170
- logger.error(RESTORE_STASH_EXAMPLE + '\n')
171
+ logger.error(restoreStashExample(ctx.backupHash) + '\n')
171
172
  }
172
173
  }
173
174
 
package/lib/messages.js CHANGED
@@ -66,11 +66,13 @@ export const PREVENTED_EMPTY_COMMIT = `
66
66
  Use the --allow-empty option to continue, or check your task configuration`)}
67
67
  `
68
68
 
69
- export const RESTORE_STASH_EXAMPLE = `Any lost modifications can be restored from a git stash:
69
+ export const restoreStashExample = (
70
+ hash = 'h0a0s0h0'
71
+ ) => `Any lost modifications can be restored from a git stash:
70
72
 
71
73
  > git stash list --format="%h %s"
72
- h0a0s0h0 On main: lint-staged automatic backup
73
- > git apply --index h0a0s0h0`
74
+ ${hash} On main: lint-staged automatic backup
75
+ > git apply --index ${hash}`
74
76
 
75
77
  export const CONFIG_STDIN_ERROR = red(`${error} Failed to read config from stdin.`)
76
78
 
package/lib/state.js CHANGED
@@ -2,7 +2,7 @@ import EventEmitter from 'events'
2
2
 
3
3
  import { GIT_ERROR, TASK_ERROR } from './messages.js'
4
4
  import {
5
- ExitCodeError,
5
+ FailOnChangesError,
6
6
  GitError,
7
7
  RestoreOriginalStateError,
8
8
  RestoreUnstagedChangesError,
@@ -18,6 +18,7 @@ export const getInitialState = ({
18
18
  backupHash: null,
19
19
  errors: new Set([]),
20
20
  events: new EventEmitter(),
21
+ shouldFailOnChanges: null,
21
22
  hasFilesToHide: null,
22
23
  output: [],
23
24
  quiet,
@@ -37,10 +38,12 @@ export const shouldRestoreUnstagedChanges = (ctx) =>
37
38
  export const applyModificationsSkipped = (ctx) => {
38
39
  // Always apply back unstaged modifications when skipping revert or backup
39
40
  if (!ctx.shouldRevert || !ctx.shouldBackup) return false
41
+
40
42
  // Should be skipped in case of git errors
41
43
  if (ctx.errors.has(GitError)) {
42
44
  return GIT_ERROR
43
45
  }
46
+
44
47
  // Should be skipped when tasks fail
45
48
  if (ctx.errors.has(TaskError)) {
46
49
  return TASK_ERROR
@@ -53,6 +56,13 @@ export const restoreUnstagedChangesSkipped = (ctx) => {
53
56
  return GIT_ERROR
54
57
  }
55
58
 
59
+ // When complete reverting to original state is skipped,
60
+ // we can still restore unstaged changes to make it easier
61
+ // to do manually.
62
+ if (!ctx.shouldRevert) {
63
+ false
64
+ }
65
+
56
66
  // Should be skipped when tasks fail
57
67
  if (ctx.errors.has(TaskError)) {
58
68
  return TASK_ERROR
@@ -62,17 +72,13 @@ export const restoreUnstagedChangesSkipped = (ctx) => {
62
72
  export const restoreOriginalStateEnabled = (ctx) =>
63
73
  !!ctx.shouldRevert &&
64
74
  !!ctx.shouldBackup &&
65
- (ctx.errors.has(ExitCodeError) ||
75
+ (ctx.errors.has(FailOnChangesError) ||
66
76
  ctx.errors.has(TaskError) ||
67
77
  ctx.errors.has(RestoreUnstagedChangesError))
68
78
 
69
79
  export const restoreOriginalStateSkipped = (ctx) => {
70
80
  // Should be skipped in case of unknown git errors
71
- if (
72
- ctx.errors.has(GitError) &&
73
- !ctx.errors.has(RestoreUnstagedChangesError) &&
74
- !ctx.errors.has(ExitCodeError)
75
- ) {
81
+ if (ctx.errors.has(GitError) && !ctx.errors.has(RestoreUnstagedChangesError)) {
76
82
  return GIT_ERROR
77
83
  }
78
84
  }
@@ -80,6 +86,11 @@ export const restoreOriginalStateSkipped = (ctx) => {
80
86
  export const cleanupEnabled = (ctx) => ctx.shouldBackup
81
87
 
82
88
  export const cleanupSkipped = (ctx) => {
89
+ // "--fail-on-changes" was used, so we shouldn't drop the backup stash
90
+ if (ctx.errors.has(FailOnChangesError) && !ctx.shouldRevert) {
91
+ return true
92
+ }
93
+
83
94
  // Should be skipped in case of unknown git errors
84
95
  if (restoreOriginalStateSkipped(ctx)) {
85
96
  return GIT_ERROR
package/lib/symbols.js CHANGED
@@ -26,4 +26,4 @@ export const RestoreUnstagedChangesError = Symbol('RestoreUnstagedChangesError')
26
26
 
27
27
  export const TaskError = Symbol('TaskError')
28
28
 
29
- export const ExitCodeError = Symbol('ExitCodeError')
29
+ export const FailOnChangesError = Symbol('FailOnChangesError')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "16.2.1",
3
+ "version": "16.2.2",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": {