@monorepolint/rules 0.5.0-alpha.97 → 0.5.0-beta.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.
Files changed (151) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +47 -25
  3. package/src/__tests__/alphabeticalScripts.spec.ts +7 -6
  4. package/src/__tests__/bannedDependencies.spec.ts +7 -9
  5. package/src/__tests__/consistentDependencies.spec.ts +8 -7
  6. package/src/__tests__/consistentVersions.spec.ts +7 -6
  7. package/src/__tests__/fileContents.spec.ts +45 -18
  8. package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +41 -40
  9. package/src/__tests__/nestedWorkspaces.spec.ts +7 -6
  10. package/src/__tests__/packageEntry.spec.ts +44 -33
  11. package/src/__tests__/packageOrder.spec.ts +24 -15
  12. package/src/__tests__/packageScript.spec.ts +62 -44
  13. package/src/__tests__/requireDependency.spec.ts +10 -9
  14. package/src/__tests__/utils.ts +11 -6
  15. package/src/alphabeticalDependencies.ts +7 -9
  16. package/src/alphabeticalScripts.ts +7 -9
  17. package/src/bannedDependencies.ts +9 -10
  18. package/src/consistentDependencies.ts +9 -7
  19. package/src/consistentVersions.ts +6 -5
  20. package/src/fileContents.ts +17 -14
  21. package/src/index.ts +13 -13
  22. package/src/mustSatisfyPeerDependencies.ts +16 -11
  23. package/src/nestedWorkspaces.ts +10 -9
  24. package/src/packageEntry.ts +7 -6
  25. package/src/packageOrder.ts +12 -7
  26. package/src/packageScript.ts +12 -16
  27. package/src/public/util.ts +1 -0
  28. package/src/requireDependency.ts +9 -7
  29. package/src/standardTsconfig.ts +11 -9
  30. package/src/util/checkAlpha.ts +2 -2
  31. package/src/util/makeRule.ts +29 -0
  32. package/src/util/packageDependencyGraphService.ts +2 -2
  33. package/tsconfig.json +10 -2
  34. package/lib/__tests__/alphabeticalScripts.spec.d.ts +0 -8
  35. package/lib/__tests__/alphabeticalScripts.spec.d.ts.map +0 -1
  36. package/lib/__tests__/alphabeticalScripts.spec.js +0 -61
  37. package/lib/__tests__/alphabeticalScripts.spec.js.map +0 -1
  38. package/lib/__tests__/bannedDependencies.spec.d.ts +0 -2
  39. package/lib/__tests__/bannedDependencies.spec.d.ts.map +0 -1
  40. package/lib/__tests__/bannedDependencies.spec.js +0 -161
  41. package/lib/__tests__/bannedDependencies.spec.js.map +0 -1
  42. package/lib/__tests__/consistentDependencies.spec.d.ts +0 -2
  43. package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
  44. package/lib/__tests__/consistentDependencies.spec.js +0 -115
  45. package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
  46. package/lib/__tests__/consistentVersions.spec.d.ts +0 -8
  47. package/lib/__tests__/consistentVersions.spec.d.ts.map +0 -1
  48. package/lib/__tests__/consistentVersions.spec.js +0 -183
  49. package/lib/__tests__/consistentVersions.spec.js.map +0 -1
  50. package/lib/__tests__/fileContents.spec.d.ts +0 -8
  51. package/lib/__tests__/fileContents.spec.d.ts.map +0 -1
  52. package/lib/__tests__/fileContents.spec.js +0 -59
  53. package/lib/__tests__/fileContents.spec.js.map +0 -1
  54. package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts +0 -8
  55. package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +0 -1
  56. package/lib/__tests__/mustSatisfyPeerDependencies.spec.js +0 -1063
  57. package/lib/__tests__/mustSatisfyPeerDependencies.spec.js.map +0 -1
  58. package/lib/__tests__/nestedWorkspaces.spec.d.ts +0 -2
  59. package/lib/__tests__/nestedWorkspaces.spec.d.ts.map +0 -1
  60. package/lib/__tests__/nestedWorkspaces.spec.js +0 -124
  61. package/lib/__tests__/nestedWorkspaces.spec.js.map +0 -1
  62. package/lib/__tests__/packageEntry.spec.d.ts +0 -8
  63. package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
  64. package/lib/__tests__/packageEntry.spec.js +0 -144
  65. package/lib/__tests__/packageEntry.spec.js.map +0 -1
  66. package/lib/__tests__/packageOrder.spec.d.ts +0 -8
  67. package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
  68. package/lib/__tests__/packageOrder.spec.js +0 -116
  69. package/lib/__tests__/packageOrder.spec.js.map +0 -1
  70. package/lib/__tests__/packageScript.spec.d.ts +0 -8
  71. package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
  72. package/lib/__tests__/packageScript.spec.js +0 -171
  73. package/lib/__tests__/packageScript.spec.js.map +0 -1
  74. package/lib/__tests__/requireDependency.spec.d.ts +0 -2
  75. package/lib/__tests__/requireDependency.spec.d.ts.map +0 -1
  76. package/lib/__tests__/requireDependency.spec.js +0 -123
  77. package/lib/__tests__/requireDependency.spec.js.map +0 -1
  78. package/lib/__tests__/utils.d.ts +0 -76
  79. package/lib/__tests__/utils.d.ts.map +0 -1
  80. package/lib/__tests__/utils.js +0 -83
  81. package/lib/__tests__/utils.js.map +0 -1
  82. package/lib/alphabeticalDependencies.d.ts +0 -12
  83. package/lib/alphabeticalDependencies.d.ts.map +0 -1
  84. package/lib/alphabeticalDependencies.js +0 -22
  85. package/lib/alphabeticalDependencies.js.map +0 -1
  86. package/lib/alphabeticalScripts.d.ts +0 -12
  87. package/lib/alphabeticalScripts.d.ts.map +0 -1
  88. package/lib/alphabeticalScripts.js +0 -20
  89. package/lib/alphabeticalScripts.js.map +0 -1
  90. package/lib/bannedDependencies.d.ts +0 -33
  91. package/lib/bannedDependencies.d.ts.map +0 -1
  92. package/lib/bannedDependencies.js +0 -131
  93. package/lib/bannedDependencies.js.map +0 -1
  94. package/lib/consistentDependencies.d.ts +0 -17
  95. package/lib/consistentDependencies.d.ts.map +0 -1
  96. package/lib/consistentDependencies.js +0 -75
  97. package/lib/consistentDependencies.js.map +0 -1
  98. package/lib/consistentVersions.d.ts +0 -14
  99. package/lib/consistentVersions.d.ts.map +0 -1
  100. package/lib/consistentVersions.js +0 -94
  101. package/lib/consistentVersions.js.map +0 -1
  102. package/lib/fileContents.d.ts +0 -25
  103. package/lib/fileContents.d.ts.map +0 -1
  104. package/lib/fileContents.js +0 -82
  105. package/lib/fileContents.js.map +0 -1
  106. package/lib/index.d.ts +0 -20
  107. package/lib/index.d.ts.map +0 -1
  108. package/lib/index.js +0 -36
  109. package/lib/index.js.map +0 -1
  110. package/lib/mustSatisfyPeerDependencies.d.ts +0 -240
  111. package/lib/mustSatisfyPeerDependencies.d.ts.map +0 -1
  112. package/lib/mustSatisfyPeerDependencies.js +0 -636
  113. package/lib/mustSatisfyPeerDependencies.js.map +0 -1
  114. package/lib/nestedWorkspaces.d.ts +0 -13
  115. package/lib/nestedWorkspaces.d.ts.map +0 -1
  116. package/lib/nestedWorkspaces.js +0 -50
  117. package/lib/nestedWorkspaces.js.map +0 -1
  118. package/lib/packageEntry.d.ts +0 -25
  119. package/lib/packageEntry.d.ts.map +0 -1
  120. package/lib/packageEntry.js +0 -75
  121. package/lib/packageEntry.js.map +0 -1
  122. package/lib/packageOrder.d.ts +0 -12
  123. package/lib/packageOrder.d.ts.map +0 -1
  124. package/lib/packageOrder.js +0 -103
  125. package/lib/packageOrder.js.map +0 -1
  126. package/lib/packageScript.d.ts +0 -25
  127. package/lib/packageScript.d.ts.map +0 -1
  128. package/lib/packageScript.js +0 -90
  129. package/lib/packageScript.js.map +0 -1
  130. package/lib/requireDependency.d.ts +0 -15
  131. package/lib/requireDependency.d.ts.map +0 -1
  132. package/lib/requireDependency.js +0 -65
  133. package/lib/requireDependency.js.map +0 -1
  134. package/lib/standardTsconfig.d.ts +0 -45
  135. package/lib/standardTsconfig.d.ts.map +0 -1
  136. package/lib/standardTsconfig.js +0 -116
  137. package/lib/standardTsconfig.js.map +0 -1
  138. package/lib/util/checkAlpha.d.ts +0 -10
  139. package/lib/util/checkAlpha.d.ts.map +0 -1
  140. package/lib/util/checkAlpha.js +0 -51
  141. package/lib/util/checkAlpha.js.map +0 -1
  142. package/lib/util/makeDirectory.d.ts +0 -8
  143. package/lib/util/makeDirectory.d.ts.map +0 -1
  144. package/lib/util/makeDirectory.js +0 -28
  145. package/lib/util/makeDirectory.js.map +0 -1
  146. package/lib/util/packageDependencyGraphService.d.ts +0 -37
  147. package/lib/util/packageDependencyGraphService.d.ts.map +0 -1
  148. package/lib/util/packageDependencyGraphService.js +0 -70
  149. package/lib/util/packageDependencyGraphService.js.map +0 -1
  150. package/tsconfig.tsbuildinfo +0 -1
  151. /package/{jest.config.js → jest.config.cjs} +0 -0
@@ -7,9 +7,10 @@
7
7
 
8
8
  // tslint:disable:no-console
9
9
 
10
- import { Context, Failure } from "@monorepolint/core";
11
- import { createExpectedEntryErrorMessage, createStandardizedEntryErrorMessage, packageEntry } from "../packageEntry";
12
- import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
10
+ import { Context, Failure } from "@monorepolint/config";
11
+ import { createExpectedEntryErrorMessage, createStandardizedEntryErrorMessage, packageEntry } from "../packageEntry.js";
12
+ import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
13
+ import { describe, expect, it, beforeEach, afterEach, jest } from "@jest/globals";
13
14
 
14
15
  const PACKAGE_MISSING_ENTRY =
15
16
  JSON.stringify(
@@ -75,12 +76,14 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
75
76
  it("fixes missing entries", () => {
76
77
  workspace.writeFile("package.json", PACKAGE_MISSING_ENTRY);
77
78
 
78
- packageEntry.check(context, {
79
- entries: {
80
- license: "UNLICENSED",
79
+ packageEntry({
80
+ options: {
81
+ entries: {
82
+ license: "UNLICENSED",
83
+ },
84
+ entriesExist: undefined,
81
85
  },
82
- entriesExist: undefined,
83
- });
86
+ }).check(context);
84
87
 
85
88
  expect(spy).toHaveBeenCalledTimes(1);
86
89
 
@@ -99,15 +102,17 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
99
102
  it("fixes missing nested entries", () => {
100
103
  workspace.writeFile("package.json", PACKAGE_MISSING_ENTRY);
101
104
 
102
- packageEntry.check(context, {
103
- entries: {
104
- repository: {
105
- type: "git",
106
- url: "https://github.com:foo/foo",
105
+ packageEntry({
106
+ options: {
107
+ entries: {
108
+ repository: {
109
+ type: "git",
110
+ url: "https://github.com:foo/foo",
111
+ },
107
112
  },
113
+ entriesExist: undefined,
108
114
  },
109
- entriesExist: undefined,
110
- });
115
+ }).check(context);
111
116
 
112
117
  expect(spy).toHaveBeenCalledTimes(1);
113
118
 
@@ -126,15 +131,17 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
126
131
  it("doesn't error for nested entries that are defined", () => {
127
132
  workspace.writeFile("package.json", PACKAGE_REPOSITORY);
128
133
 
129
- packageEntry.check(context, {
130
- entries: {
131
- repository: {
132
- type: "git",
133
- url: "https://github.com:foo/foo",
134
+ packageEntry({
135
+ options: {
136
+ entries: {
137
+ repository: {
138
+ type: "git",
139
+ url: "https://github.com:foo/foo",
140
+ },
134
141
  },
142
+ entriesExist: undefined,
135
143
  },
136
- entriesExist: undefined,
137
- });
144
+ }).check(context);
138
145
 
139
146
  expect(spy).toHaveBeenCalledTimes(0);
140
147
  expect(workspace.readFile("package.json")).toEqual(PACKAGE_REPOSITORY);
@@ -143,10 +150,12 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
143
150
  it("errors for keys that are missing", () => {
144
151
  workspace.writeFile("package.json", PACKAGE_REPOSITORY);
145
152
 
146
- packageEntry.check(context, {
147
- entries: undefined,
148
- entriesExist: ["bugs"],
149
- });
153
+ packageEntry({
154
+ options: {
155
+ entries: undefined,
156
+ entriesExist: ["bugs"],
157
+ },
158
+ }).check(context);
150
159
 
151
160
  expect(spy).toHaveBeenCalledTimes(1);
152
161
 
@@ -164,15 +173,17 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
164
173
  it("handles both entries and entriesExist", () => {
165
174
  workspace.writeFile("package.json", PACKAGE_MISSING_ENTRY);
166
175
 
167
- packageEntry.check(context, {
168
- entries: {
169
- repository: {
170
- type: "git",
171
- url: "https://github.com:foo/foo",
176
+ packageEntry({
177
+ options: {
178
+ entries: {
179
+ repository: {
180
+ type: "git",
181
+ url: "https://github.com:foo/foo",
182
+ },
172
183
  },
184
+ entriesExist: ["bugs"],
173
185
  },
174
- entriesExist: ["bugs"],
175
- });
186
+ }).check(context);
176
187
 
177
188
  expect(spy).toHaveBeenCalledTimes(2);
178
189
 
@@ -6,9 +6,10 @@
6
6
  */
7
7
 
8
8
  // tslint:disable:no-console
9
- import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
10
- import { Context, Failure } from "@monorepolint/core";
11
- import { packageOrder } from "../packageOrder";
9
+ import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
10
+ import { Context, Failure } from "@monorepolint/config";
11
+ import { packageOrder } from "../packageOrder.js";
12
+ import { describe, expect, it, beforeEach, jest } from "@jest/globals";
12
13
 
13
14
  const PACKAGE_UNORDERED =
14
15
  JSON.stringify(
@@ -100,9 +101,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
100
101
  it("fixes order for expected keys", () => {
101
102
  workspace.writeFile("package.json", PACKAGE_UNORDERED);
102
103
 
103
- packageOrder.check(context, {
104
- order: orderArray,
105
- });
104
+ packageOrder({
105
+ options: {
106
+ order: orderArray,
107
+ },
108
+ }).check(context);
106
109
 
107
110
  expect(spy).toHaveBeenCalledTimes(1);
108
111
 
@@ -121,9 +124,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
121
124
  it("fixes order for unexpected keys", () => {
122
125
  workspace.writeFile("package.json", PACKAGE_UNORDERED_UNKOWN_KEYS);
123
126
 
124
- packageOrder.check(context, {
125
- order: orderArray,
126
- });
127
+ packageOrder({
128
+ options: {
129
+ order: orderArray,
130
+ },
131
+ }).check(context);
127
132
 
128
133
  expect(spy).toHaveBeenCalledTimes(1);
129
134
 
@@ -142,9 +147,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
142
147
  it("fixes order using function", () => {
143
148
  workspace.writeFile("package.json", PACKAGE_UNORDERED);
144
149
 
145
- packageOrder.check(context, {
146
- order: orderFunction,
147
- });
150
+ packageOrder({
151
+ options: {
152
+ order: orderFunction,
153
+ },
154
+ }).check(context);
148
155
 
149
156
  expect(spy).toHaveBeenCalledTimes(1);
150
157
 
@@ -163,9 +170,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
163
170
  it("does nothing if already order", () => {
164
171
  workspace.writeFile("package.json", PACKAGE_ORDERED_UNKOWN_KEYS);
165
172
 
166
- packageOrder.check(context, {
167
- order: orderArray,
168
- });
173
+ packageOrder({
174
+ options: {
175
+ order: orderArray,
176
+ },
177
+ }).check(context);
169
178
 
170
179
  expect(spy).not.toHaveBeenCalled();
171
180
 
@@ -6,10 +6,10 @@
6
6
  */
7
7
 
8
8
  // tslint:disable:no-console
9
-
10
- import { Context, Failure } from "@monorepolint/core";
11
- import { packageScript } from "../packageScript";
12
- import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
9
+ import { describe, expect, it, beforeEach, jest } from "@jest/globals";
10
+ import { Context, Failure } from "@monorepolint/config";
11
+ import { packageScript } from "../packageScript.js";
12
+ import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
13
13
 
14
14
  const json = (a: unknown) => JSON.stringify(a, undefined, 2) + "\n";
15
15
 
@@ -47,11 +47,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
47
47
  it("handles an empty script section", () => {
48
48
  workspace.writeFile("package.json", PACKAGE_WITHOUT_SCRIPTS);
49
49
 
50
- packageScript.check(workspace.context, {
51
- scripts: {
52
- foo: "bar",
50
+ packageScript({
51
+ options: {
52
+ scripts: {
53
+ foo: "bar",
54
+ },
53
55
  },
54
- });
56
+ }).check(workspace.context);
55
57
 
56
58
  expect(spy).toHaveBeenCalledTimes(1);
57
59
 
@@ -84,11 +86,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
84
86
  it("fixes an empty script section", () => {
85
87
  workspace.writeFile("package.json", PACKAGE_WITHOUT_SCRIPTS);
86
88
 
87
- packageScript.check(context, {
88
- scripts: {
89
- foo: "bar",
89
+ packageScript({
90
+ options: {
91
+ scripts: {
92
+ foo: "bar",
93
+ },
90
94
  },
91
- });
95
+ }).check(context);
92
96
 
93
97
  expect(spy).toHaveBeenCalledTimes(1);
94
98
 
@@ -107,11 +111,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
107
111
  it("adds a script", () => {
108
112
  workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
109
113
 
110
- packageScript.check(context, {
111
- scripts: {
112
- [MISSING_SCRIPT_NAME]: MISSING_SCRIPT_VALUE,
114
+ packageScript({
115
+ options: {
116
+ scripts: {
117
+ [MISSING_SCRIPT_NAME]: MISSING_SCRIPT_VALUE,
118
+ },
113
119
  },
114
- });
120
+ }).check(context);
115
121
 
116
122
  expect(spy).toHaveBeenCalledTimes(1);
117
123
 
@@ -120,7 +126,9 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
120
126
  workspace.failureMatcher({
121
127
  file: "package.json",
122
128
  hasFixer: true,
123
- message: expect.stringContaining(`Expected standardized script entry for '${MISSING_SCRIPT_NAME}'`),
129
+ message: expect.stringContaining(
130
+ `Expected standardized script entry for '${MISSING_SCRIPT_NAME}'`
131
+ ) as unknown as string,
124
132
  })
125
133
  );
126
134
 
@@ -132,11 +140,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
132
140
  it("does nothing if the value exists", () => {
133
141
  workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
134
142
 
135
- packageScript.check(context, {
136
- scripts: {
137
- [SCRIPT_NAME]: SCRIPT_VALUE,
143
+ packageScript({
144
+ options: {
145
+ scripts: {
146
+ [SCRIPT_NAME]: SCRIPT_VALUE,
147
+ },
138
148
  },
139
- });
149
+ }).check(context);
140
150
 
141
151
  expect(spy).not.toHaveBeenCalled();
142
152
 
@@ -148,13 +158,15 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
148
158
  it("errors if long form is used and no value matches and there is no fixValue", () => {
149
159
  workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
150
160
 
151
- packageScript.check(context, {
152
- scripts: {
153
- foo: {
154
- options: ["a", "b"],
161
+ packageScript({
162
+ options: {
163
+ scripts: {
164
+ foo: {
165
+ options: ["a", "b"],
166
+ },
155
167
  },
156
168
  },
157
- });
169
+ }).check(context);
158
170
 
159
171
  const errors = spy.mock.calls;
160
172
 
@@ -165,14 +177,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
165
177
  it("uses the fixValue for fixing if provided", () => {
166
178
  workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
167
179
 
168
- packageScript.check(context, {
169
- scripts: {
170
- foo: {
171
- options: ["a", "b"],
172
- fixValue: "a",
180
+ packageScript({
181
+ options: {
182
+ scripts: {
183
+ foo: {
184
+ options: ["a", "b"],
185
+ fixValue: "a",
186
+ },
173
187
  },
174
188
  },
175
- });
189
+ }).check(context);
176
190
 
177
191
  const errors = spy.mock.calls;
178
192
 
@@ -188,14 +202,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
188
202
  it("can fix to empty", () => {
189
203
  workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
190
204
 
191
- packageScript.check(context, {
192
- scripts: {
193
- [SCRIPT_NAME]: {
194
- options: ["a", undefined],
195
- fixValue: undefined,
205
+ packageScript({
206
+ options: {
207
+ scripts: {
208
+ [SCRIPT_NAME]: {
209
+ options: ["a", undefined],
210
+ fixValue: undefined,
211
+ },
196
212
  },
197
213
  },
198
- });
214
+ }).check(context);
199
215
 
200
216
  const errors = spy.mock.calls;
201
217
 
@@ -208,14 +224,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
208
224
  it("can allow only empty", () => {
209
225
  workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
210
226
 
211
- packageScript.check(context, {
212
- scripts: {
213
- [SCRIPT_NAME]: {
214
- options: [undefined],
215
- fixValue: undefined,
227
+ packageScript({
228
+ options: {
229
+ scripts: {
230
+ [SCRIPT_NAME]: {
231
+ options: [undefined],
232
+ fixValue: undefined,
233
+ },
216
234
  },
217
235
  },
218
- });
236
+ }).check(context);
219
237
 
220
238
  const errors = spy.mock.calls;
221
239
 
@@ -4,14 +4,15 @@
4
4
  * Licensed under the MIT license. See LICENSE file in the project root for details.
5
5
  *
6
6
  */
7
- import { WorkspaceContext } from "@monorepolint/core";
7
+ import { WorkspaceContextImpl } from "@monorepolint/core";
8
8
  import { SimpleHost } from "@monorepolint/utils";
9
- import { readFileSync, writeFileSync } from "fs";
10
- import * as path from "path";
9
+ import { readFileSync, writeFileSync } from "node:fs";
10
+ import * as path from "node:path";
11
11
  import * as tmp from "tmp";
12
- import { requireDependency } from "../requireDependency";
13
- import { makeDirectoryRecursively } from "../util/makeDirectory";
14
- import { jsonToString } from "./utils";
12
+ import { requireDependency } from "../requireDependency.js";
13
+ import { makeDirectoryRecursively } from "../util/makeDirectory.js";
14
+ import { jsonToString } from "./utils.js";
15
+ import { describe, expect, it, afterEach, jest } from "@jest/globals";
15
16
 
16
17
  const PACKAGE_ROOT = jsonToString({
17
18
  workspaces: {
@@ -74,7 +75,7 @@ describe("requireDependency", () => {
74
75
  const dir: tmp.DirResult = tmp.dirSync({ unsafeCleanup: true });
75
76
  cleanupJobs.push(() => dir.removeCallback());
76
77
 
77
- const workspaceContext = new WorkspaceContext(
78
+ const workspaceContext = new WorkspaceContextImpl(
78
79
  dir.name,
79
80
  {
80
81
  rules: [],
@@ -88,7 +89,7 @@ describe("requireDependency", () => {
88
89
  function checkAndSpy(q: string) {
89
90
  const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
90
91
  const addErrorSpy = jest.spyOn(context, "addError");
91
- requireDependency.check(context, OPTIONS);
92
+ requireDependency({ options: OPTIONS }).check(context);
92
93
  return { context, addErrorSpy };
93
94
  }
94
95
 
@@ -115,7 +116,7 @@ describe("requireDependency", () => {
115
116
  addFile("./packages/wrong/package.json", PACKAGE_WITH_WRONG_ENTRIES);
116
117
  addFile("./packages/right/package.json", PACKAGE_WITH_RIGHT_ENTRIES);
117
118
 
118
- requireDependency.check(workspaceContext, OPTIONS);
119
+ requireDependency({ options: OPTIONS }).check(workspaceContext);
119
120
 
120
121
  const none = checkAndSpy("./packages/none");
121
122
  expect(none.addErrorSpy).toHaveBeenCalledTimes(2);
@@ -5,12 +5,14 @@
5
5
  *
6
6
  */
7
7
 
8
- import { AddErrorOptions, WorkspaceContext } from "@monorepolint/core";
8
+ import { AddErrorOptions, WorkspaceContext } from "@monorepolint/config";
9
+ import { WorkspaceContextImpl } from "@monorepolint/core";
9
10
  import { CachingHost, Host, SimpleHost } from "@monorepolint/utils";
10
- import * as path from "path";
11
+ import { expect, jest } from "@jest/globals";
12
+ import * as path from "node:path";
11
13
  import * as tmp from "tmp";
12
14
 
13
- export function jsonToString(obj: {}) {
15
+ export function jsonToString(obj: unknown) {
14
16
  return JSON.stringify(obj, undefined, 2) + "\n";
15
17
  }
16
18
 
@@ -41,7 +43,7 @@ export async function createTestingWorkspace(inboundOpts: TestingWorkspaceOpts)
41
43
 
42
44
  return new DefaultTestingWorkspace(
43
45
  { ...opts, rootPath },
44
- new WorkspaceContext(rootPath, { fix: opts.fixFlag, rules: [] }, opts.host)
46
+ new WorkspaceContextImpl(rootPath, { fix: opts.fixFlag, rules: [] }, opts.host)
45
47
  );
46
48
  }
47
49
 
@@ -74,7 +76,10 @@ export interface TestingWorkspace {
74
76
  }
75
77
 
76
78
  class DefaultTestingWorkspace implements TestingWorkspace {
77
- constructor(private opts: RealTestingWorkspaceOpts, public readonly context: WorkspaceContext) {}
79
+ constructor(
80
+ private opts: RealTestingWorkspaceOpts,
81
+ public readonly context: WorkspaceContext
82
+ ) {}
78
83
 
79
84
  addProject(name: string, fields: object) {
80
85
  this.writeJsonFile(path.join("packages", name, "package.json"), {
@@ -117,7 +122,7 @@ class DefaultTestingWorkspace implements TestingWorkspace {
117
122
  }
118
123
  }
119
124
 
120
- export type AddErrorSpy = jest.SpyInstance<void, [AddErrorOptions]>;
125
+ export type AddErrorSpy = jest.SpiedFunction<(options: AddErrorOptions) => void>;
121
126
 
122
127
  export const HOST_FACTORIES: Array<{ name: string; make: () => Host }> = [
123
128
  { name: "SimpleHost", make: () => new SimpleHost() },
@@ -5,17 +5,15 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
- import * as r from "runtypes";
10
- import { checkAlpha } from "./util/checkAlpha";
8
+ import { checkAlpha } from "./util/checkAlpha.js";
9
+ import { makeRule } from "./util/makeRule.js";
11
10
 
12
- const Options = r.Undefined;
13
-
14
- export const alphabeticalDependencies: RuleModule<typeof Options> = {
15
- check: function expectAlphabeticalDependencies(context: Context) {
11
+ export const alphabeticalDependencies = makeRule<undefined>({
12
+ name: "alphabeticalDependencies",
13
+ check: (context) => {
16
14
  checkAlpha(context, "dependencies");
17
15
  checkAlpha(context, "devDependencies");
18
16
  checkAlpha(context, "peerDependencies");
19
17
  },
20
- optionsRuntype: Options,
21
- };
18
+ validateOptions: () => {},
19
+ });
@@ -5,15 +5,13 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
- import * as r from "runtypes";
10
- import { checkAlpha } from "./util/checkAlpha";
8
+ import { checkAlpha } from "./util/checkAlpha.js";
9
+ import { makeRule } from "./util/makeRule.js";
11
10
 
12
- const Options = r.Undefined;
13
-
14
- export const alphabeticalScripts: RuleModule<typeof Options> = {
15
- check: function expectAlphabeticalScripts(context: Context) {
11
+ export const alphabeticalScripts = makeRule<undefined>({
12
+ name: "alphabeticalScripts",
13
+ check: (context) => {
16
14
  checkAlpha(context, "scripts");
17
15
  },
18
- optionsRuntype: Options,
19
- };
16
+ validateOptions: () => {},
17
+ });
@@ -5,13 +5,13 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { matchesAnyGlob } from "@monorepolint/utils";
10
10
  import { AggregateTiming } from "@monorepolint/utils";
11
- import path from "path";
11
+ import * as path from "node:path";
12
12
  import * as r from "runtypes";
13
- import { IPackageDependencyGraphNode, PackageDependencyGraphService } from "./util/packageDependencyGraphService";
14
-
13
+ import { makeRule } from "./util/makeRule.js";
14
+ import { IPackageDependencyGraphNode, PackageDependencyGraphService } from "./util/packageDependencyGraphService.js";
15
15
  // FIXME: This rule is messed. bannedTransitiveDependencies doesnt glob
16
16
 
17
17
  const bannedDepGlobsField = r.Union(
@@ -49,10 +49,9 @@ const setCache = new Map<ReadonlyArray<string>, Set<string>>();
49
49
 
50
50
  const aggregateTiming = new AggregateTiming(":bannedDependencies stats");
51
51
 
52
- export const bannedDependencies: RuleModule<typeof Options> & {
53
- printStats: () => void;
54
- } = {
55
- check: function expectAllowedDependencies(context, opts, extra) {
52
+ export const bannedDependencies = makeRule<Options>({
53
+ name: "bannedDependencies",
54
+ check: (context, opts, extra) => {
56
55
  aggregateTiming.start(extra?.id ?? "unknown id");
57
56
 
58
57
  const packageJson = context.getPackageJson();
@@ -108,11 +107,11 @@ export const bannedDependencies: RuleModule<typeof Options> & {
108
107
 
109
108
  aggregateTiming.stop();
110
109
  },
111
- optionsRuntype: Options,
110
+ validateOptions: Options.check,
112
111
  printStats: () => {
113
112
  aggregateTiming.printResults();
114
113
  },
115
- };
114
+ });
116
115
 
117
116
  function populateProblemsExact(banned: Set<string>, dependencies: ReadonlyArray<string>, violations: Set<string>) {
118
117
  for (const dependency of dependencies) {
@@ -5,10 +5,10 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
- import diff from "jest-diff";
8
+ import { Context } from "@monorepolint/config";
9
+ import { diff } from "jest-diff";
10
10
  import * as r from "runtypes";
11
-
11
+ import { makeRule } from "./util/makeRule.js";
12
12
  const Options = r
13
13
  .Record({
14
14
  ignoredDependencies: r.Array(r.String).Or(r.Undefined),
@@ -18,14 +18,15 @@ export type Options = r.Static<typeof Options>;
18
18
 
19
19
  const skippedVersions = ["*", "latest"];
20
20
 
21
- export const consistentDependencies = {
22
- check: function expectConsistentDependencies(context: Context, args: Options) {
21
+ export const consistentDependencies = makeRule<Options>({
22
+ name: "consistentDependencies",
23
+ check: (context, args) => {
23
24
  checkDeps(context, args, "dependencies");
24
25
  checkDeps(context, args, "devDependencies");
25
26
  // we don't check peer deps since they can be more lenient
26
27
  },
27
- optionsRuntype: Options,
28
- } as RuleModule<typeof Options>;
28
+ validateOptions: Options.check,
29
+ });
29
30
 
30
31
  function checkDeps(context: Context, args: Options, block: "dependencies" | "devDependencies" | "peerDependencies") {
31
32
  const packageJson = context.getPackageJson();
@@ -65,6 +66,7 @@ function checkDeps(context: Context, args: Options, block: "dependencies" | "dev
65
66
  }
66
67
 
67
68
  function filterKeys(ob: Record<string, string>, filterOb: Record<string, string>) {
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
70
  const newOb: Record<string, any> = {};
69
71
 
70
72
  for (const key of Object.keys(filterOb)) {
@@ -5,21 +5,22 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
10
  import * as r from "runtypes";
11
11
  import { coerce, SemVer } from "semver";
12
-
12
+ import { makeRule } from "./util/makeRule.js";
13
13
  export const Options = r.Record({
14
14
  matchDependencyVersions: r.Dictionary(r.Union(r.String, r.Array(r.String))),
15
15
  });
16
16
 
17
17
  export type Options = r.Static<typeof Options>;
18
18
 
19
- export const consistentVersions: RuleModule<typeof Options> = {
19
+ export const consistentVersions = makeRule({
20
+ name: "consistentVersions",
20
21
  check: checkConsistentVersions,
21
- optionsRuntype: Options,
22
- };
22
+ validateOptions: Options.check,
23
+ });
23
24
 
24
25
  function checkConsistentVersions(context: Context, options: Options) {
25
26
  for (const [dependencyPackageName, expectedPackageDependencyValue] of Object.entries(