@alextheman/eslint-plugin 1.11.1 → 1.12.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
@@ -3706,7 +3706,7 @@ module.exports = __toCommonJS(index_exports);
3706
3706
 
3707
3707
  // package.json
3708
3708
  var name = "@alextheman/eslint-plugin";
3709
- var version = "1.11.1";
3709
+ var version = "1.12.0";
3710
3710
 
3711
3711
  // src/configs/alexPluginBase.ts
3712
3712
  function createAlexPluginBaseConfig(plugin2) {
@@ -3725,7 +3725,8 @@ function createAlexPluginBaseConfig(plugin2) {
3725
3725
  files: ["**/*.test.ts"],
3726
3726
  rules: {
3727
3727
  "@alextheman/no-isolated-tests": "error",
3728
- "@alextheman/no-skipped-tests": "warn"
3728
+ "@alextheman/no-skipped-tests": "warn",
3729
+ "@alextheman/consistent-test-function": ["error", { preference: "test" }]
3729
3730
  }
3730
3731
  }
3731
3732
  ];
@@ -3899,6 +3900,10 @@ function createAlexTypeScriptReactBaseConfig(plugin2) {
3899
3900
  }
3900
3901
  var alexTypeScriptReactBase_default = createAlexTypeScriptReactBaseConfig;
3901
3902
 
3903
+ // src/rules/consistent-test-function.ts
3904
+ var import_utils2 = require("@typescript-eslint/utils");
3905
+ var import_zod = __toESM(require("zod"), 1);
3906
+
3902
3907
  // src/create-rule.ts
3903
3908
  var import_utils = require("@typescript-eslint/utils");
3904
3909
  var createRule = import_utils.ESLintUtils.RuleCreator((ruleName) => {
@@ -3906,10 +3911,154 @@ var createRule = import_utils.ESLintUtils.RuleCreator((ruleName) => {
3906
3911
  });
3907
3912
  var create_rule_default = createRule;
3908
3913
 
3914
+ // src/utility/getImportSpecifiersAfterRemoving.ts
3915
+ function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
3916
+ return specifiers.filter((specifier) => {
3917
+ return !(specifier.imported.name === importToRemove);
3918
+ }).map((specifier) => {
3919
+ return context.sourceCode.getText(specifier);
3920
+ }).join(", ");
3921
+ }
3922
+ var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
3923
+
3924
+ // src/rules/consistent-test-function.ts
3925
+ var validTestFunctionsSchema = import_zod.default.enum(["test", "it"]);
3926
+ var consistentTestFunction = create_rule_default({
3927
+ name: "consistent-test-function",
3928
+ meta: {
3929
+ docs: {
3930
+ description: "Enforce a consistent function (either `test` or `it`)"
3931
+ },
3932
+ messages: {
3933
+ message: "Unexpected {{source}}. Please use {{preference}} instead."
3934
+ },
3935
+ type: "suggestion",
3936
+ fixable: "code",
3937
+ schema: [
3938
+ {
3939
+ type: "object",
3940
+ properties: {
3941
+ preference: {
3942
+ type: "string"
3943
+ }
3944
+ },
3945
+ additionalProperties: false
3946
+ }
3947
+ ]
3948
+ },
3949
+ defaultOptions: [{ preference: "test" }],
3950
+ create(context) {
3951
+ var _a;
3952
+ const preference = (_a = context.options[0]) == null ? void 0 : _a.preference;
3953
+ const validatedPreference = validTestFunctionsSchema.parse(preference != null ? preference : "test");
3954
+ return {
3955
+ CallExpression(node) {
3956
+ if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "it" && validatedPreference === "test") {
3957
+ return context.report({
3958
+ node,
3959
+ messageId: "message",
3960
+ data: {
3961
+ source: node.callee.name,
3962
+ preference: validatedPreference
3963
+ },
3964
+ fix(fixer) {
3965
+ return fixer.replaceText(node.callee, "test");
3966
+ }
3967
+ });
3968
+ }
3969
+ if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "test" && validatedPreference === "it") {
3970
+ return context.report({
3971
+ node,
3972
+ messageId: "message",
3973
+ data: {
3974
+ source: node.callee.name,
3975
+ preference: validatedPreference
3976
+ },
3977
+ fix(fixer) {
3978
+ return fixer.replaceText(node.callee, "it");
3979
+ }
3980
+ });
3981
+ }
3982
+ },
3983
+ ImportDeclaration(node) {
3984
+ for (const specifier of node.specifiers) {
3985
+ if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && validatedPreference === "test") {
3986
+ return context.report({
3987
+ node,
3988
+ messageId: "message",
3989
+ data: {
3990
+ source: specifier.imported.name,
3991
+ preference: validatedPreference
3992
+ },
3993
+ fix(fixer) {
3994
+ const importedNames = node.specifiers.map((specifier2) => {
3995
+ return specifier2.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === import_utils2.AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
3996
+ });
3997
+ if (importedNames.includes("it") && importedNames.includes("test")) {
3998
+ const newSpecifiers = getImportSpecifiersAfterRemoving_default(
3999
+ context,
4000
+ node.specifiers,
4001
+ "it"
4002
+ );
4003
+ return fixer.replaceTextRange(
4004
+ [
4005
+ node.specifiers[0].range[0],
4006
+ node.specifiers[node.specifiers.length - 1].range[1]
4007
+ ],
4008
+ newSpecifiers
4009
+ );
4010
+ }
4011
+ return fixer.replaceTextRange(
4012
+ [specifier.imported.range[0], specifier.imported.range[1]],
4013
+ validatedPreference
4014
+ );
4015
+ }
4016
+ });
4017
+ }
4018
+ if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && validatedPreference === "it") {
4019
+ return context.report({
4020
+ node,
4021
+ messageId: "message",
4022
+ data: {
4023
+ source: specifier.imported.name,
4024
+ preference: validatedPreference
4025
+ },
4026
+ fix(fixer) {
4027
+ const importedNames = node.specifiers.map((specifier2) => {
4028
+ return specifier2.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === import_utils2.AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
4029
+ });
4030
+ if (importedNames.includes("it") && importedNames.includes("test")) {
4031
+ const newSpecifiers = getImportSpecifiersAfterRemoving_default(
4032
+ context,
4033
+ node.specifiers,
4034
+ "test"
4035
+ );
4036
+ return fixer.replaceTextRange(
4037
+ [
4038
+ node.specifiers[0].range[0],
4039
+ node.specifiers[node.specifiers.length - 1].range[1]
4040
+ ],
4041
+ newSpecifiers
4042
+ );
4043
+ }
4044
+ return fixer.replaceTextRange(
4045
+ [specifier.imported.range[0], specifier.imported.range[1]],
4046
+ validatedPreference
4047
+ );
4048
+ }
4049
+ });
4050
+ }
4051
+ }
4052
+ }
4053
+ };
4054
+ }
4055
+ });
4056
+ var consistent_test_function_default = consistentTestFunction;
4057
+
3909
4058
  // src/utility/checkCallExpression.ts
3910
- var import_utils2 = require("@typescript-eslint/utils");
4059
+ var import_utils3 = require("@typescript-eslint/utils");
3911
4060
  function checkCallExpression(node, objectName, propertyName) {
3912
- return node.callee.type === import_utils2.AST_NODE_TYPES.MemberExpression && node.callee.object.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.object.name === objectName && node.callee.property.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.property.name === propertyName;
4061
+ return node.callee.type === import_utils3.AST_NODE_TYPES.MemberExpression && node.callee.object.type === import_utils3.AST_NODE_TYPES.Identifier && node.callee.object.name === objectName && node.callee.property.type === import_utils3.AST_NODE_TYPES.Identifier && node.callee.property.name === propertyName;
3913
4062
  }
3914
4063
  var checkCallExpression_default = checkCallExpression;
3915
4064
 
@@ -4157,7 +4306,7 @@ var noSkippedTests = create_rule_default({
4157
4306
  var no_skipped_tests_default = noSkippedTests;
4158
4307
 
4159
4308
  // src/rules/use-object-shorthand.ts
4160
- var import_utils3 = require("@typescript-eslint/utils");
4309
+ var import_utils4 = require("@typescript-eslint/utils");
4161
4310
  var useObjectShorthand = create_rule_default({
4162
4311
  name: "use-object-shorthand",
4163
4312
  meta: {
@@ -4175,7 +4324,7 @@ var useObjectShorthand = create_rule_default({
4175
4324
  create(context) {
4176
4325
  return {
4177
4326
  Property(node) {
4178
- if (node.key.type === import_utils3.AST_NODE_TYPES.Identifier && node.value.type === import_utils3.AST_NODE_TYPES.Identifier && node.key.name === node.value.name && !node.shorthand) {
4327
+ if (node.key.type === import_utils4.AST_NODE_TYPES.Identifier && node.value.type === import_utils4.AST_NODE_TYPES.Identifier && node.key.name === node.value.name && !node.shorthand) {
4179
4328
  context.report({
4180
4329
  node,
4181
4330
  messageId: "useShorthand",
@@ -4196,6 +4345,7 @@ var use_object_shorthand_default = useObjectShorthand;
4196
4345
 
4197
4346
  // src/rules/index.ts
4198
4347
  var rules_default = {
4348
+ "consistent-test-function": consistent_test_function_default,
4199
4349
  "no-isolated-tests": no_isolated_tests_default,
4200
4350
  "no-namespace-imports": no_namespace_imports_default,
4201
4351
  "no-plugin-configs-access-from-src-configs": no_plugin_configs_access_from_src_configs_default,
package/dist/index.d.cts CHANGED
@@ -1,11 +1,18 @@
1
1
  import { Linter } from 'eslint';
2
2
  import { Config } from 'prettier';
3
+ import z from 'zod';
3
4
 
4
5
  var name = "@alextheman/eslint-plugin";
5
- var version = "1.11.1";
6
+ var version = "1.12.0";
6
7
 
7
8
  declare const prettierRules: Config;
8
9
 
10
+ declare const validTestFunctionsSchema: z.ZodEnum<{
11
+ test: "test";
12
+ it: "it";
13
+ }>;
14
+ type ValidTestFunctions = z.infer<typeof validTestFunctionsSchema>;
15
+
9
16
  interface AlexPlugin {
10
17
  meta: {
11
18
  name: typeof name;
@@ -24,4 +31,4 @@ interface AlexPlugin {
24
31
 
25
32
  declare const plugin: AlexPlugin;
26
33
 
27
- export { type AlexPlugin, plugin as default, prettierRules };
34
+ export { type AlexPlugin, type ValidTestFunctions, plugin as default, prettierRules };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,18 @@
1
1
  import { Linter } from 'eslint';
2
2
  import { Config } from 'prettier';
3
+ import z from 'zod';
3
4
 
4
5
  var name = "@alextheman/eslint-plugin";
5
- var version = "1.11.1";
6
+ var version = "1.12.0";
6
7
 
7
8
  declare const prettierRules: Config;
8
9
 
10
+ declare const validTestFunctionsSchema: z.ZodEnum<{
11
+ test: "test";
12
+ it: "it";
13
+ }>;
14
+ type ValidTestFunctions = z.infer<typeof validTestFunctionsSchema>;
15
+
9
16
  interface AlexPlugin {
10
17
  meta: {
11
18
  name: typeof name;
@@ -24,4 +31,4 @@ interface AlexPlugin {
24
31
 
25
32
  declare const plugin: AlexPlugin;
26
33
 
27
- export { type AlexPlugin, plugin as default, prettierRules };
34
+ export { type AlexPlugin, type ValidTestFunctions, plugin as default, prettierRules };
package/dist/index.js CHANGED
@@ -3692,7 +3692,7 @@ var require_globals2 = __commonJS({
3692
3692
 
3693
3693
  // package.json
3694
3694
  var name = "@alextheman/eslint-plugin";
3695
- var version = "1.11.1";
3695
+ var version = "1.12.0";
3696
3696
 
3697
3697
  // src/configs/alexPluginBase.ts
3698
3698
  function createAlexPluginBaseConfig(plugin2) {
@@ -3711,7 +3711,8 @@ function createAlexPluginBaseConfig(plugin2) {
3711
3711
  files: ["**/*.test.ts"],
3712
3712
  rules: {
3713
3713
  "@alextheman/no-isolated-tests": "error",
3714
- "@alextheman/no-skipped-tests": "warn"
3714
+ "@alextheman/no-skipped-tests": "warn",
3715
+ "@alextheman/consistent-test-function": ["error", { preference: "test" }]
3715
3716
  }
3716
3717
  }
3717
3718
  ];
@@ -3885,6 +3886,10 @@ function createAlexTypeScriptReactBaseConfig(plugin2) {
3885
3886
  }
3886
3887
  var alexTypeScriptReactBase_default = createAlexTypeScriptReactBaseConfig;
3887
3888
 
3889
+ // src/rules/consistent-test-function.ts
3890
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3891
+ import z from "zod";
3892
+
3888
3893
  // src/create-rule.ts
3889
3894
  import { ESLintUtils } from "@typescript-eslint/utils";
3890
3895
  var createRule = ESLintUtils.RuleCreator((ruleName) => {
@@ -3892,10 +3897,154 @@ var createRule = ESLintUtils.RuleCreator((ruleName) => {
3892
3897
  });
3893
3898
  var create_rule_default = createRule;
3894
3899
 
3900
+ // src/utility/getImportSpecifiersAfterRemoving.ts
3901
+ function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
3902
+ return specifiers.filter((specifier) => {
3903
+ return !(specifier.imported.name === importToRemove);
3904
+ }).map((specifier) => {
3905
+ return context.sourceCode.getText(specifier);
3906
+ }).join(", ");
3907
+ }
3908
+ var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
3909
+
3910
+ // src/rules/consistent-test-function.ts
3911
+ var validTestFunctionsSchema = z.enum(["test", "it"]);
3912
+ var consistentTestFunction = create_rule_default({
3913
+ name: "consistent-test-function",
3914
+ meta: {
3915
+ docs: {
3916
+ description: "Enforce a consistent function (either `test` or `it`)"
3917
+ },
3918
+ messages: {
3919
+ message: "Unexpected {{source}}. Please use {{preference}} instead."
3920
+ },
3921
+ type: "suggestion",
3922
+ fixable: "code",
3923
+ schema: [
3924
+ {
3925
+ type: "object",
3926
+ properties: {
3927
+ preference: {
3928
+ type: "string"
3929
+ }
3930
+ },
3931
+ additionalProperties: false
3932
+ }
3933
+ ]
3934
+ },
3935
+ defaultOptions: [{ preference: "test" }],
3936
+ create(context) {
3937
+ var _a;
3938
+ const preference = (_a = context.options[0]) == null ? void 0 : _a.preference;
3939
+ const validatedPreference = validTestFunctionsSchema.parse(preference != null ? preference : "test");
3940
+ return {
3941
+ CallExpression(node) {
3942
+ if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "it" && validatedPreference === "test") {
3943
+ return context.report({
3944
+ node,
3945
+ messageId: "message",
3946
+ data: {
3947
+ source: node.callee.name,
3948
+ preference: validatedPreference
3949
+ },
3950
+ fix(fixer) {
3951
+ return fixer.replaceText(node.callee, "test");
3952
+ }
3953
+ });
3954
+ }
3955
+ if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "test" && validatedPreference === "it") {
3956
+ return context.report({
3957
+ node,
3958
+ messageId: "message",
3959
+ data: {
3960
+ source: node.callee.name,
3961
+ preference: validatedPreference
3962
+ },
3963
+ fix(fixer) {
3964
+ return fixer.replaceText(node.callee, "it");
3965
+ }
3966
+ });
3967
+ }
3968
+ },
3969
+ ImportDeclaration(node) {
3970
+ for (const specifier of node.specifiers) {
3971
+ if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && validatedPreference === "test") {
3972
+ return context.report({
3973
+ node,
3974
+ messageId: "message",
3975
+ data: {
3976
+ source: specifier.imported.name,
3977
+ preference: validatedPreference
3978
+ },
3979
+ fix(fixer) {
3980
+ const importedNames = node.specifiers.map((specifier2) => {
3981
+ return specifier2.type === AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
3982
+ });
3983
+ if (importedNames.includes("it") && importedNames.includes("test")) {
3984
+ const newSpecifiers = getImportSpecifiersAfterRemoving_default(
3985
+ context,
3986
+ node.specifiers,
3987
+ "it"
3988
+ );
3989
+ return fixer.replaceTextRange(
3990
+ [
3991
+ node.specifiers[0].range[0],
3992
+ node.specifiers[node.specifiers.length - 1].range[1]
3993
+ ],
3994
+ newSpecifiers
3995
+ );
3996
+ }
3997
+ return fixer.replaceTextRange(
3998
+ [specifier.imported.range[0], specifier.imported.range[1]],
3999
+ validatedPreference
4000
+ );
4001
+ }
4002
+ });
4003
+ }
4004
+ if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && validatedPreference === "it") {
4005
+ return context.report({
4006
+ node,
4007
+ messageId: "message",
4008
+ data: {
4009
+ source: specifier.imported.name,
4010
+ preference: validatedPreference
4011
+ },
4012
+ fix(fixer) {
4013
+ const importedNames = node.specifiers.map((specifier2) => {
4014
+ return specifier2.type === AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
4015
+ });
4016
+ if (importedNames.includes("it") && importedNames.includes("test")) {
4017
+ const newSpecifiers = getImportSpecifiersAfterRemoving_default(
4018
+ context,
4019
+ node.specifiers,
4020
+ "test"
4021
+ );
4022
+ return fixer.replaceTextRange(
4023
+ [
4024
+ node.specifiers[0].range[0],
4025
+ node.specifiers[node.specifiers.length - 1].range[1]
4026
+ ],
4027
+ newSpecifiers
4028
+ );
4029
+ }
4030
+ return fixer.replaceTextRange(
4031
+ [specifier.imported.range[0], specifier.imported.range[1]],
4032
+ validatedPreference
4033
+ );
4034
+ }
4035
+ });
4036
+ }
4037
+ }
4038
+ }
4039
+ };
4040
+ }
4041
+ });
4042
+ var consistent_test_function_default = consistentTestFunction;
4043
+
3895
4044
  // src/utility/checkCallExpression.ts
3896
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
4045
+ import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
3897
4046
  function checkCallExpression(node, objectName, propertyName) {
3898
- return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && node.callee.object.name === objectName && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === propertyName;
4047
+ return node.callee.type === AST_NODE_TYPES2.MemberExpression && node.callee.object.type === AST_NODE_TYPES2.Identifier && node.callee.object.name === objectName && node.callee.property.type === AST_NODE_TYPES2.Identifier && node.callee.property.name === propertyName;
3899
4048
  }
3900
4049
  var checkCallExpression_default = checkCallExpression;
3901
4050
 
@@ -4143,7 +4292,7 @@ var noSkippedTests = create_rule_default({
4143
4292
  var no_skipped_tests_default = noSkippedTests;
4144
4293
 
4145
4294
  // src/rules/use-object-shorthand.ts
4146
- import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
4295
+ import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
4147
4296
  var useObjectShorthand = create_rule_default({
4148
4297
  name: "use-object-shorthand",
4149
4298
  meta: {
@@ -4161,7 +4310,7 @@ var useObjectShorthand = create_rule_default({
4161
4310
  create(context) {
4162
4311
  return {
4163
4312
  Property(node) {
4164
- if (node.key.type === AST_NODE_TYPES2.Identifier && node.value.type === AST_NODE_TYPES2.Identifier && node.key.name === node.value.name && !node.shorthand) {
4313
+ if (node.key.type === AST_NODE_TYPES3.Identifier && node.value.type === AST_NODE_TYPES3.Identifier && node.key.name === node.value.name && !node.shorthand) {
4165
4314
  context.report({
4166
4315
  node,
4167
4316
  messageId: "useShorthand",
@@ -4182,6 +4331,7 @@ var use_object_shorthand_default = useObjectShorthand;
4182
4331
 
4183
4332
  // src/rules/index.ts
4184
4333
  var rules_default = {
4334
+ "consistent-test-function": consistent_test_function_default,
4185
4335
  "no-isolated-tests": no_isolated_tests_default,
4186
4336
  "no-namespace-imports": no_namespace_imports_default,
4187
4337
  "no-plugin-configs-access-from-src-configs": no_plugin_configs_access_from_src_configs_default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/eslint-plugin",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,6 +53,7 @@
53
53
  "vitest": "^3.2.4"
54
54
  },
55
55
  "dependencies": {
56
- "common-tags": "^1.8.2"
56
+ "common-tags": "^1.8.2",
57
+ "zod": "^4.1.5"
57
58
  }
58
59
  }