@alextheman/eslint-plugin 3.1.1 → 3.1.3
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 +40 -35
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -35
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3765,7 +3765,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
3765
3765
|
|
|
3766
3766
|
// package.json
|
|
3767
3767
|
var name = "@alextheman/eslint-plugin";
|
|
3768
|
-
var version = "3.1.
|
|
3768
|
+
var version = "3.1.3";
|
|
3769
3769
|
|
|
3770
3770
|
// src/configs/index.ts
|
|
3771
3771
|
var import_eslint_plugin_package_json = __toESM(require("eslint-plugin-package-json"), 1);
|
|
@@ -3993,6 +3993,14 @@ function createPersonalJavaScriptBaseConfig(plugin) {
|
|
|
3993
3993
|
"prettier/prettier": ["warn", prettierRules_default],
|
|
3994
3994
|
"sort-vars": "error"
|
|
3995
3995
|
}
|
|
3996
|
+
},
|
|
3997
|
+
{
|
|
3998
|
+
files: ["src/**/index.{js,jsx,ts,tsx}"],
|
|
3999
|
+
rules: {
|
|
4000
|
+
// Since index files generally tend to export files from the same folder, they tend to be more coupled with their location in the folder,
|
|
4001
|
+
// so it feels more natural to allow only root-level relative imports from an index file.
|
|
4002
|
+
"@alextheman/no-relative-imports": ["error", { depth: 0 }]
|
|
4003
|
+
}
|
|
3996
4004
|
}
|
|
3997
4005
|
];
|
|
3998
4006
|
}
|
|
@@ -4487,13 +4495,24 @@ var configs_default = createAlexPluginConfigs;
|
|
|
4487
4495
|
var import_utils2 = require("@typescript-eslint/utils");
|
|
4488
4496
|
var import_zod2 = __toESM(require("zod"), 1);
|
|
4489
4497
|
|
|
4490
|
-
// src/createRule.ts
|
|
4498
|
+
// src/rules/helpers/createRule.ts
|
|
4491
4499
|
var import_utils = require("@typescript-eslint/utils");
|
|
4492
4500
|
var createRule = import_utils.ESLintUtils.RuleCreator((ruleName) => {
|
|
4493
4501
|
return `https://github.com/AlexMan123456/eslint-plugin/${ruleName}`;
|
|
4494
4502
|
});
|
|
4495
4503
|
var createRule_default = createRule;
|
|
4496
4504
|
|
|
4505
|
+
// src/rules/helpers/fixOnCondition.ts
|
|
4506
|
+
function fixOnCondition(fixable, fix) {
|
|
4507
|
+
return (fixer) => {
|
|
4508
|
+
if (!fixable) {
|
|
4509
|
+
return null;
|
|
4510
|
+
}
|
|
4511
|
+
return fix(fixer);
|
|
4512
|
+
};
|
|
4513
|
+
}
|
|
4514
|
+
var fixOnCondition_default = fixOnCondition;
|
|
4515
|
+
|
|
4497
4516
|
// src/utility/createRuleSchema.ts
|
|
4498
4517
|
var import_utility4 = require("@alextheman/utility");
|
|
4499
4518
|
var import_zod = __toESM(require("zod"), 1);
|
|
@@ -4552,12 +4571,9 @@ var consistentTestFunction = createRule_default({
|
|
|
4552
4571
|
source: node.callee.name,
|
|
4553
4572
|
preference
|
|
4554
4573
|
},
|
|
4555
|
-
fix(fixer) {
|
|
4556
|
-
if (!fixable) {
|
|
4557
|
-
return null;
|
|
4558
|
-
}
|
|
4574
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4559
4575
|
return fixer.replaceText(node.callee, "test");
|
|
4560
|
-
}
|
|
4576
|
+
})
|
|
4561
4577
|
});
|
|
4562
4578
|
}
|
|
4563
4579
|
if (node.callee.type === import_utils2.AST_NODE_TYPES.Identifier && node.callee.name === "test" && preference === "it") {
|
|
@@ -4568,12 +4584,9 @@ var consistentTestFunction = createRule_default({
|
|
|
4568
4584
|
source: node.callee.name,
|
|
4569
4585
|
preference
|
|
4570
4586
|
},
|
|
4571
|
-
fix(fixer) {
|
|
4572
|
-
if (!fixable) {
|
|
4573
|
-
return null;
|
|
4574
|
-
}
|
|
4587
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4575
4588
|
return fixer.replaceText(node.callee, "it");
|
|
4576
|
-
}
|
|
4589
|
+
})
|
|
4577
4590
|
});
|
|
4578
4591
|
}
|
|
4579
4592
|
},
|
|
@@ -4587,10 +4600,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4587
4600
|
source: specifier.imported.name,
|
|
4588
4601
|
preference
|
|
4589
4602
|
},
|
|
4590
|
-
fix(fixer) {
|
|
4591
|
-
if (!fixable) {
|
|
4592
|
-
return null;
|
|
4593
|
-
}
|
|
4603
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4594
4604
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
4595
4605
|
return specifier2.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === import_utils2.AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
|
|
4596
4606
|
});
|
|
@@ -4612,7 +4622,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4612
4622
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4613
4623
|
preference
|
|
4614
4624
|
);
|
|
4615
|
-
}
|
|
4625
|
+
})
|
|
4616
4626
|
});
|
|
4617
4627
|
}
|
|
4618
4628
|
if (specifier.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils2.AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && preference === "it") {
|
|
@@ -4623,10 +4633,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4623
4633
|
source: specifier.imported.name,
|
|
4624
4634
|
preference
|
|
4625
4635
|
},
|
|
4626
|
-
fix(fixer) {
|
|
4627
|
-
if (!fixable) {
|
|
4628
|
-
return null;
|
|
4629
|
-
}
|
|
4636
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4630
4637
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
4631
4638
|
return specifier2.type === import_utils2.AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === import_utils2.AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
|
|
4632
4639
|
});
|
|
@@ -4648,7 +4655,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4648
4655
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4649
4656
|
preference
|
|
4650
4657
|
);
|
|
4651
|
-
}
|
|
4658
|
+
})
|
|
4652
4659
|
});
|
|
4653
4660
|
}
|
|
4654
4661
|
}
|
|
@@ -4987,10 +4994,12 @@ var useNormalizedImports = createRule_default({
|
|
|
4987
4994
|
defaultOptions: [{ fixable: true }],
|
|
4988
4995
|
create(context) {
|
|
4989
4996
|
var _a;
|
|
4990
|
-
const { fixable } = parseUseNormalizedImportsOptions(
|
|
4997
|
+
const { fixable = true } = parseUseNormalizedImportsOptions(
|
|
4998
|
+
(_a = context.options[0]) != null ? _a : { fixable: true }
|
|
4999
|
+
);
|
|
4991
5000
|
return {
|
|
4992
5001
|
ImportDeclaration(node) {
|
|
4993
|
-
const normalizedPath = import_path.default.posix.normalize(node.source.value);
|
|
5002
|
+
const normalizedPath = node.source.value.startsWith("./") ? `./${import_path.default.posix.normalize(node.source.value)}` : import_path.default.posix.normalize(node.source.value);
|
|
4994
5003
|
if (node.source.value !== normalizedPath) {
|
|
4995
5004
|
return context.report({
|
|
4996
5005
|
node,
|
|
@@ -4999,13 +5008,10 @@ var useNormalizedImports = createRule_default({
|
|
|
4999
5008
|
nonNormalized: node.source.value,
|
|
5000
5009
|
normalized: normalizedPath
|
|
5001
5010
|
},
|
|
5002
|
-
fix(fixer) {
|
|
5003
|
-
if (!fixable) {
|
|
5004
|
-
return null;
|
|
5005
|
-
}
|
|
5011
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
5006
5012
|
const [quote] = node.source.raw;
|
|
5007
5013
|
return fixer.replaceText(node.source, `${quote}${normalizedPath}${quote}`);
|
|
5008
|
-
}
|
|
5014
|
+
})
|
|
5009
5015
|
});
|
|
5010
5016
|
}
|
|
5011
5017
|
}
|
|
@@ -5039,7 +5045,9 @@ var useObjectShorthand = createRule_default({
|
|
|
5039
5045
|
defaultOptions: [{ fixable: true }],
|
|
5040
5046
|
create(context) {
|
|
5041
5047
|
var _a;
|
|
5042
|
-
const { fixable } = parseUseObjectShorthandOptions(
|
|
5048
|
+
const { fixable = true } = parseUseObjectShorthandOptions(
|
|
5049
|
+
(_a = context.options[0]) != null ? _a : { fixable: true }
|
|
5050
|
+
);
|
|
5043
5051
|
return {
|
|
5044
5052
|
Property(node) {
|
|
5045
5053
|
if (node.key.type === import_utils5.AST_NODE_TYPES.Identifier && node.value.type === import_utils5.AST_NODE_TYPES.Identifier && node.key.name === node.value.name && !node.shorthand) {
|
|
@@ -5049,13 +5057,10 @@ var useObjectShorthand = createRule_default({
|
|
|
5049
5057
|
data: {
|
|
5050
5058
|
source: context.sourceCode.getText(node)
|
|
5051
5059
|
},
|
|
5052
|
-
fix(fixer) {
|
|
5053
|
-
if (!fixable) {
|
|
5054
|
-
return null;
|
|
5055
|
-
}
|
|
5060
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
5056
5061
|
const key = node.key;
|
|
5057
5062
|
return fixer.replaceTextRange([node.range[0], node.range[1]], key.name);
|
|
5058
|
-
}
|
|
5063
|
+
})
|
|
5059
5064
|
});
|
|
5060
5065
|
}
|
|
5061
5066
|
}
|
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 = "3.1.
|
|
7
|
+
var version = "3.1.3";
|
|
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
|
|
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 = "3.1.
|
|
7
|
+
var version = "3.1.3";
|
|
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
|
|
package/dist/index.js
CHANGED
|
@@ -3744,7 +3744,7 @@ var require_src = __commonJS({
|
|
|
3744
3744
|
|
|
3745
3745
|
// package.json
|
|
3746
3746
|
var name = "@alextheman/eslint-plugin";
|
|
3747
|
-
var version = "3.1.
|
|
3747
|
+
var version = "3.1.3";
|
|
3748
3748
|
|
|
3749
3749
|
// src/configs/index.ts
|
|
3750
3750
|
import packageJson from "eslint-plugin-package-json";
|
|
@@ -3972,6 +3972,14 @@ function createPersonalJavaScriptBaseConfig(plugin) {
|
|
|
3972
3972
|
"prettier/prettier": ["warn", prettierRules_default],
|
|
3973
3973
|
"sort-vars": "error"
|
|
3974
3974
|
}
|
|
3975
|
+
},
|
|
3976
|
+
{
|
|
3977
|
+
files: ["src/**/index.{js,jsx,ts,tsx}"],
|
|
3978
|
+
rules: {
|
|
3979
|
+
// Since index files generally tend to export files from the same folder, they tend to be more coupled with their location in the folder,
|
|
3980
|
+
// so it feels more natural to allow only root-level relative imports from an index file.
|
|
3981
|
+
"@alextheman/no-relative-imports": ["error", { depth: 0 }]
|
|
3982
|
+
}
|
|
3975
3983
|
}
|
|
3976
3984
|
];
|
|
3977
3985
|
}
|
|
@@ -4466,13 +4474,24 @@ var configs_default = createAlexPluginConfigs;
|
|
|
4466
4474
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4467
4475
|
import z2 from "zod";
|
|
4468
4476
|
|
|
4469
|
-
// src/createRule.ts
|
|
4477
|
+
// src/rules/helpers/createRule.ts
|
|
4470
4478
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
4471
4479
|
var createRule = ESLintUtils.RuleCreator((ruleName) => {
|
|
4472
4480
|
return `https://github.com/AlexMan123456/eslint-plugin/${ruleName}`;
|
|
4473
4481
|
});
|
|
4474
4482
|
var createRule_default = createRule;
|
|
4475
4483
|
|
|
4484
|
+
// src/rules/helpers/fixOnCondition.ts
|
|
4485
|
+
function fixOnCondition(fixable, fix) {
|
|
4486
|
+
return (fixer) => {
|
|
4487
|
+
if (!fixable) {
|
|
4488
|
+
return null;
|
|
4489
|
+
}
|
|
4490
|
+
return fix(fixer);
|
|
4491
|
+
};
|
|
4492
|
+
}
|
|
4493
|
+
var fixOnCondition_default = fixOnCondition;
|
|
4494
|
+
|
|
4476
4495
|
// src/utility/createRuleSchema.ts
|
|
4477
4496
|
import { omitProperties as omitProperties2 } from "@alextheman/utility";
|
|
4478
4497
|
import z from "zod";
|
|
@@ -4531,12 +4550,9 @@ var consistentTestFunction = createRule_default({
|
|
|
4531
4550
|
source: node.callee.name,
|
|
4532
4551
|
preference
|
|
4533
4552
|
},
|
|
4534
|
-
fix(fixer) {
|
|
4535
|
-
if (!fixable) {
|
|
4536
|
-
return null;
|
|
4537
|
-
}
|
|
4553
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4538
4554
|
return fixer.replaceText(node.callee, "test");
|
|
4539
|
-
}
|
|
4555
|
+
})
|
|
4540
4556
|
});
|
|
4541
4557
|
}
|
|
4542
4558
|
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "test" && preference === "it") {
|
|
@@ -4547,12 +4563,9 @@ var consistentTestFunction = createRule_default({
|
|
|
4547
4563
|
source: node.callee.name,
|
|
4548
4564
|
preference
|
|
4549
4565
|
},
|
|
4550
|
-
fix(fixer) {
|
|
4551
|
-
if (!fixable) {
|
|
4552
|
-
return null;
|
|
4553
|
-
}
|
|
4566
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4554
4567
|
return fixer.replaceText(node.callee, "it");
|
|
4555
|
-
}
|
|
4568
|
+
})
|
|
4556
4569
|
});
|
|
4557
4570
|
}
|
|
4558
4571
|
},
|
|
@@ -4566,10 +4579,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4566
4579
|
source: specifier.imported.name,
|
|
4567
4580
|
preference
|
|
4568
4581
|
},
|
|
4569
|
-
fix(fixer) {
|
|
4570
|
-
if (!fixable) {
|
|
4571
|
-
return null;
|
|
4572
|
-
}
|
|
4582
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4573
4583
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
4574
4584
|
return specifier2.type === AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
|
|
4575
4585
|
});
|
|
@@ -4591,7 +4601,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4591
4601
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4592
4602
|
preference
|
|
4593
4603
|
);
|
|
4594
|
-
}
|
|
4604
|
+
})
|
|
4595
4605
|
});
|
|
4596
4606
|
}
|
|
4597
4607
|
if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "test" && preference === "it") {
|
|
@@ -4602,10 +4612,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4602
4612
|
source: specifier.imported.name,
|
|
4603
4613
|
preference
|
|
4604
4614
|
},
|
|
4605
|
-
fix(fixer) {
|
|
4606
|
-
if (!fixable) {
|
|
4607
|
-
return null;
|
|
4608
|
-
}
|
|
4615
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4609
4616
|
const importedNames = node.specifiers.map((specifier2) => {
|
|
4610
4617
|
return specifier2.type === AST_NODE_TYPES.ImportSpecifier && specifier2.imported.type === AST_NODE_TYPES.Identifier ? specifier2.imported.name : "";
|
|
4611
4618
|
});
|
|
@@ -4627,7 +4634,7 @@ var consistentTestFunction = createRule_default({
|
|
|
4627
4634
|
[specifier.imported.range[0], specifier.imported.range[1]],
|
|
4628
4635
|
preference
|
|
4629
4636
|
);
|
|
4630
|
-
}
|
|
4637
|
+
})
|
|
4631
4638
|
});
|
|
4632
4639
|
}
|
|
4633
4640
|
}
|
|
@@ -4966,10 +4973,12 @@ var useNormalizedImports = createRule_default({
|
|
|
4966
4973
|
defaultOptions: [{ fixable: true }],
|
|
4967
4974
|
create(context) {
|
|
4968
4975
|
var _a;
|
|
4969
|
-
const { fixable } = parseUseNormalizedImportsOptions(
|
|
4976
|
+
const { fixable = true } = parseUseNormalizedImportsOptions(
|
|
4977
|
+
(_a = context.options[0]) != null ? _a : { fixable: true }
|
|
4978
|
+
);
|
|
4970
4979
|
return {
|
|
4971
4980
|
ImportDeclaration(node) {
|
|
4972
|
-
const normalizedPath = path.posix.normalize(node.source.value);
|
|
4981
|
+
const normalizedPath = node.source.value.startsWith("./") ? `./${path.posix.normalize(node.source.value)}` : path.posix.normalize(node.source.value);
|
|
4973
4982
|
if (node.source.value !== normalizedPath) {
|
|
4974
4983
|
return context.report({
|
|
4975
4984
|
node,
|
|
@@ -4978,13 +4987,10 @@ var useNormalizedImports = createRule_default({
|
|
|
4978
4987
|
nonNormalized: node.source.value,
|
|
4979
4988
|
normalized: normalizedPath
|
|
4980
4989
|
},
|
|
4981
|
-
fix(fixer) {
|
|
4982
|
-
if (!fixable) {
|
|
4983
|
-
return null;
|
|
4984
|
-
}
|
|
4990
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
4985
4991
|
const [quote] = node.source.raw;
|
|
4986
4992
|
return fixer.replaceText(node.source, `${quote}${normalizedPath}${quote}`);
|
|
4987
|
-
}
|
|
4993
|
+
})
|
|
4988
4994
|
});
|
|
4989
4995
|
}
|
|
4990
4996
|
}
|
|
@@ -5018,7 +5024,9 @@ var useObjectShorthand = createRule_default({
|
|
|
5018
5024
|
defaultOptions: [{ fixable: true }],
|
|
5019
5025
|
create(context) {
|
|
5020
5026
|
var _a;
|
|
5021
|
-
const { fixable } = parseUseObjectShorthandOptions(
|
|
5027
|
+
const { fixable = true } = parseUseObjectShorthandOptions(
|
|
5028
|
+
(_a = context.options[0]) != null ? _a : { fixable: true }
|
|
5029
|
+
);
|
|
5022
5030
|
return {
|
|
5023
5031
|
Property(node) {
|
|
5024
5032
|
if (node.key.type === AST_NODE_TYPES4.Identifier && node.value.type === AST_NODE_TYPES4.Identifier && node.key.name === node.value.name && !node.shorthand) {
|
|
@@ -5028,13 +5036,10 @@ var useObjectShorthand = createRule_default({
|
|
|
5028
5036
|
data: {
|
|
5029
5037
|
source: context.sourceCode.getText(node)
|
|
5030
5038
|
},
|
|
5031
|
-
fix(fixer) {
|
|
5032
|
-
if (!fixable) {
|
|
5033
|
-
return null;
|
|
5034
|
-
}
|
|
5039
|
+
fix: fixOnCondition_default(fixable, (fixer) => {
|
|
5035
5040
|
const key = node.key;
|
|
5036
5041
|
return fixer.replaceTextRange([node.range[0], node.range[1]], key.name);
|
|
5037
|
-
}
|
|
5042
|
+
})
|
|
5038
5043
|
});
|
|
5039
5044
|
}
|
|
5040
5045
|
}
|