@monorepolint/rules 0.5.0-alpha.103 → 0.5.0-alpha.106

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 (71) hide show
  1. package/.turbo/turbo-lint.log +34 -31
  2. package/.turbo/turbo-test.log +173 -166
  3. package/.turbo/turbo-transpile-typescript.log +4 -8
  4. package/build/js/index.js +75 -91
  5. package/build/js/index.js.map +1 -1
  6. package/build/tsconfig.tsbuildinfo +1 -1
  7. package/build/types/alphabeticalDependencies.d.ts +1 -15
  8. package/build/types/alphabeticalDependencies.d.ts.map +1 -1
  9. package/build/types/alphabeticalScripts.d.ts +1 -15
  10. package/build/types/alphabeticalScripts.d.ts.map +1 -1
  11. package/build/types/bannedDependencies.d.ts +36 -104
  12. package/build/types/bannedDependencies.d.ts.map +1 -1
  13. package/build/types/consistentDependencies.d.ts +3 -23
  14. package/build/types/consistentDependencies.d.ts.map +1 -1
  15. package/build/types/consistentVersions.d.ts +8 -34
  16. package/build/types/consistentVersions.d.ts.map +1 -1
  17. package/build/types/fileContents.d.ts +17 -89
  18. package/build/types/fileContents.d.ts.map +1 -1
  19. package/build/types/index.d.ts +13 -13
  20. package/build/types/index.d.ts.map +1 -1
  21. package/build/types/mustSatisfyPeerDependencies.d.ts +189 -483
  22. package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -1
  23. package/build/types/nestedWorkspaces.d.ts +1 -15
  24. package/build/types/nestedWorkspaces.d.ts.map +1 -1
  25. package/build/types/packageEntry.d.ts +30 -91
  26. package/build/types/packageEntry.d.ts.map +1 -1
  27. package/build/types/packageOrder.d.ts +3 -23
  28. package/build/types/packageOrder.d.ts.map +1 -1
  29. package/build/types/packageScript.d.ts +16 -68
  30. package/build/types/packageScript.d.ts.map +1 -1
  31. package/build/types/public/util.d.ts +2 -0
  32. package/build/types/public/util.d.ts.map +1 -0
  33. package/build/types/requireDependency.d.ts +22 -86
  34. package/build/types/requireDependency.d.ts.map +1 -1
  35. package/build/types/standardTsconfig.d.ts +9 -69
  36. package/build/types/standardTsconfig.d.ts.map +1 -1
  37. package/build/types/util/makeRule.d.ts +13 -0
  38. package/build/types/util/makeRule.d.ts.map +1 -0
  39. package/package.json +18 -12
  40. package/src/__tests__/alphabeticalScripts.spec.ts +2 -2
  41. package/src/__tests__/bannedDependencies.spec.ts +1 -3
  42. package/src/__tests__/consistentDependencies.spec.ts +2 -2
  43. package/src/__tests__/consistentVersions.spec.ts +1 -1
  44. package/src/__tests__/fileContents.spec.ts +16 -12
  45. package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +1 -1
  46. package/src/__tests__/nestedWorkspaces.spec.ts +1 -1
  47. package/src/__tests__/packageEntry.spec.ts +40 -30
  48. package/src/__tests__/packageOrder.spec.ts +20 -12
  49. package/src/__tests__/packageScript.spec.ts +55 -39
  50. package/src/__tests__/requireDependency.spec.ts +2 -2
  51. package/src/alphabeticalDependencies.ts +5 -7
  52. package/src/alphabeticalScripts.ts +5 -7
  53. package/src/bannedDependencies.ts +6 -8
  54. package/src/consistentDependencies.ts +6 -7
  55. package/src/consistentVersions.ts +5 -6
  56. package/src/fileContents.ts +7 -8
  57. package/src/index.ts +13 -13
  58. package/src/mustSatisfyPeerDependencies.ts +5 -9
  59. package/src/nestedWorkspaces.ts +6 -7
  60. package/src/packageEntry.ts +6 -7
  61. package/src/packageOrder.ts +6 -7
  62. package/src/packageScript.ts +5 -7
  63. package/src/public/util.ts +1 -0
  64. package/src/requireDependency.ts +6 -6
  65. package/src/standardTsconfig.ts +7 -9
  66. package/src/util/makeRule.ts +29 -0
  67. package/build/js/index.cjs +0 -1491
  68. package/build/js/index.cjs.map +0 -1
  69. package/build/types/util/createNewRuleConversion.d.ts +0 -30
  70. package/build/types/util/createNewRuleConversion.d.ts.map +0 -1
  71. package/src/util/createNewRuleConversion.ts +0 -38
@@ -1,15 +1,15 @@
1
1
  /*!
2
- * Copyright 2019 Palantir Technologies, Inc.
2
+ * Copyright 2023 Palantir Technologies, Inc.
3
3
  *
4
4
  * Licensed under the MIT license. See LICENSE file in the project root for details.
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { diff } from "jest-diff";
10
10
  import * as path from "path";
11
11
  import * as r from "runtypes";
12
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
12
+ import { makeRule } from "./util/makeRule.js";
13
13
  const Options = r.Union(
14
14
  r.Record({
15
15
  file: r.String,
@@ -35,8 +35,9 @@ const Options = r.Union(
35
35
 
36
36
  type Options = r.Static<typeof Options>;
37
37
 
38
- export const fileContents = {
39
- check: function expectFileContents(context: Context, opts: Options) {
38
+ export const fileContents = makeRule({
39
+ name: "fileContents",
40
+ check: (context, opts) => {
40
41
  const fullPath = path.join(context.packageDir, opts.file);
41
42
  const expectedContent = getExpectedContents(context, opts);
42
43
 
@@ -59,7 +60,7 @@ export const fileContents = {
59
60
  }
60
61
  },
61
62
  optionsRuntype: Options,
62
- } as RuleModule<typeof Options>;
63
+ });
63
64
 
64
65
  const optionsCache = new Map<Options, ((context: Context) => string | undefined) | string | undefined>();
65
66
 
@@ -88,5 +89,3 @@ function getExpectedContents(context: Context, opts: Options) {
88
89
  return opts.template;
89
90
  }
90
91
  }
91
-
92
- export const FileContents = createNewRuleConversion("FileContents", fileContents);
package/src/index.ts CHANGED
@@ -5,16 +5,16 @@
5
5
  *
6
6
  */
7
7
 
8
- export { alphabeticalDependencies, AlphabeticalDependencies } from "./alphabeticalDependencies.js";
9
- export { alphabeticalScripts, AlphabeticalScripts } from "./alphabeticalScripts.js";
10
- export { bannedDependencies, BannedDependencies } from "./bannedDependencies.js";
11
- export { consistentDependencies, ConsistentDependencies } from "./consistentDependencies.js";
12
- export { consistentVersions, ConsistentVersions } from "./consistentVersions.js";
13
- export { fileContents, FileContents } from "./fileContents.js";
14
- export { mustSatisfyPeerDependencies, MustSatisfyPeerDependencies } from "./mustSatisfyPeerDependencies.js";
15
- export { packageOrder, PackageOrder } from "./packageOrder.js";
16
- export { packageEntry, PackageEntry } from "./packageEntry.js";
17
- export { packageScript, PackageScript } from "./packageScript.js";
18
- export { standardTsconfig, StandardTsConfig } from "./standardTsconfig.js";
19
- export { nestedWorkspaces, NestedWorkspaces } from "./nestedWorkspaces.js";
20
- export { requireDependency, RequireDependency } from "./requireDependency.js";
8
+ export { alphabeticalDependencies } from "./alphabeticalDependencies.js";
9
+ export { alphabeticalScripts } from "./alphabeticalScripts.js";
10
+ export { bannedDependencies } from "./bannedDependencies.js";
11
+ export { consistentDependencies } from "./consistentDependencies.js";
12
+ export { consistentVersions } from "./consistentVersions.js";
13
+ export { fileContents } from "./fileContents.js";
14
+ export { mustSatisfyPeerDependencies } from "./mustSatisfyPeerDependencies.js";
15
+ export { packageOrder } from "./packageOrder.js";
16
+ export { packageEntry } from "./packageEntry.js";
17
+ export { packageScript } from "./packageScript.js";
18
+ export { standardTsconfig } from "./standardTsconfig.js";
19
+ export { nestedWorkspaces } from "./nestedWorkspaces.js";
20
+ export { requireDependency } from "./requireDependency.js";
@@ -5,13 +5,13 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { Host, mutateJson, PackageJson } from "@monorepolint/utils";
10
10
  import * as path from "node:path";
11
11
  import * as r from "runtypes";
12
12
  import { coerce } from "semver";
13
13
  import resolvePackagePath from "resolve-package-path";
14
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
14
+ import { makeRule } from "./util/makeRule.js";
15
15
 
16
16
  const Options = r.Union(
17
17
  r.Partial({
@@ -184,15 +184,11 @@ const Options = r.Union(
184
184
 
185
185
  export type Options = r.Static<typeof Options>;
186
186
 
187
- export const mustSatisfyPeerDependencies: RuleModule<typeof Options> = {
187
+ export const mustSatisfyPeerDependencies = makeRule({
188
+ name: "mustSatisfyPeerDependencies",
188
189
  check: checkSatisfyPeerDependencies,
189
190
  optionsRuntype: Options,
190
- };
191
-
192
- export const MustSatisfyPeerDependencies = createNewRuleConversion(
193
- "MustSatisfyPeerDependencies",
194
- mustSatisfyPeerDependencies
195
- );
191
+ });
196
192
 
197
193
  /**
198
194
  * separating on `|`, this regex allows any of the following formats:
@@ -5,18 +5,19 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
9
8
  import * as globby from "globby";
10
9
  import * as path from "node:path";
11
10
  import * as r from "runtypes";
12
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
11
+ import { makeRule } from "./util/makeRule.js";
12
+
13
13
  export const Options = r.Undefined;
14
14
 
15
15
  type Options = r.Static<typeof Options>;
16
16
 
17
17
  // Enforce that the root package.json contains all of the workspaces in the repo (including nested packages)
18
- export const nestedWorkspaces: RuleModule<typeof Options> = {
19
- check: (context: Context) => {
18
+ export const nestedWorkspaces = makeRule({
19
+ name: "nestedWorkspaces",
20
+ check: (context) => {
20
21
  const rootPackageJson = context.getWorkspaceContext().getPackageJson();
21
22
 
22
23
  // Expand a set of globs covering all package.json files in the entire repo (except the root)
@@ -56,6 +57,4 @@ export const nestedWorkspaces: RuleModule<typeof Options> = {
56
57
  }
57
58
  },
58
59
  optionsRuntype: Options,
59
- };
60
-
61
- export const NestedWorkspaces = createNewRuleConversion("NestedWorkspaces", nestedWorkspaces);
60
+ });
@@ -5,11 +5,11 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
9
8
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
9
  import { diff } from "jest-diff";
11
10
  import * as r from "runtypes";
12
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
11
+ import { makeRule } from "./util/makeRule.js";
12
+
13
13
  export const Options = r.Union(
14
14
  r
15
15
  .Record({
@@ -37,8 +37,9 @@ export const Options = r.Union(
37
37
 
38
38
  export type Options = r.Static<typeof Options>;
39
39
 
40
- export const packageEntry: RuleModule<typeof Options> = {
41
- check: function expectPackageEntry(context: Context, options: Options) {
40
+ export const packageEntry = makeRule({
41
+ name: "packageEntry",
42
+ check: (context, options) => {
42
43
  const packageJson = context.getPackageJson();
43
44
 
44
45
  if (options.entries) {
@@ -78,9 +79,7 @@ export const packageEntry: RuleModule<typeof Options> = {
78
79
  }
79
80
  },
80
81
  optionsRuntype: Options,
81
- };
82
-
83
- export const PackageEntry = createNewRuleConversion("PackageEntry", packageEntry);
82
+ });
84
83
 
85
84
  export function createStandardizedEntryErrorMessage(key: string) {
86
85
  return `Expected standardized entry for '${key}'`;
@@ -5,10 +5,10 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { diff } from "jest-diff";
10
10
  import * as r from "runtypes";
11
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
11
+ import { makeRule } from "./util/makeRule.js";
12
12
  type OrderFunction = (context: Context) => (a: string, b: string) => number;
13
13
 
14
14
  const Options = r
@@ -51,8 +51,9 @@ const defaultKeyOrder = [
51
51
  "publishConfig",
52
52
  ];
53
53
 
54
- export const packageOrder = {
55
- check: function expectPackageOrder(context: Context, opts: Options) {
54
+ export const packageOrder = makeRule({
55
+ name: "packageOrder",
56
+ check: (context, opts) => {
56
57
  const packageJson = context.getPackageJson();
57
58
  const packagePath = context.getPackageJsonPath();
58
59
 
@@ -81,9 +82,7 @@ export const packageOrder = {
81
82
  }
82
83
  },
83
84
  optionsRuntype: Options,
84
- } as RuleModule<typeof Options>;
85
-
86
- export const PackageOrder = createNewRuleConversion("PackageOrder", packageOrder);
85
+ });
87
86
 
88
87
  function arrayOrderCompare(a: ReadonlyArray<string>, b: ReadonlyArray<string>) {
89
88
  for (let index = 0; index < a.length; index++) {
@@ -5,11 +5,10 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
9
8
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
11
9
  import { diff } from "jest-diff";
12
10
  import * as r from "runtypes";
11
+ import { makeRule } from "./util/makeRule.js";
13
12
 
14
13
  export const Options = r.Record({
15
14
  scripts: r.Dictionary(
@@ -27,8 +26,9 @@ export type Options = r.Static<typeof Options>;
27
26
 
28
27
  export const MSG_NO_SCRIPTS_BLOCK = "No scripts block in package.json";
29
28
 
30
- export const packageScript = {
31
- check: function expectPackageScript(context: Context, options: Options) {
29
+ export const packageScript = makeRule({
30
+ name: "packageScript",
31
+ check: (context, options) => {
32
32
  const packageJson = context.getPackageJson();
33
33
  if (packageJson.scripts === undefined) {
34
34
  context.addError({
@@ -96,6 +96,4 @@ export const packageScript = {
96
96
  }
97
97
  },
98
98
  optionsRuntype: Options,
99
- } as RuleModule<typeof Options>;
100
-
101
- export const PackageScript = createNewRuleConversion("PackageScript", packageScript);
99
+ });
@@ -0,0 +1 @@
1
+ export { makeRule } from "../util/makeRule.js";
@@ -5,11 +5,12 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
10
  import { diff } from "jest-diff";
11
11
  import * as r from "runtypes";
12
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
12
+ import { makeRule } from "./util/makeRule.js";
13
+
13
14
  const Options = r.Partial({
14
15
  dependencies: r.Dictionary(r.String),
15
16
  devDependencies: r.Dictionary(r.String),
@@ -19,7 +20,8 @@ const Options = r.Partial({
19
20
 
20
21
  type Options = r.Static<typeof Options>;
21
22
 
22
- export const requireDependency = {
23
+ export const requireDependency = makeRule({
24
+ name: "requireDependency",
23
25
  check: function expectPackageEntry(context: Context, options: Options) {
24
26
  const packageJson = context.getPackageJson();
25
27
  const packageJsonPath = context.getPackageJsonPath();
@@ -66,6 +68,4 @@ export const requireDependency = {
66
68
  });
67
69
  },
68
70
  optionsRuntype: Options,
69
- } as RuleModule<typeof Options>;
70
-
71
- export const RequireDependency = createNewRuleConversion("RequireDependency", requireDependency);
71
+ });
@@ -5,12 +5,12 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/config";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { matchesAnyGlob } from "@monorepolint/utils";
10
10
  import { diff } from "jest-diff";
11
- import { createNewRuleConversion } from "./util/createNewRuleConversion.js";
12
11
  import * as path from "path";
13
12
  import * as r from "runtypes";
13
+ import { makeRule } from "./util/makeRule.js";
14
14
 
15
15
  const DEFAULT_TSCONFIG_FILENAME = "tsconfig.json";
16
16
 
@@ -41,8 +41,9 @@ const Options = r
41
41
 
42
42
  export interface Options extends r.Static<typeof Options> {}
43
43
 
44
- export const standardTsconfig = {
45
- check: async function expectStandardTsconfig(context: Context, opts: Options) {
44
+ export const standardTsconfig = makeRule({
45
+ name: "standardTsconfig",
46
+ check: async (context, opts) => {
46
47
  const tsconfigFileName = opts.file ?? DEFAULT_TSCONFIG_FILENAME;
47
48
  const fullPath = path.resolve(context.packageDir, tsconfigFileName);
48
49
  const generator = getGenerator(context, opts);
@@ -74,9 +75,7 @@ export const standardTsconfig = {
74
75
  }
75
76
  },
76
77
  optionsRuntype: Options,
77
- } as RuleModule<typeof Options>;
78
-
79
- export const StandardTsConfig = createNewRuleConversion("StandardTsconfig", standardTsconfig);
78
+ });
80
79
 
81
80
  function getGenerator(context: Context, opts: Options) {
82
81
  if (opts.generator) {
@@ -110,10 +109,9 @@ function makeGenerator(
110
109
 
111
110
  const packageJson = context.getPackageJson();
112
111
  const deps = [...Object.keys(packageJson.dependencies || {}), ...Object.keys(packageJson.devDependencies || {})];
113
-
114
112
  for (const dep of deps) {
115
113
  const packageDir = nameToDirectory.get(dep);
116
- if (packageDir !== undefined && (excludedReferences === undefined || matchesAnyGlob(dep, excludedReferences))) {
114
+ if (packageDir !== undefined && (excludedReferences === undefined || !matchesAnyGlob(dep, excludedReferences))) {
117
115
  const absoluteReferencePath =
118
116
  tsconfigReferenceFile !== undefined ? path.join(packageDir, tsconfigReferenceFile) : packageDir;
119
117
  template.references.push({
@@ -0,0 +1,29 @@
1
+ import { Context, RuleEntry, RuleModule } from "@monorepolint/config";
2
+ import * as r from "runtypes";
3
+
4
+ let globalId = 0;
5
+ export function makeRule<T extends r.Runtype<unknown>>({
6
+ name,
7
+ check,
8
+ optionsRuntype,
9
+ printStats,
10
+ }: {
11
+ name: string;
12
+ check: (context: Context, options: r.Static<T>, extra: { id: string }) => Promise<unknown> | unknown;
13
+ optionsRuntype: T;
14
+ printStats?: () => void;
15
+ }): RuleFunction<T> {
16
+ return function (ruleEntry) {
17
+ const id = `${name} :: ${globalId++}`;
18
+ return {
19
+ id,
20
+ check: (context) => check(context, ruleEntry.options, { id }),
21
+ name,
22
+ optionsRuntype,
23
+ ruleEntry,
24
+ printStats,
25
+ };
26
+ };
27
+ }
28
+
29
+ type RuleFunction<T extends r.Runtype<any>> = (ruleEntry: RuleEntry<r.Static<T>>) => RuleModule<T>;