@alextheman/eslint-plugin 2.8.1 → 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 +99 -119
- package/dist/index.d.cts +24 -42
- package/dist/index.d.ts +24 -42
- package/dist/index.js +99 -119
- package/package.json +2 -4
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.
|
|
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);
|
|
@@ -3867,6 +3867,14 @@ var javaScriptLanguageOptions = {
|
|
|
3867
3867
|
};
|
|
3868
3868
|
var javaScriptLanguageOptions_default = javaScriptLanguageOptions;
|
|
3869
3869
|
|
|
3870
|
+
// src/configs/miscellaneous/unusedVarsIgnorePatterns.ts
|
|
3871
|
+
var unusedVarsIgnorePatterns = {
|
|
3872
|
+
argsIgnorePattern: "^_",
|
|
3873
|
+
caughtErrorsIgnorePattern: "^_",
|
|
3874
|
+
varsIgnorePattern: "^_"
|
|
3875
|
+
};
|
|
3876
|
+
var unusedVarsIgnorePatterns_default = unusedVarsIgnorePatterns;
|
|
3877
|
+
|
|
3870
3878
|
// src/configs/general/javaScriptBase.ts
|
|
3871
3879
|
var javaScriptBase = [
|
|
3872
3880
|
import_js.default.configs.recommended,
|
|
@@ -3900,14 +3908,7 @@ var javaScriptBase = [
|
|
|
3900
3908
|
}
|
|
3901
3909
|
],
|
|
3902
3910
|
"no-undef": "error",
|
|
3903
|
-
"no-unused-vars": [
|
|
3904
|
-
"error",
|
|
3905
|
-
{
|
|
3906
|
-
argsIgnorePattern: "^_",
|
|
3907
|
-
caughtErrorsIgnorePattern: "^_",
|
|
3908
|
-
varsIgnorePattern: "^_"
|
|
3909
|
-
}
|
|
3910
|
-
],
|
|
3911
|
+
"no-unused-vars": ["error", unusedVarsIgnorePatterns_default],
|
|
3911
3912
|
"no-useless-rename": "error",
|
|
3912
3913
|
"no-useless-return": "error",
|
|
3913
3914
|
"prefer-const": "error"
|
|
@@ -4138,26 +4139,15 @@ var typeScriptBase = [
|
|
|
4138
4139
|
"@typescript-eslint/explicit-member-accessibility": "error",
|
|
4139
4140
|
"@typescript-eslint/no-deprecated": "warn",
|
|
4140
4141
|
"@typescript-eslint/no-redeclare": ["error", { ignoreDeclarationMerge: true }],
|
|
4141
|
-
"@typescript-eslint/no-unused-vars": [
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
argsIgnorePattern: "^_",
|
|
4145
|
-
caughtErrorsIgnorePattern: "^_",
|
|
4146
|
-
varsIgnorePattern: "^_"
|
|
4147
|
-
}
|
|
4148
|
-
],
|
|
4142
|
+
"@typescript-eslint/no-unused-vars": ["error", unusedVarsIgnorePatterns_default],
|
|
4143
|
+
// Disable import/no-unresolved (enabled in general/javascript, being extended here) because the TypeScript compiler already catches unused imports for us.
|
|
4144
|
+
"import/no-unresolved": "off",
|
|
4149
4145
|
// Disable regular no-redeclare in favour of TypeScript-specific version since that will flag type redeclarations when we do const MyType = {}; export type MyType = ...
|
|
4150
4146
|
"no-redeclare": "off",
|
|
4151
4147
|
// Disable no-undef because undefined variables tend to be better caught by the TypeScript compiler.
|
|
4152
4148
|
"no-undef": "off",
|
|
4153
4149
|
// Disable regular no-unused-vars rule since that will flag interface declarations. Only use the TypeScript specific rule for this.
|
|
4154
4150
|
"no-unused-vars": "off"
|
|
4155
|
-
},
|
|
4156
|
-
settings: {
|
|
4157
|
-
"import/resolver": {
|
|
4158
|
-
node: true,
|
|
4159
|
-
typescript: true
|
|
4160
|
-
}
|
|
4161
4151
|
}
|
|
4162
4152
|
}
|
|
4163
4153
|
];
|
|
@@ -4474,7 +4464,7 @@ var configs_default = createAlexPluginConfigs;
|
|
|
4474
4464
|
|
|
4475
4465
|
// src/rules/consistent-test-function.ts
|
|
4476
4466
|
var import_utils2 = require("@typescript-eslint/utils");
|
|
4477
|
-
var
|
|
4467
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
4478
4468
|
|
|
4479
4469
|
// src/createRule.ts
|
|
4480
4470
|
var import_utils = require("@typescript-eslint/utils");
|
|
@@ -4483,6 +4473,14 @@ var createRule = import_utils.ESLintUtils.RuleCreator((ruleName) => {
|
|
|
4483
4473
|
});
|
|
4484
4474
|
var createRule_default = createRule;
|
|
4485
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
|
+
|
|
4486
4484
|
// src/utility/getImportSpecifiersAfterRemoving.ts
|
|
4487
4485
|
function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
|
|
4488
4486
|
return specifiers.filter((specifier) => {
|
|
@@ -4494,10 +4492,17 @@ function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
|
|
|
4494
4492
|
var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
|
|
4495
4493
|
|
|
4496
4494
|
// src/rules/consistent-test-function.ts
|
|
4497
|
-
var validTestFunctionsSchema =
|
|
4495
|
+
var validTestFunctionsSchema = import_zod2.default.enum(["test", "it"]);
|
|
4498
4496
|
function parseTestFunction(data) {
|
|
4499
4497
|
return validTestFunctionsSchema.parse(data);
|
|
4500
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);
|
|
4501
4506
|
var consistentTestFunction = createRule_default({
|
|
4502
4507
|
name: "consistent-test-function",
|
|
4503
4508
|
meta: {
|
|
@@ -4509,46 +4514,36 @@ var consistentTestFunction = createRule_default({
|
|
|
4509
4514
|
},
|
|
4510
4515
|
type: "suggestion",
|
|
4511
4516
|
fixable: "code",
|
|
4512
|
-
schema
|
|
4513
|
-
{
|
|
4514
|
-
type: "object",
|
|
4515
|
-
properties: {
|
|
4516
|
-
preference: {
|
|
4517
|
-
type: "string",
|
|
4518
|
-
enum: ["it", "test"]
|
|
4519
|
-
}
|
|
4520
|
-
},
|
|
4521
|
-
additionalProperties: false
|
|
4522
|
-
}
|
|
4523
|
-
]
|
|
4517
|
+
schema
|
|
4524
4518
|
},
|
|
4525
4519
|
defaultOptions: [{ preference: "test" }],
|
|
4526
4520
|
create(context) {
|
|
4527
4521
|
var _a;
|
|
4528
|
-
const preference = (
|
|
4529
|
-
|
|
4522
|
+
const { preference } = parseConsistentTestFunctionOptions(
|
|
4523
|
+
(_a = context.options[0]) != null ? _a : { preference: "test" }
|
|
4524
|
+
);
|
|
4530
4525
|
return {
|
|
4531
4526
|
CallExpression(node) {
|
|
4532
|
-
if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "it" &&
|
|
4527
|
+
if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "it" && preference === "test") {
|
|
4533
4528
|
return context.report({
|
|
4534
4529
|
node,
|
|
4535
4530
|
messageId: "message",
|
|
4536
4531
|
data: {
|
|
4537
4532
|
source: node.callee.name,
|
|
4538
|
-
preference
|
|
4533
|
+
preference
|
|
4539
4534
|
},
|
|
4540
4535
|
fix(fixer) {
|
|
4541
4536
|
return fixer.replaceText(node.callee, "test");
|
|
4542
4537
|
}
|
|
4543
4538
|
});
|
|
4544
4539
|
}
|
|
4545
|
-
if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "test" &&
|
|
4540
|
+
if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "test" && preference === "it") {
|
|
4546
4541
|
return context.report({
|
|
4547
4542
|
node,
|
|
4548
4543
|
messageId: "message",
|
|
4549
4544
|
data: {
|
|
4550
4545
|
source: node.callee.name,
|
|
4551
|
-
preference
|
|
4546
|
+
preference
|
|
4552
4547
|
},
|
|
4553
4548
|
fix(fixer) {
|
|
4554
4549
|
return fixer.replaceText(node.callee, "it");
|
|
@@ -4558,13 +4553,13 @@ var consistentTestFunction = createRule_default({
|
|
|
4558
4553
|
},
|
|
4559
4554
|
ImportDeclaration(node) {
|
|
4560
4555
|
for (const specifier of node.specifiers) {
|
|
4561
|
-
if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "it" &&
|
|
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") {
|
|
4562
4557
|
return context.report({
|
|
4563
4558
|
node,
|
|
4564
4559
|
messageId: "message",
|
|
4565
4560
|
data: {
|
|
4566
4561
|
source: specifier.imported.name,
|
|
4567
|
-
preference
|
|
4562
|
+
preference
|
|
4568
4563
|
},
|
|
4569
4564
|
fix(fixer) {
|
|
4570
4565
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
@@ -4586,18 +4581,18 @@ var consistentTestFunction = createRule_default({
|
|
|
4586
4581
|
}
|
|
4587
4582
|
return fixer.replaceTextRange(
|
|
4588
4583
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4589
|
-
|
|
4584
|
+
preference
|
|
4590
4585
|
);
|
|
4591
4586
|
}
|
|
4592
4587
|
});
|
|
4593
4588
|
}
|
|
4594
|
-
if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "test" &&
|
|
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") {
|
|
4595
4590
|
return context.report({
|
|
4596
4591
|
node,
|
|
4597
4592
|
messageId: "message",
|
|
4598
4593
|
data: {
|
|
4599
4594
|
source: specifier.imported.name,
|
|
4600
|
-
preference
|
|
4595
|
+
preference
|
|
4601
4596
|
},
|
|
4602
4597
|
fix(fixer) {
|
|
4603
4598
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
@@ -4619,7 +4614,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4619
4614
|
}
|
|
4620
4615
|
return fixer.replaceTextRange(
|
|
4621
4616
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4622
|
-
|
|
4617
|
+
preference
|
|
4623
4618
|
);
|
|
4624
4619
|
}
|
|
4625
4620
|
});
|
|
@@ -4671,6 +4666,14 @@ var noIsolatedTests = createRule_default({
|
|
|
4671
4666
|
var no_isolated_tests_default = noIsolatedTests;
|
|
4672
4667
|
|
|
4673
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);
|
|
4674
4677
|
var noNamespaceImports = createRule_default({
|
|
4675
4678
|
name: "no-namespace-imports",
|
|
4676
4679
|
meta: {
|
|
@@ -4681,31 +4684,17 @@ var noNamespaceImports = createRule_default({
|
|
|
4681
4684
|
message: 'Import * from "{{source}}" is not allowed. Please use named imports instead.'
|
|
4682
4685
|
},
|
|
4683
4686
|
type: "suggestion",
|
|
4684
|
-
schema:
|
|
4685
|
-
{
|
|
4686
|
-
type: "object",
|
|
4687
|
-
properties: {
|
|
4688
|
-
allow: {
|
|
4689
|
-
type: "array",
|
|
4690
|
-
items: {
|
|
4691
|
-
type: "string"
|
|
4692
|
-
},
|
|
4693
|
-
uniqueItems: true
|
|
4694
|
-
}
|
|
4695
|
-
},
|
|
4696
|
-
additionalProperties: false
|
|
4697
|
-
}
|
|
4698
|
-
]
|
|
4687
|
+
schema: schema2
|
|
4699
4688
|
},
|
|
4700
4689
|
defaultOptions: [{ allow: [""] }],
|
|
4701
4690
|
create(context) {
|
|
4702
4691
|
var _a;
|
|
4703
|
-
const
|
|
4692
|
+
const { allow } = parseNoNamespaceImportsOptions((_a = context.options[0]) != null ? _a : { allow: [] });
|
|
4704
4693
|
return {
|
|
4705
4694
|
ImportDeclaration(node) {
|
|
4706
4695
|
const allSpecifiers = node.specifiers;
|
|
4707
4696
|
for (const specifier of allSpecifiers) {
|
|
4708
|
-
if (specifier.type === "ImportNamespaceSpecifier" && !(
|
|
4697
|
+
if (specifier.type === "ImportNamespaceSpecifier" && !(allow == null ? void 0 : allow.includes(node.source.value))) {
|
|
4709
4698
|
context.report({
|
|
4710
4699
|
node,
|
|
4711
4700
|
messageId: "message",
|
|
@@ -4758,6 +4747,14 @@ var noPluginConfigAccessFromSrcConfigs = createRule_default({
|
|
|
4758
4747
|
var no_plugin_configs_access_from_src_configs_default = noPluginConfigAccessFromSrcConfigs;
|
|
4759
4748
|
|
|
4760
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);
|
|
4761
4758
|
var noRelativeImports = createRule_default({
|
|
4762
4759
|
name: "no-relative-imports",
|
|
4763
4760
|
meta: {
|
|
@@ -4769,34 +4766,16 @@ var noRelativeImports = createRule_default({
|
|
|
4769
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}}?!"
|
|
4770
4767
|
},
|
|
4771
4768
|
type: "suggestion",
|
|
4772
|
-
schema:
|
|
4773
|
-
{
|
|
4774
|
-
type: "object",
|
|
4775
|
-
properties: {
|
|
4776
|
-
depth: {
|
|
4777
|
-
type: "number"
|
|
4778
|
-
}
|
|
4779
|
-
},
|
|
4780
|
-
additionalProperties: false
|
|
4781
|
-
}
|
|
4782
|
-
]
|
|
4769
|
+
schema: schema3
|
|
4783
4770
|
},
|
|
4784
4771
|
defaultOptions: [{ depth: void 0 }],
|
|
4785
4772
|
create(context) {
|
|
4786
4773
|
var _a;
|
|
4787
|
-
const
|
|
4788
|
-
if (allowedDepth !== void 0) {
|
|
4789
|
-
if (allowedDepth % 1 !== 0) {
|
|
4790
|
-
throw new Error("NON_INTEGER_DEPTH_NOT_ALLOWED");
|
|
4791
|
-
}
|
|
4792
|
-
if (allowedDepth < 0) {
|
|
4793
|
-
throw new Error("NEGATIVE_DEPTH_NOT_ALLOWED");
|
|
4794
|
-
}
|
|
4795
|
-
}
|
|
4774
|
+
const { depth } = parseNoRelativeImportsOptions((_a = context.options[0]) != null ? _a : { depth: void 0 });
|
|
4796
4775
|
return {
|
|
4797
4776
|
ImportDeclaration(node) {
|
|
4798
4777
|
if (node.source.value.includes("./") || node.source.value.includes("../")) {
|
|
4799
|
-
if (
|
|
4778
|
+
if (depth === void 0) {
|
|
4800
4779
|
return context.report({
|
|
4801
4780
|
node,
|
|
4802
4781
|
messageId: "strictNoRelative",
|
|
@@ -4824,18 +4803,18 @@ var noRelativeImports = createRule_default({
|
|
|
4824
4803
|
}
|
|
4825
4804
|
});
|
|
4826
4805
|
}
|
|
4827
|
-
if (
|
|
4806
|
+
if (depth === 0 && importPathParts[0] === ".") {
|
|
4828
4807
|
return;
|
|
4829
4808
|
}
|
|
4830
4809
|
let endOfRelativePathFound = false;
|
|
4831
|
-
for (const part of importPathParts.slice(0,
|
|
4810
|
+
for (const part of importPathParts.slice(0, depth + 1)) {
|
|
4832
4811
|
if (part !== "..") {
|
|
4833
4812
|
endOfRelativePathFound = true;
|
|
4834
4813
|
break;
|
|
4835
4814
|
}
|
|
4836
4815
|
}
|
|
4837
4816
|
if (!endOfRelativePathFound) {
|
|
4838
|
-
if (
|
|
4817
|
+
if (depth === 0) {
|
|
4839
4818
|
return context.report({
|
|
4840
4819
|
node,
|
|
4841
4820
|
messageId: "rootOnly",
|
|
@@ -4849,8 +4828,8 @@ var noRelativeImports = createRule_default({
|
|
|
4849
4828
|
messageId: "exceededAllowedDepth",
|
|
4850
4829
|
data: {
|
|
4851
4830
|
source: node.source.value,
|
|
4852
|
-
depth
|
|
4853
|
-
s:
|
|
4831
|
+
depth,
|
|
4832
|
+
s: depth !== 1 ? "s" : ""
|
|
4854
4833
|
}
|
|
4855
4834
|
});
|
|
4856
4835
|
}
|
|
@@ -4895,9 +4874,20 @@ var no_skipped_tests_default = noSkippedTests;
|
|
|
4895
4874
|
|
|
4896
4875
|
// src/rules/standardise-error-messages.ts
|
|
4897
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]+)*$";
|
|
4898
4886
|
function checkCurrentNode(context, node) {
|
|
4899
|
-
var _a
|
|
4900
|
-
const errorRegex =
|
|
4887
|
+
var _a;
|
|
4888
|
+
const { regex: errorRegex = defaultErrorRegex } = parseStandardiseErrorMessagesOptions(
|
|
4889
|
+
(_a = context.options[0]) != null ? _a : { regex: defaultErrorRegex }
|
|
4890
|
+
);
|
|
4901
4891
|
if (node.callee.type === import_utils4.AST_NODE_TYPES.Identifier && node.callee.name === "Error") {
|
|
4902
4892
|
const [errorArgument] = node.arguments;
|
|
4903
4893
|
const errorMessage = errorArgument.type === import_utils4.AST_NODE_TYPES.Literal ? errorArgument.value : "";
|
|
@@ -4923,19 +4913,9 @@ var standardiseErrorMessages = createRule_default({
|
|
|
4923
4913
|
message: "Expected error message {{error}} to match {{regex}}."
|
|
4924
4914
|
},
|
|
4925
4915
|
type: "suggestion",
|
|
4926
|
-
schema:
|
|
4927
|
-
{
|
|
4928
|
-
type: "object",
|
|
4929
|
-
properties: {
|
|
4930
|
-
regex: {
|
|
4931
|
-
type: "string"
|
|
4932
|
-
}
|
|
4933
|
-
},
|
|
4934
|
-
additionalProperties: false
|
|
4935
|
-
}
|
|
4936
|
-
]
|
|
4916
|
+
schema: schema4
|
|
4937
4917
|
},
|
|
4938
|
-
defaultOptions: [{ regex:
|
|
4918
|
+
defaultOptions: [{ regex: defaultErrorRegex }],
|
|
4939
4919
|
create(context) {
|
|
4940
4920
|
return {
|
|
4941
4921
|
CallExpression(node) {
|
|
@@ -4951,6 +4931,14 @@ var standardise_error_messages_default = standardiseErrorMessages;
|
|
|
4951
4931
|
|
|
4952
4932
|
// src/rules/use-normalized-imports.ts
|
|
4953
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);
|
|
4954
4942
|
var useNormalizedImports = createRule_default({
|
|
4955
4943
|
name: "use-normalized-imports",
|
|
4956
4944
|
meta: {
|
|
@@ -4961,23 +4949,15 @@ var useNormalizedImports = createRule_default({
|
|
|
4961
4949
|
pathNotNormalized: "Import path {{nonNormalized}} is not normalised. Please use {{normalized}} instead."
|
|
4962
4950
|
},
|
|
4963
4951
|
type: "suggestion",
|
|
4964
|
-
schema:
|
|
4965
|
-
{
|
|
4966
|
-
type: "object",
|
|
4967
|
-
properties: {
|
|
4968
|
-
fixable: {
|
|
4969
|
-
type: "boolean"
|
|
4970
|
-
}
|
|
4971
|
-
},
|
|
4972
|
-
additionalProperties: false
|
|
4973
|
-
}
|
|
4974
|
-
],
|
|
4952
|
+
schema: schema5,
|
|
4975
4953
|
fixable: "code"
|
|
4976
4954
|
},
|
|
4977
4955
|
defaultOptions: [{ fixable: true }],
|
|
4978
4956
|
create(context) {
|
|
4979
|
-
var _a
|
|
4980
|
-
const isFixable
|
|
4957
|
+
var _a;
|
|
4958
|
+
const { fixable: isFixable } = parseUseNormalizedImportsOptionsSchema(
|
|
4959
|
+
(_a = context.options[0]) != null ? _a : { fixable: true }
|
|
4960
|
+
);
|
|
4981
4961
|
return {
|
|
4982
4962
|
ImportDeclaration(node) {
|
|
4983
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.
|
|
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,50 +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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
interface ConsistentTestFunctionOptions {
|
|
74
|
-
preference?: "it" | "test";
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* This file was automatically generated by json-schema-to-typescript.
|
|
79
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
80
|
-
* and run json-schema-to-typescript to regenerate this file.
|
|
81
|
-
*/
|
|
82
|
-
interface NoNamespaceImportsOptions {
|
|
83
|
-
allow?: string[];
|
|
84
|
-
}
|
|
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>;
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*/
|
|
91
|
-
interface NoRelativeImportsOptions {
|
|
92
|
-
depth?: number;
|
|
93
|
-
}
|
|
80
|
+
declare const noRelativeImportsOptionsSchema: z.ZodObject<{
|
|
81
|
+
depth: z.ZodOptional<z.ZodInt>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
type NoRelativeImportsOptions = z.infer<typeof noRelativeImportsOptionsSchema>;
|
|
94
84
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
interface StandardiseErrorMessagesOptions {
|
|
101
|
-
regex?: string;
|
|
102
|
-
}
|
|
85
|
+
declare const standardiseErrorMessagesOptionsSchema: z.ZodObject<{
|
|
86
|
+
regex: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
type StandardiseErrorMessagesOptions = z.infer<typeof standardiseErrorMessagesOptionsSchema>;
|
|
103
89
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/
|
|
109
|
-
interface UseNormalizedImportsOptions {
|
|
110
|
-
fixable?: boolean;
|
|
111
|
-
}
|
|
90
|
+
declare const useNormalizedImportsOptionsSchema: z.ZodObject<{
|
|
91
|
+
fixable: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
type UseNormalizedImportsOptions = z.infer<typeof useNormalizedImportsOptionsSchema>;
|
|
112
94
|
|
|
113
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.
|
|
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,50 +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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
interface ConsistentTestFunctionOptions {
|
|
74
|
-
preference?: "it" | "test";
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* This file was automatically generated by json-schema-to-typescript.
|
|
79
|
-
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
80
|
-
* and run json-schema-to-typescript to regenerate this file.
|
|
81
|
-
*/
|
|
82
|
-
interface NoNamespaceImportsOptions {
|
|
83
|
-
allow?: string[];
|
|
84
|
-
}
|
|
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>;
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*/
|
|
91
|
-
interface NoRelativeImportsOptions {
|
|
92
|
-
depth?: number;
|
|
93
|
-
}
|
|
80
|
+
declare const noRelativeImportsOptionsSchema: z.ZodObject<{
|
|
81
|
+
depth: z.ZodOptional<z.ZodInt>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
type NoRelativeImportsOptions = z.infer<typeof noRelativeImportsOptionsSchema>;
|
|
94
84
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
interface StandardiseErrorMessagesOptions {
|
|
101
|
-
regex?: string;
|
|
102
|
-
}
|
|
85
|
+
declare const standardiseErrorMessagesOptionsSchema: z.ZodObject<{
|
|
86
|
+
regex: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
type StandardiseErrorMessagesOptions = z.infer<typeof standardiseErrorMessagesOptionsSchema>;
|
|
103
89
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/
|
|
109
|
-
interface UseNormalizedImportsOptions {
|
|
110
|
-
fixable?: boolean;
|
|
111
|
-
}
|
|
90
|
+
declare const useNormalizedImportsOptionsSchema: z.ZodObject<{
|
|
91
|
+
fixable: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
type UseNormalizedImportsOptions = z.infer<typeof useNormalizedImportsOptionsSchema>;
|
|
112
94
|
|
|
113
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.
|
|
3746
|
+
var version = "2.9.0";
|
|
3747
3747
|
|
|
3748
3748
|
// src/configs/index.ts
|
|
3749
3749
|
import packageJson from "eslint-plugin-package-json";
|
|
@@ -3851,6 +3851,14 @@ var javaScriptLanguageOptions = {
|
|
|
3851
3851
|
};
|
|
3852
3852
|
var javaScriptLanguageOptions_default = javaScriptLanguageOptions;
|
|
3853
3853
|
|
|
3854
|
+
// src/configs/miscellaneous/unusedVarsIgnorePatterns.ts
|
|
3855
|
+
var unusedVarsIgnorePatterns = {
|
|
3856
|
+
argsIgnorePattern: "^_",
|
|
3857
|
+
caughtErrorsIgnorePattern: "^_",
|
|
3858
|
+
varsIgnorePattern: "^_"
|
|
3859
|
+
};
|
|
3860
|
+
var unusedVarsIgnorePatterns_default = unusedVarsIgnorePatterns;
|
|
3861
|
+
|
|
3854
3862
|
// src/configs/general/javaScriptBase.ts
|
|
3855
3863
|
var javaScriptBase = [
|
|
3856
3864
|
import_js.default.configs.recommended,
|
|
@@ -3884,14 +3892,7 @@ var javaScriptBase = [
|
|
|
3884
3892
|
}
|
|
3885
3893
|
],
|
|
3886
3894
|
"no-undef": "error",
|
|
3887
|
-
"no-unused-vars": [
|
|
3888
|
-
"error",
|
|
3889
|
-
{
|
|
3890
|
-
argsIgnorePattern: "^_",
|
|
3891
|
-
caughtErrorsIgnorePattern: "^_",
|
|
3892
|
-
varsIgnorePattern: "^_"
|
|
3893
|
-
}
|
|
3894
|
-
],
|
|
3895
|
+
"no-unused-vars": ["error", unusedVarsIgnorePatterns_default],
|
|
3895
3896
|
"no-useless-rename": "error",
|
|
3896
3897
|
"no-useless-return": "error",
|
|
3897
3898
|
"prefer-const": "error"
|
|
@@ -4122,26 +4123,15 @@ var typeScriptBase = [
|
|
|
4122
4123
|
"@typescript-eslint/explicit-member-accessibility": "error",
|
|
4123
4124
|
"@typescript-eslint/no-deprecated": "warn",
|
|
4124
4125
|
"@typescript-eslint/no-redeclare": ["error", { ignoreDeclarationMerge: true }],
|
|
4125
|
-
"@typescript-eslint/no-unused-vars": [
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
argsIgnorePattern: "^_",
|
|
4129
|
-
caughtErrorsIgnorePattern: "^_",
|
|
4130
|
-
varsIgnorePattern: "^_"
|
|
4131
|
-
}
|
|
4132
|
-
],
|
|
4126
|
+
"@typescript-eslint/no-unused-vars": ["error", unusedVarsIgnorePatterns_default],
|
|
4127
|
+
// Disable import/no-unresolved (enabled in general/javascript, being extended here) because the TypeScript compiler already catches unused imports for us.
|
|
4128
|
+
"import/no-unresolved": "off",
|
|
4133
4129
|
// Disable regular no-redeclare in favour of TypeScript-specific version since that will flag type redeclarations when we do const MyType = {}; export type MyType = ...
|
|
4134
4130
|
"no-redeclare": "off",
|
|
4135
4131
|
// Disable no-undef because undefined variables tend to be better caught by the TypeScript compiler.
|
|
4136
4132
|
"no-undef": "off",
|
|
4137
4133
|
// Disable regular no-unused-vars rule since that will flag interface declarations. Only use the TypeScript specific rule for this.
|
|
4138
4134
|
"no-unused-vars": "off"
|
|
4139
|
-
},
|
|
4140
|
-
settings: {
|
|
4141
|
-
"import/resolver": {
|
|
4142
|
-
node: true,
|
|
4143
|
-
typescript: true
|
|
4144
|
-
}
|
|
4145
4135
|
}
|
|
4146
4136
|
}
|
|
4147
4137
|
];
|
|
@@ -4458,7 +4448,7 @@ var configs_default = createAlexPluginConfigs;
|
|
|
4458
4448
|
|
|
4459
4449
|
// src/rules/consistent-test-function.ts
|
|
4460
4450
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4461
|
-
import
|
|
4451
|
+
import z2 from "zod";
|
|
4462
4452
|
|
|
4463
4453
|
// src/createRule.ts
|
|
4464
4454
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
@@ -4467,6 +4457,14 @@ var createRule = ESLintUtils.RuleCreator((ruleName) => {
|
|
|
4467
4457
|
});
|
|
4468
4458
|
var createRule_default = createRule;
|
|
4469
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
|
+
|
|
4470
4468
|
// src/utility/getImportSpecifiersAfterRemoving.ts
|
|
4471
4469
|
function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
|
|
4472
4470
|
return specifiers.filter((specifier) => {
|
|
@@ -4478,10 +4476,17 @@ function getImportSpecifiersAfterRemoving(context, specifiers, importToRemove) {
|
|
|
4478
4476
|
var getImportSpecifiersAfterRemoving_default = getImportSpecifiersAfterRemoving;
|
|
4479
4477
|
|
|
4480
4478
|
// src/rules/consistent-test-function.ts
|
|
4481
|
-
var validTestFunctionsSchema =
|
|
4479
|
+
var validTestFunctionsSchema = z2.enum(["test", "it"]);
|
|
4482
4480
|
function parseTestFunction(data) {
|
|
4483
4481
|
return validTestFunctionsSchema.parse(data);
|
|
4484
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);
|
|
4485
4490
|
var consistentTestFunction = createRule_default({
|
|
4486
4491
|
name: "consistent-test-function",
|
|
4487
4492
|
meta: {
|
|
@@ -4493,46 +4498,36 @@ var consistentTestFunction = createRule_default({
|
|
|
4493
4498
|
},
|
|
4494
4499
|
type: "suggestion",
|
|
4495
4500
|
fixable: "code",
|
|
4496
|
-
schema
|
|
4497
|
-
{
|
|
4498
|
-
type: "object",
|
|
4499
|
-
properties: {
|
|
4500
|
-
preference: {
|
|
4501
|
-
type: "string",
|
|
4502
|
-
enum: ["it", "test"]
|
|
4503
|
-
}
|
|
4504
|
-
},
|
|
4505
|
-
additionalProperties: false
|
|
4506
|
-
}
|
|
4507
|
-
]
|
|
4501
|
+
schema
|
|
4508
4502
|
},
|
|
4509
4503
|
defaultOptions: [{ preference: "test" }],
|
|
4510
4504
|
create(context) {
|
|
4511
4505
|
var _a;
|
|
4512
|
-
const preference = (
|
|
4513
|
-
|
|
4506
|
+
const { preference } = parseConsistentTestFunctionOptions(
|
|
4507
|
+
(_a = context.options[0]) != null ? _a : { preference: "test" }
|
|
4508
|
+
);
|
|
4514
4509
|
return {
|
|
4515
4510
|
CallExpression(node) {
|
|
4516
|
-
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "it" &&
|
|
4511
|
+
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "it" && preference === "test") {
|
|
4517
4512
|
return context.report({
|
|
4518
4513
|
node,
|
|
4519
4514
|
messageId: "message",
|
|
4520
4515
|
data: {
|
|
4521
4516
|
source: node.callee.name,
|
|
4522
|
-
preference
|
|
4517
|
+
preference
|
|
4523
4518
|
},
|
|
4524
4519
|
fix(fixer) {
|
|
4525
4520
|
return fixer.replaceText(node.callee, "test");
|
|
4526
4521
|
}
|
|
4527
4522
|
});
|
|
4528
4523
|
}
|
|
4529
|
-
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "test" &&
|
|
4524
|
+
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "test" && preference === "it") {
|
|
4530
4525
|
return context.report({
|
|
4531
4526
|
node,
|
|
4532
4527
|
messageId: "message",
|
|
4533
4528
|
data: {
|
|
4534
4529
|
source: node.callee.name,
|
|
4535
|
-
preference
|
|
4530
|
+
preference
|
|
4536
4531
|
},
|
|
4537
4532
|
fix(fixer) {
|
|
4538
4533
|
return fixer.replaceText(node.callee, "it");
|
|
@@ -4542,13 +4537,13 @@ var consistentTestFunction = createRule_default({
|
|
|
4542
4537
|
},
|
|
4543
4538
|
ImportDeclaration(node) {
|
|
4544
4539
|
for (const specifier of node.specifiers) {
|
|
4545
|
-
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "it" &&
|
|
4540
|
+
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "it" && preference === "test") {
|
|
4546
4541
|
return context.report({
|
|
4547
4542
|
node,
|
|
4548
4543
|
messageId: "message",
|
|
4549
4544
|
data: {
|
|
4550
4545
|
source: specifier.imported.name,
|
|
4551
|
-
preference
|
|
4546
|
+
preference
|
|
4552
4547
|
},
|
|
4553
4548
|
fix(fixer) {
|
|
4554
4549
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
@@ -4570,18 +4565,18 @@ var consistentTestFunction = createRule_default({
|
|
|
4570
4565
|
}
|
|
4571
4566
|
return fixer.replaceTextRange(
|
|
4572
4567
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4573
|
-
|
|
4568
|
+
preference
|
|
4574
4569
|
);
|
|
4575
4570
|
}
|
|
4576
4571
|
});
|
|
4577
4572
|
}
|
|
4578
|
-
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "test" &&
|
|
4573
|
+
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && preference === "it") {
|
|
4579
4574
|
return context.report({
|
|
4580
4575
|
node,
|
|
4581
4576
|
messageId: "message",
|
|
4582
4577
|
data: {
|
|
4583
4578
|
source: specifier.imported.name,
|
|
4584
|
-
preference
|
|
4579
|
+
preference
|
|
4585
4580
|
},
|
|
4586
4581
|
fix(fixer) {
|
|
4587
4582
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
@@ -4603,7 +4598,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4603
4598
|
}
|
|
4604
4599
|
return fixer.replaceTextRange(
|
|
4605
4600
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4606
|
-
|
|
4601
|
+
preference
|
|
4607
4602
|
);
|
|
4608
4603
|
}
|
|
4609
4604
|
});
|
|
@@ -4655,6 +4650,14 @@ var noIsolatedTests = createRule_default({
|
|
|
4655
4650
|
var no_isolated_tests_default = noIsolatedTests;
|
|
4656
4651
|
|
|
4657
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);
|
|
4658
4661
|
var noNamespaceImports = createRule_default({
|
|
4659
4662
|
name: "no-namespace-imports",
|
|
4660
4663
|
meta: {
|
|
@@ -4665,31 +4668,17 @@ var noNamespaceImports = createRule_default({
|
|
|
4665
4668
|
message: 'Import * from "{{source}}" is not allowed. Please use named imports instead.'
|
|
4666
4669
|
},
|
|
4667
4670
|
type: "suggestion",
|
|
4668
|
-
schema:
|
|
4669
|
-
{
|
|
4670
|
-
type: "object",
|
|
4671
|
-
properties: {
|
|
4672
|
-
allow: {
|
|
4673
|
-
type: "array",
|
|
4674
|
-
items: {
|
|
4675
|
-
type: "string"
|
|
4676
|
-
},
|
|
4677
|
-
uniqueItems: true
|
|
4678
|
-
}
|
|
4679
|
-
},
|
|
4680
|
-
additionalProperties: false
|
|
4681
|
-
}
|
|
4682
|
-
]
|
|
4671
|
+
schema: schema2
|
|
4683
4672
|
},
|
|
4684
4673
|
defaultOptions: [{ allow: [""] }],
|
|
4685
4674
|
create(context) {
|
|
4686
4675
|
var _a;
|
|
4687
|
-
const
|
|
4676
|
+
const { allow } = parseNoNamespaceImportsOptions((_a = context.options[0]) != null ? _a : { allow: [] });
|
|
4688
4677
|
return {
|
|
4689
4678
|
ImportDeclaration(node) {
|
|
4690
4679
|
const allSpecifiers = node.specifiers;
|
|
4691
4680
|
for (const specifier of allSpecifiers) {
|
|
4692
|
-
if (specifier.type === "ImportNamespaceSpecifier" && !(
|
|
4681
|
+
if (specifier.type === "ImportNamespaceSpecifier" && !(allow == null ? void 0 : allow.includes(node.source.value))) {
|
|
4693
4682
|
context.report({
|
|
4694
4683
|
node,
|
|
4695
4684
|
messageId: "message",
|
|
@@ -4742,6 +4731,14 @@ var noPluginConfigAccessFromSrcConfigs = createRule_default({
|
|
|
4742
4731
|
var no_plugin_configs_access_from_src_configs_default = noPluginConfigAccessFromSrcConfigs;
|
|
4743
4732
|
|
|
4744
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);
|
|
4745
4742
|
var noRelativeImports = createRule_default({
|
|
4746
4743
|
name: "no-relative-imports",
|
|
4747
4744
|
meta: {
|
|
@@ -4753,34 +4750,16 @@ var noRelativeImports = createRule_default({
|
|
|
4753
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}}?!"
|
|
4754
4751
|
},
|
|
4755
4752
|
type: "suggestion",
|
|
4756
|
-
schema:
|
|
4757
|
-
{
|
|
4758
|
-
type: "object",
|
|
4759
|
-
properties: {
|
|
4760
|
-
depth: {
|
|
4761
|
-
type: "number"
|
|
4762
|
-
}
|
|
4763
|
-
},
|
|
4764
|
-
additionalProperties: false
|
|
4765
|
-
}
|
|
4766
|
-
]
|
|
4753
|
+
schema: schema3
|
|
4767
4754
|
},
|
|
4768
4755
|
defaultOptions: [{ depth: void 0 }],
|
|
4769
4756
|
create(context) {
|
|
4770
4757
|
var _a;
|
|
4771
|
-
const
|
|
4772
|
-
if (allowedDepth !== void 0) {
|
|
4773
|
-
if (allowedDepth % 1 !== 0) {
|
|
4774
|
-
throw new Error("NON_INTEGER_DEPTH_NOT_ALLOWED");
|
|
4775
|
-
}
|
|
4776
|
-
if (allowedDepth < 0) {
|
|
4777
|
-
throw new Error("NEGATIVE_DEPTH_NOT_ALLOWED");
|
|
4778
|
-
}
|
|
4779
|
-
}
|
|
4758
|
+
const { depth } = parseNoRelativeImportsOptions((_a = context.options[0]) != null ? _a : { depth: void 0 });
|
|
4780
4759
|
return {
|
|
4781
4760
|
ImportDeclaration(node) {
|
|
4782
4761
|
if (node.source.value.includes("./") || node.source.value.includes("../")) {
|
|
4783
|
-
if (
|
|
4762
|
+
if (depth === void 0) {
|
|
4784
4763
|
return context.report({
|
|
4785
4764
|
node,
|
|
4786
4765
|
messageId: "strictNoRelative",
|
|
@@ -4808,18 +4787,18 @@ var noRelativeImports = createRule_default({
|
|
|
4808
4787
|
}
|
|
4809
4788
|
});
|
|
4810
4789
|
}
|
|
4811
|
-
if (
|
|
4790
|
+
if (depth === 0 && importPathParts[0] === ".") {
|
|
4812
4791
|
return;
|
|
4813
4792
|
}
|
|
4814
4793
|
let endOfRelativePathFound = false;
|
|
4815
|
-
for (const part of importPathParts.slice(0,
|
|
4794
|
+
for (const part of importPathParts.slice(0, depth + 1)) {
|
|
4816
4795
|
if (part !== "..") {
|
|
4817
4796
|
endOfRelativePathFound = true;
|
|
4818
4797
|
break;
|
|
4819
4798
|
}
|
|
4820
4799
|
}
|
|
4821
4800
|
if (!endOfRelativePathFound) {
|
|
4822
|
-
if (
|
|
4801
|
+
if (depth === 0) {
|
|
4823
4802
|
return context.report({
|
|
4824
4803
|
node,
|
|
4825
4804
|
messageId: "rootOnly",
|
|
@@ -4833,8 +4812,8 @@ var noRelativeImports = createRule_default({
|
|
|
4833
4812
|
messageId: "exceededAllowedDepth",
|
|
4834
4813
|
data: {
|
|
4835
4814
|
source: node.source.value,
|
|
4836
|
-
depth
|
|
4837
|
-
s:
|
|
4815
|
+
depth,
|
|
4816
|
+
s: depth !== 1 ? "s" : ""
|
|
4838
4817
|
}
|
|
4839
4818
|
});
|
|
4840
4819
|
}
|
|
@@ -4879,9 +4858,20 @@ var no_skipped_tests_default = noSkippedTests;
|
|
|
4879
4858
|
|
|
4880
4859
|
// src/rules/standardise-error-messages.ts
|
|
4881
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]+)*$";
|
|
4882
4870
|
function checkCurrentNode(context, node) {
|
|
4883
|
-
var _a
|
|
4884
|
-
const errorRegex =
|
|
4871
|
+
var _a;
|
|
4872
|
+
const { regex: errorRegex = defaultErrorRegex } = parseStandardiseErrorMessagesOptions(
|
|
4873
|
+
(_a = context.options[0]) != null ? _a : { regex: defaultErrorRegex }
|
|
4874
|
+
);
|
|
4885
4875
|
if (node.callee.type === AST_NODE_TYPES3.Identifier && node.callee.name === "Error") {
|
|
4886
4876
|
const [errorArgument] = node.arguments;
|
|
4887
4877
|
const errorMessage = errorArgument.type === AST_NODE_TYPES3.Literal ? errorArgument.value : "";
|
|
@@ -4907,19 +4897,9 @@ var standardiseErrorMessages = createRule_default({
|
|
|
4907
4897
|
message: "Expected error message {{error}} to match {{regex}}."
|
|
4908
4898
|
},
|
|
4909
4899
|
type: "suggestion",
|
|
4910
|
-
schema:
|
|
4911
|
-
{
|
|
4912
|
-
type: "object",
|
|
4913
|
-
properties: {
|
|
4914
|
-
regex: {
|
|
4915
|
-
type: "string"
|
|
4916
|
-
}
|
|
4917
|
-
},
|
|
4918
|
-
additionalProperties: false
|
|
4919
|
-
}
|
|
4920
|
-
]
|
|
4900
|
+
schema: schema4
|
|
4921
4901
|
},
|
|
4922
|
-
defaultOptions: [{ regex:
|
|
4902
|
+
defaultOptions: [{ regex: defaultErrorRegex }],
|
|
4923
4903
|
create(context) {
|
|
4924
4904
|
return {
|
|
4925
4905
|
CallExpression(node) {
|
|
@@ -4935,6 +4915,14 @@ var standardise_error_messages_default = standardiseErrorMessages;
|
|
|
4935
4915
|
|
|
4936
4916
|
// src/rules/use-normalized-imports.ts
|
|
4937
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);
|
|
4938
4926
|
var useNormalizedImports = createRule_default({
|
|
4939
4927
|
name: "use-normalized-imports",
|
|
4940
4928
|
meta: {
|
|
@@ -4945,23 +4933,15 @@ var useNormalizedImports = createRule_default({
|
|
|
4945
4933
|
pathNotNormalized: "Import path {{nonNormalized}} is not normalised. Please use {{normalized}} instead."
|
|
4946
4934
|
},
|
|
4947
4935
|
type: "suggestion",
|
|
4948
|
-
schema:
|
|
4949
|
-
{
|
|
4950
|
-
type: "object",
|
|
4951
|
-
properties: {
|
|
4952
|
-
fixable: {
|
|
4953
|
-
type: "boolean"
|
|
4954
|
-
}
|
|
4955
|
-
},
|
|
4956
|
-
additionalProperties: false
|
|
4957
|
-
}
|
|
4958
|
-
],
|
|
4936
|
+
schema: schema5,
|
|
4959
4937
|
fixable: "code"
|
|
4960
4938
|
},
|
|
4961
4939
|
defaultOptions: [{ fixable: true }],
|
|
4962
4940
|
create(context) {
|
|
4963
|
-
var _a
|
|
4964
|
-
const isFixable
|
|
4941
|
+
var _a;
|
|
4942
|
+
const { fixable: isFixable } = parseUseNormalizedImportsOptionsSchema(
|
|
4943
|
+
(_a = context.options[0]) != null ? _a : { fixable: true }
|
|
4944
|
+
);
|
|
4965
4945
|
return {
|
|
4966
4946
|
ImportDeclaration(node) {
|
|
4967
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.
|
|
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",
|