lint-staged 15.4.3 → 15.5.0

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.
package/README.md CHANGED
@@ -876,7 +876,7 @@ export default {
876
876
  }
877
877
  ```
878
878
 
879
- To support backwards-compatibility, monorepo features require multiple _lint-staged_ configuration files present in the git repo. If you still want to run _lint-staged_ in only one of the packages in a monorepo, you can either add an "empty" _lint-staged_ configuration to the root of the repo (so that there's two configs in total), or alternatively run _lint-staged_ with the `--cwd` option pointing to your package directory (for example, `lint-staged --cwd packages/frontend`).
879
+ To support backwards-compatibility, monorepo features require multiple _lint-staged_ configuration files present in the git repo. If you still want to run _lint-staged_ in only one of the packages in a monorepo, you can use the `--cwd` option (for example, `lint-staged --cwd packages/frontend`).
880
880
 
881
881
  </details>
882
882
 
@@ -909,15 +909,15 @@ all changed files between two different branches. If you want to run _lint-stage
909
909
  Try out the `git diff` command until you are satisfied with the result, for example:
910
910
 
911
911
  ```
912
- git diff --diff-filter=ACMR --name-only master...my-branch
912
+ git diff --diff-filter=ACMR --name-only main...my-branch
913
913
  ```
914
914
 
915
- This will print a list of _added_, _changed_, _modified_, and _renamed_ files between `master` and `my-branch`.
915
+ This will print a list of _added_, _changed_, _modified_, and _renamed_ files between `main` and `my-branch`.
916
916
 
917
917
  You can then run lint-staged against the same files with:
918
918
 
919
919
  ```
920
- npx lint-staged --diff="master...my-branch"
920
+ npx lint-staged --diff="main...my-branch"
921
921
  ```
922
922
 
923
923
  </details>
@@ -1013,3 +1013,98 @@ ESLint v8.51.0 introduced [`--no-warn-ignored` CLI flag](https://eslint.org/docs
1013
1013
  </details>
1014
1014
 
1015
1015
  </details>
1016
+
1017
+ ### How can I resolve TypeScript (`tsc`) ignoring `tsconfig.json` when `lint-staged` runs via Husky hooks?
1018
+
1019
+ <details>
1020
+ <summary>Click to expand</summary>
1021
+
1022
+ When running `lint-staged` via Husky hooks, TypeScript may ignore `tsconfig.json`, leading to errors like:
1023
+
1024
+ > **TS17004:** Cannot use JSX unless the '--jsx' flag is provided.
1025
+ > **TS1056:** Accessors are only available when targeting ECMAScript 5 and higher.
1026
+
1027
+ See issue [#825](https://github.com/okonet/lint-staged/issues/825) for more details.
1028
+
1029
+ #### Root Cause
1030
+
1031
+ <details>
1032
+ <summary>Click to expand</summary>
1033
+
1034
+ 1. `lint-staged` automatically passes matched staged files as arguments to commands.
1035
+ 2. Certain input files can cause TypeScript to ignore `tsconfig.json`. For more details, see this TypeScript issue: [Allow tsconfig.json when input files are specified](https://github.com/microsoft/TypeScript/issues/27379).
1036
+
1037
+ </details>
1038
+
1039
+ #### Workaround 1: Use a [function signature](https://github.com/lint-staged/lint-staged?tab=readme-ov-file#example-run-tsc-on-changes-to-typescript-files-but-do-not-pass-any-filename-arguments) for the `tsc` command
1040
+
1041
+ <details>
1042
+ <summary>Click to expand</summary>
1043
+
1044
+ As suggested by @antoinerousseau in [#825 (comment)](https://github.com/lint-staged/lint-staged/issues/825#issuecomment-620018284), using a function prevents `lint-staged` from appending file arguments:
1045
+
1046
+ **Before:**
1047
+
1048
+ ```js
1049
+ // package.json
1050
+
1051
+ "lint-staged": {
1052
+ "*.{ts,tsx}":[
1053
+ "tsc --noEmit",
1054
+ "prettier --write"
1055
+ ]
1056
+ }
1057
+ ```
1058
+
1059
+ **After:**
1060
+
1061
+ ```js
1062
+ // lint-staged.config.js
1063
+ module.exports = {
1064
+ "*.{ts,tsx}": [
1065
+ () => "tsc --noEmit",
1066
+ "prettier --write"
1067
+ ],
1068
+ }
1069
+ ```
1070
+
1071
+ </details>
1072
+
1073
+ #### Workaround 2: Take the `sh` or `bash` to wrap the `tsc` command
1074
+
1075
+ <details>
1076
+ <summary>Click to expand</summary>
1077
+
1078
+ As suggested by @sombreroEnPuntas in [#825 (comment)](https://github.com/lint-staged/lint-staged/issues/825#issuecomment-674575655), wrapping `tsc` in a shell command prevents `lint-staged` from modifying its arguments:
1079
+
1080
+ **Before:**
1081
+
1082
+ ```js
1083
+ // package.json
1084
+
1085
+ "lint-staged": {
1086
+ "*.{ts,tsx}":[
1087
+ "tsc --noEmit",
1088
+ "prettier --write"
1089
+ ]
1090
+ }
1091
+ ```
1092
+
1093
+ **After:**
1094
+
1095
+ ```js
1096
+ // package.json
1097
+
1098
+ "lint-staged": {
1099
+ "*.{ts,tsx}":[
1100
+ "bash -c 'tsc --noEmit'"
1101
+ "prettier --write"
1102
+ ]
1103
+ }
1104
+ ```
1105
+
1106
+ **Note:** This approach may have cross-platform compatibility issues.
1107
+
1108
+ </details>
1109
+
1110
+ </details>
package/lib/state.js CHANGED
@@ -2,7 +2,6 @@ import EventEmitter from 'events'
2
2
 
3
3
  import { GIT_ERROR, TASK_ERROR } from './messages.js'
4
4
  import {
5
- ApplyEmptyCommitError,
6
5
  GitError,
7
6
  RestoreOriginalStateError,
8
7
  RestoreUnstagedChangesError,
@@ -49,18 +48,11 @@ export const restoreUnstagedChangesSkipped = (ctx) => {
49
48
  }
50
49
 
51
50
  export const restoreOriginalStateEnabled = (ctx) =>
52
- ctx.shouldBackup &&
53
- (ctx.errors.has(TaskError) ||
54
- ctx.errors.has(ApplyEmptyCommitError) ||
55
- ctx.errors.has(RestoreUnstagedChangesError))
51
+ ctx.shouldBackup && (ctx.errors.has(TaskError) || ctx.errors.has(RestoreUnstagedChangesError))
56
52
 
57
53
  export const restoreOriginalStateSkipped = (ctx) => {
58
54
  // Should be skipped in case of unknown git errors
59
- if (
60
- ctx.errors.has(GitError) &&
61
- !ctx.errors.has(ApplyEmptyCommitError) &&
62
- !ctx.errors.has(RestoreUnstagedChangesError)
63
- ) {
55
+ if (ctx.errors.has(GitError) && !ctx.errors.has(RestoreUnstagedChangesError)) {
64
56
  return GIT_ERROR
65
57
  }
66
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "15.4.3",
3
+ "version": "15.5.0",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/lint-staged/lint-staged",
@@ -19,14 +19,10 @@
19
19
  "type": "module",
20
20
  "bin": "./bin/lint-staged.js",
21
21
  "exports": {
22
- ".": {
23
- "default": "./lib/index.js",
24
- "types": "./lib/types.d.ts"
25
- },
22
+ ".": "./lib/index.js",
26
23
  "./bin": "./bin/lint-staged.js",
27
24
  "./package.json": "./package.json"
28
25
  },
29
- "types": "lib/types.d.ts",
30
26
  "files": [
31
27
  "bin",
32
28
  "lib"
@@ -35,7 +31,7 @@
35
31
  "lint": "eslint .",
36
32
  "test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
37
33
  "test:watch": "npm run test -- --watch",
38
- "typecheck": "tsc --noEmit --strict test/unit/types.ts",
34
+ "typecheck": "tsc --noEmit --strict test/types/index.ts",
39
35
  "version": "npx changeset version",
40
36
  "postversion": "npm i --package-lock-only && git commit -am \"chore(changeset): release\"",
41
37
  "tag": "npx changeset tag"
@@ -53,26 +49,26 @@
53
49
  "yaml": "^2.7.0"
54
50
  },
55
51
  "devDependencies": {
56
- "@changesets/changelog-github": "0.5.0",
57
- "@changesets/cli": "2.27.11",
58
- "@commitlint/cli": "19.6.1",
59
- "@commitlint/config-conventional": "19.6.0",
60
- "@eslint/js": "9.18.0",
52
+ "@changesets/changelog-github": "0.5.1",
53
+ "@changesets/cli": "2.28.1",
54
+ "@commitlint/cli": "19.8.0",
55
+ "@commitlint/config-conventional": "19.8.0",
56
+ "@eslint/js": "9.22.0",
61
57
  "consolemock": "1.1.0",
62
58
  "cross-env": "7.0.3",
63
- "eslint": "9.18.0",
64
- "eslint-config-prettier": "10.0.1",
59
+ "eslint": "9.22.0",
60
+ "eslint-config-prettier": "10.1.1",
65
61
  "eslint-plugin-jest": "28.11.0",
66
- "eslint-plugin-n": "17.15.1",
62
+ "eslint-plugin-n": "17.16.2",
67
63
  "eslint-plugin-prettier": "5.2.3",
68
64
  "eslint-plugin-simple-import-sort": "12.1.1",
69
65
  "husky": "9.1.7",
70
66
  "jest": "29.7.0",
71
- "jest-snapshot-serializer-ansi": "2.1.0",
67
+ "jest-snapshot-serializer-ansi": "2.2.1",
72
68
  "mock-stdin": "1.0.0",
73
- "prettier": "3.4.2",
74
- "semver": "7.6.3",
75
- "typescript": "5.7.3"
69
+ "prettier": "3.5.3",
70
+ "semver": "7.7.1",
71
+ "typescript": "5.8.2"
76
72
  },
77
73
  "keywords": [
78
74
  "lint",
File without changes