@alextheman/eslint-plugin 2.8.2 → 2.9.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/dist/index.cjs CHANGED
@@ -3759,7 +3759,7 @@ module.exports = __toCommonJS(index_exports);
3759
3759
 
3760
3760
  // package.json
3761
3761
  var name = "@alextheman/eslint-plugin";
3762
- var version = "2.8.2";
3762
+ var version = "2.9.0";
3763
3763
 
3764
3764
  // src/configs/index.ts
3765
3765
  var import_eslint_plugin_package_json = __toESM(require("eslint-plugin-package-json"), 1);
@@ -4464,7 +4464,7 @@ var configs_default = createAlexPluginConfigs;
4464
4464
 
4465
4465
  // src/rules/consistent-test-function.ts
4466
4466
  var import_utils2 = require("@typescript-eslint/utils");
4467
- var import_zod = __toESM(require("zod"), 1);
4467
+ var import_zod2 = __toESM(require("zod"), 1);
4468
4468
 
4469
4469
  // src/createRule.ts
4470
4470
  var import_utils = require("@typescript-eslint/utils");
@@ -4473,6 +4473,14 @@ var createRule = import_utils.ESLintUtils.RuleCreator((ruleName) => {
4473
4473
  });
4474
4474
  var createRule_default = createRule;
4475
4475
 
4476
+ // src/utility/createRuleSchema.ts
4477
+ var import_utility3 = require("@alextheman/utility");
4478
+ var import_zod = __toESM(require("zod"), 1);
4479
+ function createRuleSchema(schema6) {
4480
+ return [(0, import_utility3.omitProperties)(import_zod.default.toJSONSchema(schema6), "$schema")];
4481
+ }
4482
+ var createRuleSchema_default = createRuleSchema;
4483
+
4476
4484
  // src/utility/getImportSpecifiersAfterRemoving.ts
4477
4485
  function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
4478
4486
  return specifiers.filter((specifier) => {
@@ -4484,10 +4492,17 @@ function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
4484
4492
  var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
4485
4493
 
4486
4494
  // src/rules/consistent-test-function.ts
4487
- var validTestFunctionsSchema = import_zod.default.enum(["test", "it"]);
4495
+ var validTestFunctionsSchema = import_zod2.default.enum(["test", "it"]);
4488
4496
  function parseTestFunction(data) {
4489
4497
  return validTestFunctionsSchema.parse(data);
4490
4498
  }
4499
+ var consistentTestFunctionOptionsSchema = import_zod2.default.object({
4500
+ preference: validTestFunctionsSchema
4501
+ }).partial();
4502
+ function parseConsistentTestFunctionOptions(data) {
4503
+ return consistentTestFunctionOptionsSchema.parse(data);
4504
+ }
4505
+ var schema = createRuleSchema_default(consistentTestFunctionOptionsSchema);
4491
4506
  var consistentTestFunction = createRule_default({
4492
4507
  name: "consistent-test-function",
4493
4508
  meta: {
@@ -4499,46 +4514,36 @@ var consistentTestFunction = createRule_default({
4499
4514
  },
4500
4515
  type: "suggestion",
4501
4516
  fixable: "code",
4502
- schema: [
4503
- {
4504
- type: "object",
4505
- properties: {
4506
- preference: {
4507
- type: "string",
4508
- enum: ["it", "test"]
4509
- }
4510
- },
4511
- additionalProperties: false
4512
- }
4513
- ]
4517
+ schema
4514
4518
  },
4515
4519
  defaultOptions: [{ preference: "test" }],
4516
4520
  create(context) {
4517
4521
  var _a;
4518
- const preference = (_a = context.options[0]) == null ? void 0 : _a.preference;
4519
- const validatedPreference = parseTestFunction(preference != null ? preference : "test");
4522
+ const { preference } = parseConsistentTestFunctionOptions(
4523
+ (_a = context.options[0]) != null ? _a : { preference: "test" }
4524
+ );
4520
4525
  return {
4521
4526
  CallExpression(node) {
4522
- if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "it" && validatedPreference === "test") {
4527
+ if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "it" && preference === "test") {
4523
4528
  return context.report({
4524
4529
  node,
4525
4530
  messageId: "message",
4526
4531
  data: {
4527
4532
  source: node.callee.name,
4528
- preference: validatedPreference
4533
+ preference
4529
4534
  },
4530
4535
  fix(fixer) {
4531
4536
  return fixer.replaceText(node.callee, "test");
4532
4537
  }
4533
4538
  });
4534
4539
  }
4535
- if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "test" && validatedPreference === "it") {
4540
+ if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "test" && preference === "it") {
4536
4541
  return context.report({
4537
4542
  node,
4538
4543
  messageId: "message",
4539
4544
  data: {
4540
4545
  source: node.callee.name,
4541
- preference: validatedPreference
4546
+ preference
4542
4547
  },
4543
4548
  fix(fixer) {
4544
4549
  return fixer.replaceText(node.callee, "it");
@@ -4548,13 +4553,13 @@ var consistentTestFunction = createRule_default({
4548
4553
  },
4549
4554
  ImportDeclaration(node) {
4550
4555
  for (const specifier of node.specifiers) {
4551
- if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && validatedPreference === "test") {
4556
+ if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && preference === "test") {
4552
4557
  return context.report({
4553
4558
  node,
4554
4559
  messageId: "message",
4555
4560
  data: {
4556
4561
  source: specifier.imported.name,
4557
- preference: validatedPreference
4562
+ preference
4558
4563
  },
4559
4564
  fix(fixer) {
4560
4565
  const importedNames = node.specifiers.map((specifier2) => {
@@ -4576,18 +4581,18 @@ var consistentTestFunction = createRule_default({
4576
4581
  }
4577
4582
  return fixer.replaceTextRange(
4578
4583
  [specifier.imported.range[0], specifier.imported.range[1]],
4579
- validatedPreference
4584
+ preference
4580
4585
  );
4581
4586
  }
4582
4587
  });
4583
4588
  }
4584
- if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && validatedPreference === "it") {
4589
+ if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && preference === "it") {
4585
4590
  return context.report({
4586
4591
  node,
4587
4592
  messageId: "message",
4588
4593
  data: {
4589
4594
  source: specifier.imported.name,
4590
- preference: validatedPreference
4595
+ preference
4591
4596
  },
4592
4597
  fix(fixer) {
4593
4598
  const importedNames = node.specifiers.map((specifier2) => {
@@ -4609,7 +4614,7 @@ var consistentTestFunction = createRule_default({
4609
4614
  }
4610
4615
  return fixer.replaceTextRange(
4611
4616
  [specifier.imported.range[0], specifier.imported.range[1]],
4612
- validatedPreference
4617
+ preference
4613
4618
  );
4614
4619
  }
4615
4620
  });
@@ -4661,6 +4666,14 @@ var noIsolatedTests = createRule_default({
4661
4666
  var no_isolated_tests_default = noIsolatedTests;
4662
4667
 
4663
4668
  // src/rules/no-namespace-imports.ts
4669
+ var import_zod3 = __toESM(require("zod"), 1);
4670
+ var noNamespaceImportsOptionsSchema = import_zod3.default.object({
4671
+ allow: import_zod3.default.array(import_zod3.default.string())
4672
+ }).partial();
4673
+ function parseNoNamespaceImportsOptions(data) {
4674
+ return noNamespaceImportsOptionsSchema.parse(data);
4675
+ }
4676
+ var schema2 = createRuleSchema_default(noNamespaceImportsOptionsSchema);
4664
4677
  var noNamespaceImports = createRule_default({
4665
4678
  name: "no-namespace-imports",
4666
4679
  meta: {
@@ -4671,31 +4684,17 @@ var noNamespaceImports = createRule_default({
4671
4684
  message: 'Import * from "{{source}}" is not allowed. Please use named imports instead.'
4672
4685
  },
4673
4686
  type: "suggestion",
4674
- schema: [
4675
- {
4676
- type: "object",
4677
- properties: {
4678
- allow: {
4679
- type: "array",
4680
- items: {
4681
- type: "string"
4682
- },
4683
- uniqueItems: true
4684
- }
4685
- },
4686
- additionalProperties: false
4687
- }
4688
- ]
4687
+ schema: schema2
4689
4688
  },
4690
4689
  defaultOptions: [{ allow: [""] }],
4691
4690
  create(context) {
4692
4691
  var _a;
4693
- const allowableNamedImports = (_a = context.options[0]) == null ? void 0 : _a.allow;
4692
+ const { allow } = parseNoNamespaceImportsOptions((_a = context.options[0]) != null ? _a : { allow: [] });
4694
4693
  return {
4695
4694
  ImportDeclaration(node) {
4696
4695
  const allSpecifiers = node.specifiers;
4697
4696
  for (const specifier of allSpecifiers) {
4698
- if (specifier.type === "ImportNamespaceSpecifier" && !(allowableNamedImports == null ? void 0 : allowableNamedImports.includes(node.source.value))) {
4697
+ if (specifier.type === "ImportNamespaceSpecifier" && !(allow == null ? void 0 : allow.includes(node.source.value))) {
4699
4698
  context.report({
4700
4699
  node,
4701
4700
  messageId: "message",
@@ -4748,6 +4747,14 @@ var noPluginConfigAccessFromSrcConfigs = createRule_default({
4748
4747
  var no_plugin_configs_access_from_src_configs_default = noPluginConfigAccessFromSrcConfigs;
4749
4748
 
4750
4749
  // src/rules/no-relative-imports.ts
4750
+ var import_zod4 = __toESM(require("zod"), 1);
4751
+ var noRelativeImportsOptionsSchema = import_zod4.default.object({
4752
+ depth: import_zod4.default.int().nonnegative()
4753
+ }).partial();
4754
+ function parseNoRelativeImportsOptions(data) {
4755
+ return noRelativeImportsOptionsSchema.parse(data);
4756
+ }
4757
+ var schema3 = createRuleSchema_default(noRelativeImportsOptionsSchema);
4751
4758
  var noRelativeImports = createRule_default({
4752
4759
  name: "no-relative-imports",
4753
4760
  meta: {
@@ -4759,34 +4766,16 @@ var noRelativeImports = createRule_default({
4759
4766
  stupidPath: "For the love of God, please do not mix relative path parts in your import statements like that! How can you possibly be ok with {{source}}?!"
4760
4767
  },
4761
4768
  type: "suggestion",
4762
- schema: [
4763
- {
4764
- type: "object",
4765
- properties: {
4766
- depth: {
4767
- type: "number"
4768
- }
4769
- },
4770
- additionalProperties: false
4771
- }
4772
- ]
4769
+ schema: schema3
4773
4770
  },
4774
4771
  defaultOptions: [{ depth: void 0 }],
4775
4772
  create(context) {
4776
4773
  var _a;
4777
- const allowedDepth = (_a = context.options[0]) == null ? void 0 : _a.depth;
4778
- if (allowedDepth !== void 0) {
4779
- if (allowedDepth % 1 !== 0) {
4780
- throw new Error("NON_INTEGER_DEPTH_NOT_ALLOWED");
4781
- }
4782
- if (allowedDepth < 0) {
4783
- throw new Error("NEGATIVE_DEPTH_NOT_ALLOWED");
4784
- }
4785
- }
4774
+ const { depth } = parseNoRelativeImportsOptions((_a = context.options[0]) != null ? _a : { depth: void 0 });
4786
4775
  return {
4787
4776
  ImportDeclaration(node) {
4788
4777
  if (node.source.value.includes("./") || node.source.value.includes("../")) {
4789
- if (allowedDepth === void 0) {
4778
+ if (depth === void 0) {
4790
4779
  return context.report({
4791
4780
  node,
4792
4781
  messageId: "strictNoRelative",
@@ -4814,18 +4803,18 @@ var noRelativeImports = createRule_default({
4814
4803
  }
4815
4804
  });
4816
4805
  }
4817
- if (allowedDepth === 0 && importPathParts[0] === ".") {
4806
+ if (depth === 0 && importPathParts[0] === ".") {
4818
4807
  return;
4819
4808
  }
4820
4809
  let endOfRelativePathFound = false;
4821
- for (const part of importPathParts.slice(0, allowedDepth + 1)) {
4810
+ for (const part of importPathParts.slice(0, depth + 1)) {
4822
4811
  if (part !== "..") {
4823
4812
  endOfRelativePathFound = true;
4824
4813
  break;
4825
4814
  }
4826
4815
  }
4827
4816
  if (!endOfRelativePathFound) {
4828
- if (allowedDepth === 0) {
4817
+ if (depth === 0) {
4829
4818
  return context.report({
4830
4819
  node,
4831
4820
  messageId: "rootOnly",
@@ -4839,8 +4828,8 @@ var noRelativeImports = createRule_default({
4839
4828
  messageId: "exceededAllowedDepth",
4840
4829
  data: {
4841
4830
  source: node.source.value,
4842
- depth: allowedDepth,
4843
- s: allowedDepth !== 1 ? "s" : ""
4831
+ depth,
4832
+ s: depth !== 1 ? "s" : ""
4844
4833
  }
4845
4834
  });
4846
4835
  }
@@ -4885,9 +4874,20 @@ var no_skipped_tests_default = noSkippedTests;
4885
4874
 
4886
4875
  // src/rules/standardise-error-messages.ts
4887
4876
  var import_utils4 = require("@typescript-eslint/utils");
4877
+ var import_zod5 = __toESM(require("zod"), 1);
4878
+ var standardiseErrorMessagesOptionsSchema = import_zod5.default.object({
4879
+ regex: import_zod5.default.string()
4880
+ }).partial();
4881
+ function parseStandardiseErrorMessagesOptions(data) {
4882
+ return standardiseErrorMessagesOptionsSchema.parse(data);
4883
+ }
4884
+ var schema4 = createRuleSchema_default(standardiseErrorMessagesOptionsSchema);
4885
+ var defaultErrorRegex = "^[A-Z]+(?:_[A-Z]+)*$";
4888
4886
  function checkCurrentNode(context, node) {
4889
- var _a, _b;
4890
- const errorRegex = (_b = (_a = context.options[0]) == null ? void 0 : _a.regex) != null ? _b : "^[A-Z]+(?:_[A-Z]+)*$";
4887
+ var _a;
4888
+ const { regex: errorRegex = defaultErrorRegex } = parseStandardiseErrorMessagesOptions(
4889
+ (_a = context.options[0]) != null ? _a : { regex: defaultErrorRegex }
4890
+ );
4891
4891
  if (node.callee.type === import_utils4.AST_NODE_TYPES.Identifier && node.callee.name === "Error") {
4892
4892
  const [errorArgument] = node.arguments;
4893
4893
  const errorMessage = errorArgument.type === import_utils4.AST_NODE_TYPES.Literal ? errorArgument.value : "";
@@ -4913,19 +4913,9 @@ var standardiseErrorMessages = createRule_default({
4913
4913
  message: "Expected error message {{error}} to match {{regex}}."
4914
4914
  },
4915
4915
  type: "suggestion",
4916
- schema: [
4917
- {
4918
- type: "object",
4919
- properties: {
4920
- regex: {
4921
- type: "string"
4922
- }
4923
- },
4924
- additionalProperties: false
4925
- }
4926
- ]
4916
+ schema: schema4
4927
4917
  },
4928
- defaultOptions: [{ regex: "^[A-Z]+(?:_[A-Z]+)*$" }],
4918
+ defaultOptions: [{ regex: defaultErrorRegex }],
4929
4919
  create(context) {
4930
4920
  return {
4931
4921
  CallExpression(node) {
@@ -4941,6 +4931,14 @@ var standardise_error_messages_default = standardiseErrorMessages;
4941
4931
 
4942
4932
  // src/rules/use-normalized-imports.ts
4943
4933
  var import_path = __toESM(require("path"), 1);
4934
+ var import_zod6 = __toESM(require("zod"), 1);
4935
+ var useNormalizedImportsOptionsSchema = import_zod6.default.object({
4936
+ fixable: import_zod6.default.boolean()
4937
+ }).partial();
4938
+ function parseUseNormalizedImportsOptionsSchema(data) {
4939
+ return useNormalizedImportsOptionsSchema.parse(data);
4940
+ }
4941
+ var schema5 = createRuleSchema_default(useNormalizedImportsOptionsSchema);
4944
4942
  var useNormalizedImports = createRule_default({
4945
4943
  name: "use-normalized-imports",
4946
4944
  meta: {
@@ -4951,23 +4949,15 @@ var useNormalizedImports = createRule_default({
4951
4949
  pathNotNormalized: "Import path {{nonNormalized}} is not normalised. Please use {{normalized}} instead."
4952
4950
  },
4953
4951
  type: "suggestion",
4954
- schema: [
4955
- {
4956
- type: "object",
4957
- properties: {
4958
- fixable: {
4959
- type: "boolean"
4960
- }
4961
- },
4962
- additionalProperties: false
4963
- }
4964
- ],
4952
+ schema: schema5,
4965
4953
  fixable: "code"
4966
4954
  },
4967
4955
  defaultOptions: [{ fixable: true }],
4968
4956
  create(context) {
4969
- var _a, _b;
4970
- const isFixable = (_b = (_a = context.options[0]) == null ? void 0 : _a.fixable) != null ? _b : true;
4957
+ var _a;
4958
+ const { fixable: isFixable } = parseUseNormalizedImportsOptionsSchema(
4959
+ (_a = context.options[0]) != null ? _a : { fixable: true }
4960
+ );
4971
4961
  return {
4972
4962
  ImportDeclaration(node) {
4973
4963
  const normalizedPath = import_path.default.posix.normalize(node.source.value);
package/dist/index.d.cts CHANGED
@@ -4,7 +4,7 @@ import { Config } from 'prettier';
4
4
  import z from 'zod';
5
5
 
6
6
  var name = "@alextheman/eslint-plugin";
7
- var version = "2.8.2";
7
+ var version = "2.9.0";
8
8
 
9
9
  type CamelToKebab<S extends string> = S extends `${IgnoreCase<"J">}avaScript${infer Rest}` ? Rest extends "" ? "javascript" : `javascript${CamelToKebab<Rest>}` : S extends `${IgnoreCase<"T">}ypeScript${infer Rest}` ? Rest extends "" ? "typescript" : `typescript${CamelToKebab<Rest>}` : S extends `${infer Head}${infer Tail}` ? Head extends Lowercase<Head> ? `${Head}${CamelToKebab<Tail>}` : `-${Lowercase<Head>}${CamelToKebab<Tail>}` : S;
10
10
 
@@ -64,35 +64,32 @@ declare const validTestFunctionsSchema: z.ZodEnum<{
64
64
  }>;
65
65
  type TestFunction = z.infer<typeof validTestFunctionsSchema>;
66
66
  declare function parseTestFunction(data: unknown): TestFunction;
67
+ declare const consistentTestFunctionOptionsSchema: z.ZodObject<{
68
+ preference: z.ZodOptional<z.ZodEnum<{
69
+ test: "test";
70
+ it: "it";
71
+ }>>;
72
+ }, z.core.$strip>;
73
+ type ConsistentTestFunctionOptions = z.infer<typeof consistentTestFunctionOptionsSchema>;
67
74
 
68
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
69
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
70
- interface ConsistentTestFunctionOptions {
71
- preference?: "it" | "test";
72
- }
73
-
74
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
75
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
76
- interface NoNamespaceImportsOptions {
77
- allow?: string[];
78
- }
75
+ declare const noNamespaceImportsOptionsSchema: z.ZodObject<{
76
+ allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ }, z.core.$strip>;
78
+ type NoNamespaceImportsOptions = z.infer<typeof noNamespaceImportsOptionsSchema>;
79
79
 
80
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
81
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
82
- interface NoRelativeImportsOptions {
83
- depth?: number;
84
- }
80
+ declare const noRelativeImportsOptionsSchema: z.ZodObject<{
81
+ depth: z.ZodOptional<z.ZodInt>;
82
+ }, z.core.$strip>;
83
+ type NoRelativeImportsOptions = z.infer<typeof noRelativeImportsOptionsSchema>;
85
84
 
86
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
87
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
88
- interface StandardiseErrorMessagesOptions {
89
- regex?: string;
90
- }
85
+ declare const standardiseErrorMessagesOptionsSchema: z.ZodObject<{
86
+ regex: z.ZodOptional<z.ZodString>;
87
+ }, z.core.$strip>;
88
+ type StandardiseErrorMessagesOptions = z.infer<typeof standardiseErrorMessagesOptionsSchema>;
91
89
 
92
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
93
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
94
- interface UseNormalizedImportsOptions {
95
- fixable?: boolean;
96
- }
90
+ declare const useNormalizedImportsOptionsSchema: z.ZodObject<{
91
+ fixable: z.ZodOptional<z.ZodBoolean>;
92
+ }, z.core.$strip>;
93
+ type UseNormalizedImportsOptions = z.infer<typeof useNormalizedImportsOptionsSchema>;
97
94
 
98
95
  export { type AlexPlugin, type AlexPluginConfigGroup, type CombinedConfig, type ConfigGroupName, type ConfigKey, type ConsistentTestFunctionOptions, type GeneralConfig, type NoNamespaceImportsOptions, type NoRelativeImportsOptions, type PersonalConfig, type PluginConfig, type StandardiseErrorMessagesOptions, type TestFunction, type UseNormalizedImportsOptions, alexPlugin as default, parseTestFunction, prettierRules, sortObjects };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Config } from 'prettier';
4
4
  import z from 'zod';
5
5
 
6
6
  var name = "@alextheman/eslint-plugin";
7
- var version = "2.8.2";
7
+ var version = "2.9.0";
8
8
 
9
9
  type CamelToKebab<S extends string> = S extends `${IgnoreCase<"J">}avaScript${infer Rest}` ? Rest extends "" ? "javascript" : `javascript${CamelToKebab<Rest>}` : S extends `${IgnoreCase<"T">}ypeScript${infer Rest}` ? Rest extends "" ? "typescript" : `typescript${CamelToKebab<Rest>}` : S extends `${infer Head}${infer Tail}` ? Head extends Lowercase<Head> ? `${Head}${CamelToKebab<Tail>}` : `-${Lowercase<Head>}${CamelToKebab<Tail>}` : S;
10
10
 
@@ -64,35 +64,32 @@ declare const validTestFunctionsSchema: z.ZodEnum<{
64
64
  }>;
65
65
  type TestFunction = z.infer<typeof validTestFunctionsSchema>;
66
66
  declare function parseTestFunction(data: unknown): TestFunction;
67
+ declare const consistentTestFunctionOptionsSchema: z.ZodObject<{
68
+ preference: z.ZodOptional<z.ZodEnum<{
69
+ test: "test";
70
+ it: "it";
71
+ }>>;
72
+ }, z.core.$strip>;
73
+ type ConsistentTestFunctionOptions = z.infer<typeof consistentTestFunctionOptionsSchema>;
67
74
 
68
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
69
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
70
- interface ConsistentTestFunctionOptions {
71
- preference?: "it" | "test";
72
- }
73
-
74
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
75
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
76
- interface NoNamespaceImportsOptions {
77
- allow?: string[];
78
- }
75
+ declare const noNamespaceImportsOptionsSchema: z.ZodObject<{
76
+ allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ }, z.core.$strip>;
78
+ type NoNamespaceImportsOptions = z.infer<typeof noNamespaceImportsOptionsSchema>;
79
79
 
80
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
81
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
82
- interface NoRelativeImportsOptions {
83
- depth?: number;
84
- }
80
+ declare const noRelativeImportsOptionsSchema: z.ZodObject<{
81
+ depth: z.ZodOptional<z.ZodInt>;
82
+ }, z.core.$strip>;
83
+ type NoRelativeImportsOptions = z.infer<typeof noRelativeImportsOptionsSchema>;
85
84
 
86
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
87
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
88
- interface StandardiseErrorMessagesOptions {
89
- regex?: string;
90
- }
85
+ declare const standardiseErrorMessagesOptionsSchema: z.ZodObject<{
86
+ regex: z.ZodOptional<z.ZodString>;
87
+ }, z.core.$strip>;
88
+ type StandardiseErrorMessagesOptions = z.infer<typeof standardiseErrorMessagesOptionsSchema>;
91
89
 
92
- /** Generated from src/utility/generateRuleOptionsTypes.ts.
93
- * You may execute the above file to re-generate this type using `npm run generate-rule-options-types` */
94
- interface UseNormalizedImportsOptions {
95
- fixable?: boolean;
96
- }
90
+ declare const useNormalizedImportsOptionsSchema: z.ZodObject<{
91
+ fixable: z.ZodOptional<z.ZodBoolean>;
92
+ }, z.core.$strip>;
93
+ type UseNormalizedImportsOptions = z.infer<typeof useNormalizedImportsOptionsSchema>;
97
94
 
98
95
  export { type AlexPlugin, type AlexPluginConfigGroup, type CombinedConfig, type ConfigGroupName, type ConfigKey, type ConsistentTestFunctionOptions, type GeneralConfig, type NoNamespaceImportsOptions, type NoRelativeImportsOptions, type PersonalConfig, type PluginConfig, type StandardiseErrorMessagesOptions, type TestFunction, type UseNormalizedImportsOptions, alexPlugin as default, parseTestFunction, prettierRules, sortObjects };
package/dist/index.js CHANGED
@@ -3743,7 +3743,7 @@ var require_src = __commonJS({
3743
3743
 
3744
3744
  // package.json
3745
3745
  var name = "@alextheman/eslint-plugin";
3746
- var version = "2.8.2";
3746
+ var version = "2.9.0";
3747
3747
 
3748
3748
  // src/configs/index.ts
3749
3749
  import packageJson from "eslint-plugin-package-json";
@@ -4448,7 +4448,7 @@ var configs_default = createAlexPluginConfigs;
4448
4448
 
4449
4449
  // src/rules/consistent-test-function.ts
4450
4450
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
4451
- import z from "zod";
4451
+ import z2 from "zod";
4452
4452
 
4453
4453
  // src/createRule.ts
4454
4454
  import { ESLintUtils } from "@typescript-eslint/utils";
@@ -4457,6 +4457,14 @@ var createRule = ESLintUtils.RuleCreator((ruleName) => {
4457
4457
  });
4458
4458
  var createRule_default = createRule;
4459
4459
 
4460
+ // src/utility/createRuleSchema.ts
4461
+ import { omitProperties } from "@alextheman/utility";
4462
+ import z from "zod";
4463
+ function createRuleSchema(schema6) {
4464
+ return [omitProperties(z.toJSONSchema(schema6), "$schema")];
4465
+ }
4466
+ var createRuleSchema_default = createRuleSchema;
4467
+
4460
4468
  // src/utility/getImportSpecifiersAfterRemoving.ts
4461
4469
  function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
4462
4470
  return specifiers.filter((specifier) => {
@@ -4468,10 +4476,17 @@ function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
4468
4476
  var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
4469
4477
 
4470
4478
  // src/rules/consistent-test-function.ts
4471
- var validTestFunctionsSchema = z.enum(["test", "it"]);
4479
+ var validTestFunctionsSchema = z2.enum(["test", "it"]);
4472
4480
  function parseTestFunction(data) {
4473
4481
  return validTestFunctionsSchema.parse(data);
4474
4482
  }
4483
+ var consistentTestFunctionOptionsSchema = z2.object({
4484
+ preference: validTestFunctionsSchema
4485
+ }).partial();
4486
+ function parseConsistentTestFunctionOptions(data) {
4487
+ return consistentTestFunctionOptionsSchema.parse(data);
4488
+ }
4489
+ var schema = createRuleSchema_default(consistentTestFunctionOptionsSchema);
4475
4490
  var consistentTestFunction = createRule_default({
4476
4491
  name: "consistent-test-function",
4477
4492
  meta: {
@@ -4483,46 +4498,36 @@ var consistentTestFunction = createRule_default({
4483
4498
  },
4484
4499
  type: "suggestion",
4485
4500
  fixable: "code",
4486
- schema: [
4487
- {
4488
- type: "object",
4489
- properties: {
4490
- preference: {
4491
- type: "string",
4492
- enum: ["it", "test"]
4493
- }
4494
- },
4495
- additionalProperties: false
4496
- }
4497
- ]
4501
+ schema
4498
4502
  },
4499
4503
  defaultOptions: [{ preference: "test" }],
4500
4504
  create(context) {
4501
4505
  var _a;
4502
- const preference = (_a = context.options[0]) == null ? void 0 : _a.preference;
4503
- const validatedPreference = parseTestFunction(preference != null ? preference : "test");
4506
+ const { preference } = parseConsistentTestFunctionOptions(
4507
+ (_a = context.options[0]) != null ? _a : { preference: "test" }
4508
+ );
4504
4509
  return {
4505
4510
  CallExpression(node) {
4506
- if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "it" && validatedPreference === "test") {
4511
+ if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "it" && preference === "test") {
4507
4512
  return context.report({
4508
4513
  node,
4509
4514
  messageId: "message",
4510
4515
  data: {
4511
4516
  source: node.callee.name,
4512
- preference: validatedPreference
4517
+ preference
4513
4518
  },
4514
4519
  fix(fixer) {
4515
4520
  return fixer.replaceText(node.callee, "test");
4516
4521
  }
4517
4522
  });
4518
4523
  }
4519
- if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "test" && validatedPreference === "it") {
4524
+ if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "test" && preference === "it") {
4520
4525
  return context.report({
4521
4526
  node,
4522
4527
  messageId: "message",
4523
4528
  data: {
4524
4529
  source: node.callee.name,
4525
- preference: validatedPreference
4530
+ preference
4526
4531
  },
4527
4532
  fix(fixer) {
4528
4533
  return fixer.replaceText(node.callee, "it");
@@ -4532,13 +4537,13 @@ var consistentTestFunction = createRule_default({
4532
4537
  },
4533
4538
  ImportDeclaration(node) {
4534
4539
  for (const specifier of node.specifiers) {
4535
- if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && validatedPreference === "test") {
4540
+ if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && preference === "test") {
4536
4541
  return context.report({
4537
4542
  node,
4538
4543
  messageId: "message",
4539
4544
  data: {
4540
4545
  source: specifier.imported.name,
4541
- preference: validatedPreference
4546
+ preference
4542
4547
  },
4543
4548
  fix(fixer) {
4544
4549
  const importedNames = node.specifiers.map((specifier2) => {
@@ -4560,18 +4565,18 @@ var consistentTestFunction = createRule_default({
4560
4565
  }
4561
4566
  return fixer.replaceTextRange(
4562
4567
  [specifier.imported.range[0], specifier.imported.range[1]],
4563
- validatedPreference
4568
+ preference
4564
4569
  );
4565
4570
  }
4566
4571
  });
4567
4572
  }
4568
- if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && validatedPreference === "it") {
4573
+ if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && preference === "it") {
4569
4574
  return context.report({
4570
4575
  node,
4571
4576
  messageId: "message",
4572
4577
  data: {
4573
4578
  source: specifier.imported.name,
4574
- preference: validatedPreference
4579
+ preference
4575
4580
  },
4576
4581
  fix(fixer) {
4577
4582
  const importedNames = node.specifiers.map((specifier2) => {
@@ -4593,7 +4598,7 @@ var consistentTestFunction = createRule_default({
4593
4598
  }
4594
4599
  return fixer.replaceTextRange(
4595
4600
  [specifier.imported.range[0], specifier.imported.range[1]],
4596
- validatedPreference
4601
+ preference
4597
4602
  );
4598
4603
  }
4599
4604
  });
@@ -4645,6 +4650,14 @@ var noIsolatedTests = createRule_default({
4645
4650
  var no_isolated_tests_default = noIsolatedTests;
4646
4651
 
4647
4652
  // src/rules/no-namespace-imports.ts
4653
+ import z3 from "zod";
4654
+ var noNamespaceImportsOptionsSchema = z3.object({
4655
+ allow: z3.array(z3.string())
4656
+ }).partial();
4657
+ function parseNoNamespaceImportsOptions(data) {
4658
+ return noNamespaceImportsOptionsSchema.parse(data);
4659
+ }
4660
+ var schema2 = createRuleSchema_default(noNamespaceImportsOptionsSchema);
4648
4661
  var noNamespaceImports = createRule_default({
4649
4662
  name: "no-namespace-imports",
4650
4663
  meta: {
@@ -4655,31 +4668,17 @@ var noNamespaceImports = createRule_default({
4655
4668
  message: 'Import * from "{{source}}" is not allowed. Please use named imports instead.'
4656
4669
  },
4657
4670
  type: "suggestion",
4658
- schema: [
4659
- {
4660
- type: "object",
4661
- properties: {
4662
- allow: {
4663
- type: "array",
4664
- items: {
4665
- type: "string"
4666
- },
4667
- uniqueItems: true
4668
- }
4669
- },
4670
- additionalProperties: false
4671
- }
4672
- ]
4671
+ schema: schema2
4673
4672
  },
4674
4673
  defaultOptions: [{ allow: [""] }],
4675
4674
  create(context) {
4676
4675
  var _a;
4677
- const allowableNamedImports = (_a = context.options[0]) == null ? void 0 : _a.allow;
4676
+ const { allow } = parseNoNamespaceImportsOptions((_a = context.options[0]) != null ? _a : { allow: [] });
4678
4677
  return {
4679
4678
  ImportDeclaration(node) {
4680
4679
  const allSpecifiers = node.specifiers;
4681
4680
  for (const specifier of allSpecifiers) {
4682
- if (specifier.type === "ImportNamespaceSpecifier" && !(allowableNamedImports == null ? void 0 : allowableNamedImports.includes(node.source.value))) {
4681
+ if (specifier.type === "ImportNamespaceSpecifier" && !(allow == null ? void 0 : allow.includes(node.source.value))) {
4683
4682
  context.report({
4684
4683
  node,
4685
4684
  messageId: "message",
@@ -4732,6 +4731,14 @@ var noPluginConfigAccessFromSrcConfigs = createRule_default({
4732
4731
  var no_plugin_configs_access_from_src_configs_default = noPluginConfigAccessFromSrcConfigs;
4733
4732
 
4734
4733
  // src/rules/no-relative-imports.ts
4734
+ import z4 from "zod";
4735
+ var noRelativeImportsOptionsSchema = z4.object({
4736
+ depth: z4.int().nonnegative()
4737
+ }).partial();
4738
+ function parseNoRelativeImportsOptions(data) {
4739
+ return noRelativeImportsOptionsSchema.parse(data);
4740
+ }
4741
+ var schema3 = createRuleSchema_default(noRelativeImportsOptionsSchema);
4735
4742
  var noRelativeImports = createRule_default({
4736
4743
  name: "no-relative-imports",
4737
4744
  meta: {
@@ -4743,34 +4750,16 @@ var noRelativeImports = createRule_default({
4743
4750
  stupidPath: "For the love of God, please do not mix relative path parts in your import statements like that! How can you possibly be ok with {{source}}?!"
4744
4751
  },
4745
4752
  type: "suggestion",
4746
- schema: [
4747
- {
4748
- type: "object",
4749
- properties: {
4750
- depth: {
4751
- type: "number"
4752
- }
4753
- },
4754
- additionalProperties: false
4755
- }
4756
- ]
4753
+ schema: schema3
4757
4754
  },
4758
4755
  defaultOptions: [{ depth: void 0 }],
4759
4756
  create(context) {
4760
4757
  var _a;
4761
- const allowedDepth = (_a = context.options[0]) == null ? void 0 : _a.depth;
4762
- if (allowedDepth !== void 0) {
4763
- if (allowedDepth % 1 !== 0) {
4764
- throw new Error("NON_INTEGER_DEPTH_NOT_ALLOWED");
4765
- }
4766
- if (allowedDepth < 0) {
4767
- throw new Error("NEGATIVE_DEPTH_NOT_ALLOWED");
4768
- }
4769
- }
4758
+ const { depth } = parseNoRelativeImportsOptions((_a = context.options[0]) != null ? _a : { depth: void 0 });
4770
4759
  return {
4771
4760
  ImportDeclaration(node) {
4772
4761
  if (node.source.value.includes("./") || node.source.value.includes("../")) {
4773
- if (allowedDepth === void 0) {
4762
+ if (depth === void 0) {
4774
4763
  return context.report({
4775
4764
  node,
4776
4765
  messageId: "strictNoRelative",
@@ -4798,18 +4787,18 @@ var noRelativeImports = createRule_default({
4798
4787
  }
4799
4788
  });
4800
4789
  }
4801
- if (allowedDepth === 0 && importPathParts[0] === ".") {
4790
+ if (depth === 0 && importPathParts[0] === ".") {
4802
4791
  return;
4803
4792
  }
4804
4793
  let endOfRelativePathFound = false;
4805
- for (const part of importPathParts.slice(0, allowedDepth + 1)) {
4794
+ for (const part of importPathParts.slice(0, depth + 1)) {
4806
4795
  if (part !== "..") {
4807
4796
  endOfRelativePathFound = true;
4808
4797
  break;
4809
4798
  }
4810
4799
  }
4811
4800
  if (!endOfRelativePathFound) {
4812
- if (allowedDepth === 0) {
4801
+ if (depth === 0) {
4813
4802
  return context.report({
4814
4803
  node,
4815
4804
  messageId: "rootOnly",
@@ -4823,8 +4812,8 @@ var noRelativeImports = createRule_default({
4823
4812
  messageId: "exceededAllowedDepth",
4824
4813
  data: {
4825
4814
  source: node.source.value,
4826
- depth: allowedDepth,
4827
- s: allowedDepth !== 1 ? "s" : ""
4815
+ depth,
4816
+ s: depth !== 1 ? "s" : ""
4828
4817
  }
4829
4818
  });
4830
4819
  }
@@ -4869,9 +4858,20 @@ var no_skipped_tests_default = noSkippedTests;
4869
4858
 
4870
4859
  // src/rules/standardise-error-messages.ts
4871
4860
  import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
4861
+ import z5 from "zod";
4862
+ var standardiseErrorMessagesOptionsSchema = z5.object({
4863
+ regex: z5.string()
4864
+ }).partial();
4865
+ function parseStandardiseErrorMessagesOptions(data) {
4866
+ return standardiseErrorMessagesOptionsSchema.parse(data);
4867
+ }
4868
+ var schema4 = createRuleSchema_default(standardiseErrorMessagesOptionsSchema);
4869
+ var defaultErrorRegex = "^[A-Z]+(?:_[A-Z]+)*$";
4872
4870
  function checkCurrentNode(context, node) {
4873
- var _a, _b;
4874
- const errorRegex = (_b = (_a = context.options[0]) == null ? void 0 : _a.regex) != null ? _b : "^[A-Z]+(?:_[A-Z]+)*$";
4871
+ var _a;
4872
+ const { regex: errorRegex = defaultErrorRegex } = parseStandardiseErrorMessagesOptions(
4873
+ (_a = context.options[0]) != null ? _a : { regex: defaultErrorRegex }
4874
+ );
4875
4875
  if (node.callee.type === AST_NODE_TYPES3.Identifier && node.callee.name === "Error") {
4876
4876
  const [errorArgument] = node.arguments;
4877
4877
  const errorMessage = errorArgument.type === AST_NODE_TYPES3.Literal ? errorArgument.value : "";
@@ -4897,19 +4897,9 @@ var standardiseErrorMessages = createRule_default({
4897
4897
  message: "Expected error message {{error}} to match {{regex}}."
4898
4898
  },
4899
4899
  type: "suggestion",
4900
- schema: [
4901
- {
4902
- type: "object",
4903
- properties: {
4904
- regex: {
4905
- type: "string"
4906
- }
4907
- },
4908
- additionalProperties: false
4909
- }
4910
- ]
4900
+ schema: schema4
4911
4901
  },
4912
- defaultOptions: [{ regex: "^[A-Z]+(?:_[A-Z]+)*$" }],
4902
+ defaultOptions: [{ regex: defaultErrorRegex }],
4913
4903
  create(context) {
4914
4904
  return {
4915
4905
  CallExpression(node) {
@@ -4925,6 +4915,14 @@ var standardise_error_messages_default = standardiseErrorMessages;
4925
4915
 
4926
4916
  // src/rules/use-normalized-imports.ts
4927
4917
  import path from "path";
4918
+ import z6 from "zod";
4919
+ var useNormalizedImportsOptionsSchema = z6.object({
4920
+ fixable: z6.boolean()
4921
+ }).partial();
4922
+ function parseUseNormalizedImportsOptionsSchema(data) {
4923
+ return useNormalizedImportsOptionsSchema.parse(data);
4924
+ }
4925
+ var schema5 = createRuleSchema_default(useNormalizedImportsOptionsSchema);
4928
4926
  var useNormalizedImports = createRule_default({
4929
4927
  name: "use-normalized-imports",
4930
4928
  meta: {
@@ -4935,23 +4933,15 @@ var useNormalizedImports = createRule_default({
4935
4933
  pathNotNormalized: "Import path {{nonNormalized}} is not normalised. Please use {{normalized}} instead."
4936
4934
  },
4937
4935
  type: "suggestion",
4938
- schema: [
4939
- {
4940
- type: "object",
4941
- properties: {
4942
- fixable: {
4943
- type: "boolean"
4944
- }
4945
- },
4946
- additionalProperties: false
4947
- }
4948
- ],
4936
+ schema: schema5,
4949
4937
  fixable: "code"
4950
4938
  },
4951
4939
  defaultOptions: [{ fixable: true }],
4952
4940
  create(context) {
4953
- var _a, _b;
4954
- const isFixable = (_b = (_a = context.options[0]) == null ? void 0 : _a.fixable) != null ? _b : true;
4941
+ var _a;
4942
+ const { fixable: isFixable } = parseUseNormalizedImportsOptionsSchema(
4943
+ (_a = context.options[0]) != null ? _a : { fixable: true }
4944
+ );
4955
4945
  return {
4956
4946
  ImportDeclaration(node) {
4957
4947
  const normalizedPath = path.posix.normalize(node.source.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/eslint-plugin",
3
- "version": "2.8.2",
3
+ "version": "2.9.0",
4
4
  "description": "A package to provide custom ESLint rules and configs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,6 @@
25
25
  "format-prettier": "npm run format-prettier-typescript && npm run format-prettier-javascript",
26
26
  "format-prettier-javascript": "prettier --write \"./**/*.js\"",
27
27
  "format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
28
- "generate-rule-options-types": "tsx src/utility/generateRuleOptionsTypes.ts",
29
28
  "lint": "tsx src/utility/checkConfigChanges.ts || npm run build && npm run lint-tsc && npm run lint-eslint && npm run lint-prettier",
30
29
  "lint-eslint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" \"package.json\"",
31
30
  "lint-prettier": "npm run lint-prettier-typescript && npm run lint-prettier-javascript",
@@ -40,8 +39,6 @@
40
39
  "dependencies": {
41
40
  "@alextheman/utility": "^2.15.1",
42
41
  "common-tags": "^1.8.2",
43
- "eslint-plugin-package-json": "^0.64.0",
44
- "json-schema-to-typescript": "^15.0.4",
45
42
  "zod": "^4.1.12"
46
43
  },
47
44
  "devDependencies": {
@@ -70,6 +67,7 @@
70
67
  "eslint-import-resolver-typescript": "^4.4.4",
71
68
  "eslint-plugin-import": "^2.32.0",
72
69
  "eslint-plugin-jsx-a11y": "^6.10.2",
70
+ "eslint-plugin-package-json": "^0.74.0",
73
71
  "eslint-plugin-perfectionist": "^4.15.0",
74
72
  "eslint-plugin-prettier": "^5.5.3",
75
73
  "eslint-plugin-react": "^7.37.5",