@alextheman/eslint-plugin 1.8.2 → 1.10.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 +100 -32
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +100 -32
- package/package.json +1 -1
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.
|
|
3709
|
+
var version = "1.10.0";
|
|
3710
3710
|
|
|
3711
3711
|
// src/configs/alexPluginBase.ts
|
|
3712
3712
|
function createAlexPluginBaseConfig(plugin2) {
|
|
@@ -3717,7 +3717,8 @@ function createAlexPluginBaseConfig(plugin2) {
|
|
|
3717
3717
|
},
|
|
3718
3718
|
rules: {
|
|
3719
3719
|
"@alextheman/no-namespace-imports": "error",
|
|
3720
|
-
"@alextheman/no-relative-imports": "error"
|
|
3720
|
+
"@alextheman/no-relative-imports": "error",
|
|
3721
|
+
"@alextheman/use-object-shorthand": "error"
|
|
3721
3722
|
}
|
|
3722
3723
|
}
|
|
3723
3724
|
];
|
|
@@ -3982,59 +3983,125 @@ var noPluginConfigAccessFromSrcConfigs = create_rule_default({
|
|
|
3982
3983
|
var no_plugin_configs_access_from_src_configs_default = noPluginConfigAccessFromSrcConfigs;
|
|
3983
3984
|
|
|
3984
3985
|
// src/rules/no-relative-imports.ts
|
|
3985
|
-
var import_path = __toESM(require("path"), 1);
|
|
3986
3986
|
var noRelativeImports = create_rule_default({
|
|
3987
3987
|
name: "no-relative-imports",
|
|
3988
3988
|
meta: {
|
|
3989
3989
|
docs: { description: "Forbid the use of relative imports" },
|
|
3990
3990
|
messages: {
|
|
3991
3991
|
message: 'Relative import from "{{source}}" is not allowed.',
|
|
3992
|
-
stupidPath:
|
|
3992
|
+
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}}?!"
|
|
3993
3993
|
},
|
|
3994
3994
|
type: "suggestion",
|
|
3995
|
-
|
|
3996
|
-
|
|
3995
|
+
schema: [
|
|
3996
|
+
{
|
|
3997
|
+
type: "object",
|
|
3998
|
+
properties: {
|
|
3999
|
+
depth: {
|
|
4000
|
+
type: "number"
|
|
4001
|
+
}
|
|
4002
|
+
},
|
|
4003
|
+
additionalProperties: false
|
|
4004
|
+
}
|
|
4005
|
+
]
|
|
3997
4006
|
},
|
|
3998
|
-
defaultOptions: [],
|
|
4007
|
+
defaultOptions: [{ depth: void 0 }],
|
|
3999
4008
|
create(context) {
|
|
4009
|
+
var _a;
|
|
4010
|
+
const depth = (_a = context.options[0]) == null ? void 0 : _a.depth;
|
|
4011
|
+
if (depth !== void 0) {
|
|
4012
|
+
if (depth % 1 !== 0) {
|
|
4013
|
+
throw new Error("NON_INTEGER_DEPTH_NOT_ALLOWED");
|
|
4014
|
+
}
|
|
4015
|
+
if (depth < 0) {
|
|
4016
|
+
throw new Error("NEGATIVE_DEPTH_NOT_ALLOWED");
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4000
4019
|
return {
|
|
4001
4020
|
ImportDeclaration(node) {
|
|
4002
4021
|
if (node.source.value.includes("./") || node.source.value.includes("../")) {
|
|
4003
|
-
if (
|
|
4004
|
-
context.report({
|
|
4022
|
+
if (depth === void 0) {
|
|
4023
|
+
return context.report({
|
|
4024
|
+
node,
|
|
4025
|
+
messageId: "message",
|
|
4026
|
+
data: {
|
|
4027
|
+
source: node.source.value
|
|
4028
|
+
}
|
|
4029
|
+
});
|
|
4030
|
+
}
|
|
4031
|
+
const importPathParts = node.source.value.split("/");
|
|
4032
|
+
if (importPathParts.includes(".") && importPathParts.includes("..")) {
|
|
4033
|
+
return context.report({
|
|
4005
4034
|
node,
|
|
4006
4035
|
messageId: "stupidPath",
|
|
4007
4036
|
data: {
|
|
4008
4037
|
source: node.source.value
|
|
4009
4038
|
}
|
|
4010
4039
|
});
|
|
4011
|
-
return null;
|
|
4012
4040
|
}
|
|
4041
|
+
if (importPathParts.includes(".") && importPathParts[0] !== "." || importPathParts.includes("..") && importPathParts[0] !== "..") {
|
|
4042
|
+
return context.report({
|
|
4043
|
+
node,
|
|
4044
|
+
messageId: "stupidPath",
|
|
4045
|
+
data: {
|
|
4046
|
+
source: node.source.value
|
|
4047
|
+
}
|
|
4048
|
+
});
|
|
4049
|
+
}
|
|
4050
|
+
if (depth === 0 && importPathParts[0] === ".") {
|
|
4051
|
+
return;
|
|
4052
|
+
}
|
|
4053
|
+
let endOfRelativePathFound = false;
|
|
4054
|
+
for (const part of importPathParts.slice(0, depth + 1)) {
|
|
4055
|
+
if (part !== "..") {
|
|
4056
|
+
endOfRelativePathFound = true;
|
|
4057
|
+
break;
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
if (!endOfRelativePathFound) {
|
|
4061
|
+
return context.report({
|
|
4062
|
+
node,
|
|
4063
|
+
messageId: "message",
|
|
4064
|
+
data: {
|
|
4065
|
+
source: node.source.value
|
|
4066
|
+
}
|
|
4067
|
+
});
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
};
|
|
4072
|
+
}
|
|
4073
|
+
});
|
|
4074
|
+
var no_relative_imports_default = noRelativeImports;
|
|
4075
|
+
|
|
4076
|
+
// src/rules/use-object-shorthand.ts
|
|
4077
|
+
var import_utils2 = require("@typescript-eslint/utils");
|
|
4078
|
+
var useObjectShorthand = create_rule_default({
|
|
4079
|
+
name: "use-object-shorthand",
|
|
4080
|
+
meta: {
|
|
4081
|
+
docs: {
|
|
4082
|
+
description: 'Encourage the use of object shorthand (e.g. const property = "Hello"; const object = { property });'
|
|
4083
|
+
},
|
|
4084
|
+
messages: {
|
|
4085
|
+
useShorthand: "{ {{source}} } is not allowed. Please use the object shorthand."
|
|
4086
|
+
},
|
|
4087
|
+
type: "suggestion",
|
|
4088
|
+
fixable: "code",
|
|
4089
|
+
schema: []
|
|
4090
|
+
},
|
|
4091
|
+
defaultOptions: [],
|
|
4092
|
+
create(context) {
|
|
4093
|
+
return {
|
|
4094
|
+
Property(node) {
|
|
4095
|
+
if (node.key.type === import_utils2.AST_NODE_TYPES.Identifier && node.value.type === import_utils2.AST_NODE_TYPES.Identifier && node.key.name === node.value.name && !node.shorthand) {
|
|
4013
4096
|
context.report({
|
|
4014
4097
|
node,
|
|
4015
|
-
messageId: "
|
|
4098
|
+
messageId: "useShorthand",
|
|
4016
4099
|
data: {
|
|
4017
|
-
source:
|
|
4100
|
+
source: context.sourceCode.getText(node)
|
|
4018
4101
|
},
|
|
4019
4102
|
fix(fixer) {
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
}
|
|
4023
|
-
const fullImportPath = import_path.default.resolve(
|
|
4024
|
-
import_path.default.dirname(context.physicalFilename),
|
|
4025
|
-
node.source.value
|
|
4026
|
-
);
|
|
4027
|
-
const projectRelativePath = import_path.default.relative(
|
|
4028
|
-
context.parserOptions.tsconfigRootDir,
|
|
4029
|
-
fullImportPath
|
|
4030
|
-
);
|
|
4031
|
-
if (projectRelativePath.startsWith("..")) {
|
|
4032
|
-
return null;
|
|
4033
|
-
}
|
|
4034
|
-
return fixer.replaceText(
|
|
4035
|
-
node.source,
|
|
4036
|
-
`${node.source.raw[0]}${import_path.default.posix.normalize(projectRelativePath)}${node.source.raw[0]}`
|
|
4037
|
-
);
|
|
4103
|
+
const key = node.key;
|
|
4104
|
+
return fixer.replaceTextRange([node.range[0], node.range[1]], key.name);
|
|
4038
4105
|
}
|
|
4039
4106
|
});
|
|
4040
4107
|
}
|
|
@@ -4042,13 +4109,14 @@ var noRelativeImports = create_rule_default({
|
|
|
4042
4109
|
};
|
|
4043
4110
|
}
|
|
4044
4111
|
});
|
|
4045
|
-
var
|
|
4112
|
+
var use_object_shorthand_default = useObjectShorthand;
|
|
4046
4113
|
|
|
4047
4114
|
// src/rules/index.ts
|
|
4048
4115
|
var rules_default = {
|
|
4049
4116
|
"no-namespace-imports": no_namespace_imports_default,
|
|
4050
4117
|
"no-relative-imports": no_relative_imports_default,
|
|
4051
|
-
"no-plugin-configs-access-from-src-configs": no_plugin_configs_access_from_src_configs_default
|
|
4118
|
+
"no-plugin-configs-access-from-src-configs": no_plugin_configs_access_from_src_configs_default,
|
|
4119
|
+
"use-object-shorthand": use_object_shorthand_default
|
|
4052
4120
|
};
|
|
4053
4121
|
|
|
4054
4122
|
// src/index.ts
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
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.
|
|
3695
|
+
var version = "1.10.0";
|
|
3696
3696
|
|
|
3697
3697
|
// src/configs/alexPluginBase.ts
|
|
3698
3698
|
function createAlexPluginBaseConfig(plugin2) {
|
|
@@ -3703,7 +3703,8 @@ function createAlexPluginBaseConfig(plugin2) {
|
|
|
3703
3703
|
},
|
|
3704
3704
|
rules: {
|
|
3705
3705
|
"@alextheman/no-namespace-imports": "error",
|
|
3706
|
-
"@alextheman/no-relative-imports": "error"
|
|
3706
|
+
"@alextheman/no-relative-imports": "error",
|
|
3707
|
+
"@alextheman/use-object-shorthand": "error"
|
|
3707
3708
|
}
|
|
3708
3709
|
}
|
|
3709
3710
|
];
|
|
@@ -3968,59 +3969,125 @@ var noPluginConfigAccessFromSrcConfigs = create_rule_default({
|
|
|
3968
3969
|
var no_plugin_configs_access_from_src_configs_default = noPluginConfigAccessFromSrcConfigs;
|
|
3969
3970
|
|
|
3970
3971
|
// src/rules/no-relative-imports.ts
|
|
3971
|
-
import path from "path";
|
|
3972
3972
|
var noRelativeImports = create_rule_default({
|
|
3973
3973
|
name: "no-relative-imports",
|
|
3974
3974
|
meta: {
|
|
3975
3975
|
docs: { description: "Forbid the use of relative imports" },
|
|
3976
3976
|
messages: {
|
|
3977
3977
|
message: 'Relative import from "{{source}}" is not allowed.',
|
|
3978
|
-
stupidPath:
|
|
3978
|
+
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}}?!"
|
|
3979
3979
|
},
|
|
3980
3980
|
type: "suggestion",
|
|
3981
|
-
|
|
3982
|
-
|
|
3981
|
+
schema: [
|
|
3982
|
+
{
|
|
3983
|
+
type: "object",
|
|
3984
|
+
properties: {
|
|
3985
|
+
depth: {
|
|
3986
|
+
type: "number"
|
|
3987
|
+
}
|
|
3988
|
+
},
|
|
3989
|
+
additionalProperties: false
|
|
3990
|
+
}
|
|
3991
|
+
]
|
|
3983
3992
|
},
|
|
3984
|
-
defaultOptions: [],
|
|
3993
|
+
defaultOptions: [{ depth: void 0 }],
|
|
3985
3994
|
create(context) {
|
|
3995
|
+
var _a;
|
|
3996
|
+
const depth = (_a = context.options[0]) == null ? void 0 : _a.depth;
|
|
3997
|
+
if (depth !== void 0) {
|
|
3998
|
+
if (depth % 1 !== 0) {
|
|
3999
|
+
throw new Error("NON_INTEGER_DEPTH_NOT_ALLOWED");
|
|
4000
|
+
}
|
|
4001
|
+
if (depth < 0) {
|
|
4002
|
+
throw new Error("NEGATIVE_DEPTH_NOT_ALLOWED");
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
3986
4005
|
return {
|
|
3987
4006
|
ImportDeclaration(node) {
|
|
3988
4007
|
if (node.source.value.includes("./") || node.source.value.includes("../")) {
|
|
3989
|
-
if (
|
|
3990
|
-
context.report({
|
|
4008
|
+
if (depth === void 0) {
|
|
4009
|
+
return context.report({
|
|
4010
|
+
node,
|
|
4011
|
+
messageId: "message",
|
|
4012
|
+
data: {
|
|
4013
|
+
source: node.source.value
|
|
4014
|
+
}
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
const importPathParts = node.source.value.split("/");
|
|
4018
|
+
if (importPathParts.includes(".") && importPathParts.includes("..")) {
|
|
4019
|
+
return context.report({
|
|
3991
4020
|
node,
|
|
3992
4021
|
messageId: "stupidPath",
|
|
3993
4022
|
data: {
|
|
3994
4023
|
source: node.source.value
|
|
3995
4024
|
}
|
|
3996
4025
|
});
|
|
3997
|
-
return null;
|
|
3998
4026
|
}
|
|
4027
|
+
if (importPathParts.includes(".") && importPathParts[0] !== "." || importPathParts.includes("..") && importPathParts[0] !== "..") {
|
|
4028
|
+
return context.report({
|
|
4029
|
+
node,
|
|
4030
|
+
messageId: "stupidPath",
|
|
4031
|
+
data: {
|
|
4032
|
+
source: node.source.value
|
|
4033
|
+
}
|
|
4034
|
+
});
|
|
4035
|
+
}
|
|
4036
|
+
if (depth === 0 && importPathParts[0] === ".") {
|
|
4037
|
+
return;
|
|
4038
|
+
}
|
|
4039
|
+
let endOfRelativePathFound = false;
|
|
4040
|
+
for (const part of importPathParts.slice(0, depth + 1)) {
|
|
4041
|
+
if (part !== "..") {
|
|
4042
|
+
endOfRelativePathFound = true;
|
|
4043
|
+
break;
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
if (!endOfRelativePathFound) {
|
|
4047
|
+
return context.report({
|
|
4048
|
+
node,
|
|
4049
|
+
messageId: "message",
|
|
4050
|
+
data: {
|
|
4051
|
+
source: node.source.value
|
|
4052
|
+
}
|
|
4053
|
+
});
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
});
|
|
4060
|
+
var no_relative_imports_default = noRelativeImports;
|
|
4061
|
+
|
|
4062
|
+
// src/rules/use-object-shorthand.ts
|
|
4063
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4064
|
+
var useObjectShorthand = create_rule_default({
|
|
4065
|
+
name: "use-object-shorthand",
|
|
4066
|
+
meta: {
|
|
4067
|
+
docs: {
|
|
4068
|
+
description: 'Encourage the use of object shorthand (e.g. const property = "Hello"; const object = { property });'
|
|
4069
|
+
},
|
|
4070
|
+
messages: {
|
|
4071
|
+
useShorthand: "{ {{source}} } is not allowed. Please use the object shorthand."
|
|
4072
|
+
},
|
|
4073
|
+
type: "suggestion",
|
|
4074
|
+
fixable: "code",
|
|
4075
|
+
schema: []
|
|
4076
|
+
},
|
|
4077
|
+
defaultOptions: [],
|
|
4078
|
+
create(context) {
|
|
4079
|
+
return {
|
|
4080
|
+
Property(node) {
|
|
4081
|
+
if (node.key.type === AST_NODE_TYPES.Identifier && node.value.type === AST_NODE_TYPES.Identifier && node.key.name === node.value.name && !node.shorthand) {
|
|
3999
4082
|
context.report({
|
|
4000
4083
|
node,
|
|
4001
|
-
messageId: "
|
|
4084
|
+
messageId: "useShorthand",
|
|
4002
4085
|
data: {
|
|
4003
|
-
source:
|
|
4086
|
+
source: context.sourceCode.getText(node)
|
|
4004
4087
|
},
|
|
4005
4088
|
fix(fixer) {
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
}
|
|
4009
|
-
const fullImportPath = path.resolve(
|
|
4010
|
-
path.dirname(context.physicalFilename),
|
|
4011
|
-
node.source.value
|
|
4012
|
-
);
|
|
4013
|
-
const projectRelativePath = path.relative(
|
|
4014
|
-
context.parserOptions.tsconfigRootDir,
|
|
4015
|
-
fullImportPath
|
|
4016
|
-
);
|
|
4017
|
-
if (projectRelativePath.startsWith("..")) {
|
|
4018
|
-
return null;
|
|
4019
|
-
}
|
|
4020
|
-
return fixer.replaceText(
|
|
4021
|
-
node.source,
|
|
4022
|
-
`${node.source.raw[0]}${path.posix.normalize(projectRelativePath)}${node.source.raw[0]}`
|
|
4023
|
-
);
|
|
4089
|
+
const key = node.key;
|
|
4090
|
+
return fixer.replaceTextRange([node.range[0], node.range[1]], key.name);
|
|
4024
4091
|
}
|
|
4025
4092
|
});
|
|
4026
4093
|
}
|
|
@@ -4028,13 +4095,14 @@ var noRelativeImports = create_rule_default({
|
|
|
4028
4095
|
};
|
|
4029
4096
|
}
|
|
4030
4097
|
});
|
|
4031
|
-
var
|
|
4098
|
+
var use_object_shorthand_default = useObjectShorthand;
|
|
4032
4099
|
|
|
4033
4100
|
// src/rules/index.ts
|
|
4034
4101
|
var rules_default = {
|
|
4035
4102
|
"no-namespace-imports": no_namespace_imports_default,
|
|
4036
4103
|
"no-relative-imports": no_relative_imports_default,
|
|
4037
|
-
"no-plugin-configs-access-from-src-configs": no_plugin_configs_access_from_src_configs_default
|
|
4104
|
+
"no-plugin-configs-access-from-src-configs": no_plugin_configs_access_from_src_configs_default,
|
|
4105
|
+
"use-object-shorthand": use_object_shorthand_default
|
|
4038
4106
|
};
|
|
4039
4107
|
|
|
4040
4108
|
// src/index.ts
|