@o3r/eslint-plugin 10.0.0-next.24 → 10.0.0-next.27
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/eslint-plugin",
|
|
3
|
-
"version": "10.0.0-next.
|
|
3
|
+
"version": "10.0.0-next.27",
|
|
4
4
|
"description": "The module provides in-house eslint plugins to use in your own eslint configuration.",
|
|
5
5
|
"main": "./src/public_api.js",
|
|
6
6
|
"keywords": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@compodoc/compodoc": "^1.1.19",
|
|
56
56
|
"@nx/eslint-plugin": "~16.10.0",
|
|
57
57
|
"@nx/jest": "~16.10.0",
|
|
58
|
-
"@o3r/build-helpers": "^10.0.0-next.
|
|
58
|
+
"@o3r/build-helpers": "^10.0.0-next.27",
|
|
59
59
|
"@types/jest": "~29.5.2",
|
|
60
60
|
"@types/node": "^18.0.0",
|
|
61
61
|
"@types/semver": "^7.3.13",
|
package/src/index.js
CHANGED
|
@@ -5,19 +5,23 @@ const no_folder_import_for_module_1 = require("./rules/typescript/no-folder-impo
|
|
|
5
5
|
const o3r_widget_tags_1 = require("./rules/typescript/o3r-widget-tags/o3r-widget-tags");
|
|
6
6
|
const template_async_number_limitation_1 = require("./rules/template/template-async-number-limitation/template-async-number-limitation");
|
|
7
7
|
const json_dependency_versions_harmonize_1 = require("./rules/json/json-dependency-versions-harmonize/json-dependency-versions-harmonize");
|
|
8
|
+
const matching_configuration_name_1 = require("./rules/typescript/matching-configuration-name/matching-configuration-name");
|
|
8
9
|
module.exports = {
|
|
9
10
|
rules: {
|
|
10
11
|
'no-folder-import-for-module': no_folder_import_for_module_1.default,
|
|
11
12
|
'template-async-number-limitation': template_async_number_limitation_1.default,
|
|
12
13
|
'o3r-widget-tags': o3r_widget_tags_1.default,
|
|
13
|
-
'json-dependency-versions-harmonize': json_dependency_versions_harmonize_1.default
|
|
14
|
+
'json-dependency-versions-harmonize': json_dependency_versions_harmonize_1.default,
|
|
15
|
+
'matching-configuration-name': matching_configuration_name_1.default
|
|
14
16
|
},
|
|
15
17
|
configs: {
|
|
16
18
|
'@o3r/no-folder-import-for-module': 'error',
|
|
17
19
|
'@o3r/json-dependency-versions-harmonize': 'error',
|
|
18
20
|
'@o3r/template-async-number-limitation': 'warn',
|
|
21
|
+
'@o3r/matching-configuration-name': 'warn',
|
|
19
22
|
recommended: {
|
|
20
23
|
rules: {
|
|
24
|
+
'@o3r/matching-configuration-name': 'error',
|
|
21
25
|
'@o3r/no-folder-import-for-module': 'error',
|
|
22
26
|
'@o3r/template-async-number-limitation': 'off'
|
|
23
27
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/experimental-utils';
|
|
2
|
+
declare const _default: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"suggestion" | "error", never[], {
|
|
3
|
+
CallExpression: (node: TSESTree.CallExpression) => void;
|
|
4
|
+
}>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
exports.default = (0, utils_1.createRule)({
|
|
6
|
+
name: 'matching-configuration-name',
|
|
7
|
+
meta: {
|
|
8
|
+
hasSuggestions: true,
|
|
9
|
+
fixable: 'code',
|
|
10
|
+
type: 'problem',
|
|
11
|
+
docs: {
|
|
12
|
+
// eslint-disable-next-line max-len
|
|
13
|
+
description: 'Ensures that the configuration interface name matches the first parameter of `computeConfigurationName` used beside the configuration interface to expose its ID (as generated by the configuration module).',
|
|
14
|
+
recommended: 'error'
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: {
|
|
18
|
+
error: '{{currentValue}} does not match: {{possibleValues}}',
|
|
19
|
+
suggestion: 'Replace {{currentValue}} by {{recommendedValue}}'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create: (context) => {
|
|
24
|
+
return {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
26
|
+
CallExpression: (node) => {
|
|
27
|
+
if (node.callee.type !== experimental_utils_1.TSESTree.AST_NODE_TYPES.Identifier
|
|
28
|
+
|| node.callee.name !== 'computeConfigurationName'
|
|
29
|
+
|| !node.arguments.length
|
|
30
|
+
|| node.arguments[0].type !== experimental_utils_1.TSESTree.AST_NODE_TYPES.Literal
|
|
31
|
+
|| typeof node.arguments[0].value !== 'string') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const sourceCode = context.getSourceCode();
|
|
35
|
+
const interfaceNames = sourceCode.ast.body
|
|
36
|
+
.filter((statement) => statement.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration
|
|
37
|
+
&& statement.declaration?.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.TSInterfaceDeclaration
|
|
38
|
+
&& (statement.declaration.extends || []).some((heritageClause) => heritageClause.expression.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.Identifier
|
|
39
|
+
&& heritageClause.expression.name === 'Configuration'))
|
|
40
|
+
.map((statement) => statement.declaration.id.name);
|
|
41
|
+
const fnArgInterfaceName = node.arguments[0].value;
|
|
42
|
+
if (interfaceNames.length && !interfaceNames.includes(fnArgInterfaceName)) {
|
|
43
|
+
return context.report({
|
|
44
|
+
node: node.arguments[0],
|
|
45
|
+
loc: node.arguments[0].loc,
|
|
46
|
+
messageId: 'error',
|
|
47
|
+
data: {
|
|
48
|
+
currentValue: fnArgInterfaceName,
|
|
49
|
+
possibleValues: interfaceNames.join(', ')
|
|
50
|
+
},
|
|
51
|
+
fix: (fixer) => {
|
|
52
|
+
return fixer.replaceText(node.arguments[0], `'${interfaceNames[0]}'`);
|
|
53
|
+
},
|
|
54
|
+
suggest: interfaceNames.map((interfaceName) => ({
|
|
55
|
+
messageId: 'suggestion',
|
|
56
|
+
data: {
|
|
57
|
+
currentValue: fnArgInterfaceName,
|
|
58
|
+
recommendedValue: interfaceName
|
|
59
|
+
},
|
|
60
|
+
fix: (fixer) => {
|
|
61
|
+
return fixer.replaceText(node.arguments[0], `'${interfaceName}'`);
|
|
62
|
+
}
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|