@o3r/eslint-plugin 11.6.0-prerelease.6 → 11.6.0-prerelease.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. package/package.json +22 -21
  2. package/schematics/ng-add/index.d.ts.map +1 -1
  3. package/src/index.js +4 -5
  4. package/src/public_api.d.ts +3 -0
  5. package/src/public_api.js +1 -0
  6. package/src/rules/json/json-dependency-versions-harmonize/json-dependency-versions-harmonize.d.ts +3 -2
  7. package/src/rules/json/json-dependency-versions-harmonize/json-dependency-versions-harmonize.js +60 -60
  8. package/src/rules/json/json-dependency-versions-harmonize/version-harmonize.js +1 -1
  9. package/src/rules/json/utils.js +2 -2
  10. package/src/rules/template/no-inner-html/no-inner-html.d.ts +1 -1
  11. package/src/rules/template/no-inner-html/no-inner-html.js +30 -31
  12. package/src/rules/template/template-async-number-limitation/template-async-number-limitation.d.ts +2 -2
  13. package/src/rules/template/template-async-number-limitation/template-async-number-limitation.js +24 -24
  14. package/src/rules/template/utils.js +3 -3
  15. package/src/rules/typescript/matching-configuration-name/matching-configuration-name.d.ts +1 -1
  16. package/src/rules/typescript/matching-configuration-name/matching-configuration-name.js +40 -40
  17. package/src/rules/typescript/no-folder-import-for-module/no-folder-import-for-module.d.ts +1 -1
  18. package/src/rules/typescript/no-folder-import-for-module/no-folder-import-for-module.js +28 -24
  19. package/src/rules/typescript/no-multiple-type-configuration-property/no-multiple-type-configuration-property.d.ts +1 -1
  20. package/src/rules/typescript/no-multiple-type-configuration-property/no-multiple-type-configuration-property.js +3 -5
  21. package/src/rules/typescript/o3r-categories-tags/o3r-categories-tags.d.ts +1 -1
  22. package/src/rules/typescript/o3r-categories-tags/o3r-categories-tags.js +82 -82
  23. package/src/rules/typescript/o3r-widget-tags/o3r-widget-tags.d.ts +1 -1
  24. package/src/rules/typescript/o3r-widget-tags/o3r-widget-tags.js +142 -142
  25. package/src/rules/utils.d.ts +1 -1
  26. package/src/rules/utils.js +4 -7
  27. package/src/rules/yaml/utils.js +2 -2
  28. package/src/rules/yaml/yarnrc-package-extensions-harmonize/yarnrc-package-extensions-harmonize.d.ts +2 -2
  29. package/src/rules/yaml/yarnrc-package-extensions-harmonize/yarnrc-package-extensions-harmonize.js +45 -45
@@ -72,184 +72,184 @@ exports.default = (0, utils_1.createRule)({
72
72
  defaultOptions,
73
73
  create: (context, [options]) => {
74
74
  const supportedO3rWidgets = new Set(Object.keys(options.widgets));
75
- return {
76
- // eslint-disable-next-line @typescript-eslint/naming-convention
77
- TSPropertySignature: (node) => {
78
- const sourceCode = context.getSourceCode();
79
- const comment = (0, utils_1.getNodeComment)(node, sourceCode);
80
- if (!comment || !comment.value.length) {
81
- return;
82
- }
83
- const { loc, value: docText } = comment;
84
- const widgetTypes = Array.from(docText.matchAll(/@o3rWidget (.*)/g));
85
- if (widgetTypes.length > 1) {
75
+ const rule = (node) => {
76
+ const { sourceCode } = context;
77
+ const comment = (0, utils_1.getNodeComment)(node, sourceCode);
78
+ if (!comment || comment.value.length === 0) {
79
+ return;
80
+ }
81
+ const { loc, value: docText } = comment;
82
+ const widgetTypes = Array.from(docText.matchAll(/@o3rWidget (.*)/g));
83
+ if (widgetTypes.length > 1) {
84
+ const fix = (fixer) => {
85
+ return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/(.*(@o3rWidget ).*(\n.*)*)(\n.*)\2.*/, '$1')));
86
+ };
87
+ return context.report({
88
+ messageId: 'onlyOneWidgetAllowed',
89
+ node,
90
+ loc,
91
+ fix,
92
+ suggest: [{
93
+ messageId: 'suggestRemoveDuplicatedO3rWidget',
94
+ fix
95
+ }]
96
+ });
97
+ }
98
+ const widgetType = widgetTypes[0]?.[1].trim();
99
+ const widgetParameterTexts = Array.from(docText.matchAll(/@o3rWidgetParam (.*)/g))
100
+ .map((match) => match[1].trim());
101
+ if (!widgetType) {
102
+ if (widgetParameterTexts.length > 0) {
86
103
  const fix = (fixer) => {
87
- return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/(.*(@o3rWidget ).*(\n.*)*)(\n.*)\2.*/, '$1')));
104
+ return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/((.*)@o3rWidgetParam .*)/, '$2@o3rWidget widgetType\n$1')));
88
105
  };
89
106
  return context.report({
90
- messageId: 'onlyOneWidgetAllowed',
107
+ messageId: 'noParamWithoutWidget',
91
108
  node,
92
109
  loc,
93
110
  fix,
94
111
  suggest: [{
95
- messageId: 'suggestRemoveDuplicatedO3rWidget',
112
+ messageId: 'suggestAddO3rWidgetTag',
96
113
  fix
97
114
  }]
98
115
  });
99
116
  }
100
- const widgetType = widgetTypes[0]?.[1].trim();
101
- const widgetParameterTexts = Array.from(docText.matchAll(/@o3rWidgetParam (.*)/g))
102
- .map((match) => match[1].trim());
103
- if (!widgetType) {
104
- if (widgetParameterTexts.length) {
105
- const fix = (fixer) => {
106
- return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/((.*)@o3rWidgetParam .*)/, '$2@o3rWidget widgetType\n$1')));
107
- };
108
- return context.report({
109
- messageId: 'noParamWithoutWidget',
110
- node,
111
- loc,
112
- fix,
113
- suggest: [{
114
- messageId: 'suggestAddO3rWidgetTag',
115
- fix
116
- }]
117
- });
118
- }
119
- return;
120
- }
121
- const interfaceDeclNode = node.parent?.parent;
122
- if (!(0, utils_1.isExtendingConfiguration)(interfaceDeclNode, options.supportedInterfaceNames)) {
117
+ return;
118
+ }
119
+ const interfaceDeclNode = node.parent?.parent;
120
+ if (!(0, utils_1.isExtendingConfiguration)(interfaceDeclNode, options.supportedInterfaceNames)) {
121
+ return context.report({
122
+ messageId: 'notInConfigurationInterface',
123
+ node,
124
+ loc
125
+ });
126
+ }
127
+ if (!supportedO3rWidgets.has(widgetType)) {
128
+ return context.report({
129
+ messageId: 'notSupportedType',
130
+ node,
131
+ loc,
132
+ data: {
133
+ o3rWidgetType: widgetType,
134
+ supportedO3rWidgets: Array.from(supportedO3rWidgets).join(', ')
135
+ },
136
+ suggest: Array.from(supportedO3rWidgets).map((suggestedWidget) => ({
137
+ messageId: 'suggestReplaceO3rWidgetType',
138
+ data: {
139
+ currentType: widgetType,
140
+ suggestedType: suggestedWidget
141
+ },
142
+ fix: (fixer) => {
143
+ return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(`@o3rWidget ${widgetType}`, `@o3rWidget ${suggestedWidget}`)));
144
+ }
145
+ }))
146
+ });
147
+ }
148
+ const widgetParameters = widgetParameterTexts.map((text) => {
149
+ const [name, ...values] = text.split(' ');
150
+ return {
151
+ name,
152
+ textValue: values.join(' ')
153
+ };
154
+ });
155
+ const widgetParameterNames = widgetParameters.map(({ name }) => name);
156
+ const supportedO3rWidgetParam = new Set(Object.keys(options.widgets[widgetType]));
157
+ const checkedParam = new Set();
158
+ for (const widgetParameterName of widgetParameterNames) {
159
+ if (checkedParam.has(widgetParameterName)) {
160
+ const fix = (fixer) => {
161
+ return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/(.*(@o3rWidgetParam ).*(\n.*)*)(\n.*)\2.*/m, '$1')));
162
+ };
123
163
  return context.report({
124
- messageId: 'notInConfigurationInterface',
164
+ messageId: 'duplicatedParam',
125
165
  node,
126
- loc
166
+ loc,
167
+ data: {
168
+ o3rWidgetParam: widgetParameterName
169
+ },
170
+ fix,
171
+ suggest: [{
172
+ messageId: 'suggestRemoveDuplicatedO3rWidgetParam',
173
+ fix
174
+ }]
127
175
  });
128
176
  }
129
- if (!supportedO3rWidgets.has(widgetType)) {
177
+ if (!supportedO3rWidgetParam.has(widgetParameterName)) {
130
178
  return context.report({
131
- messageId: 'notSupportedType',
179
+ messageId: 'notSupportedParamForType',
132
180
  node,
133
181
  loc,
134
182
  data: {
183
+ o3rWidgetParam: widgetParameterName,
135
184
  o3rWidgetType: widgetType,
136
- supportedO3rWidgets: Array.from(supportedO3rWidgets).join(', ')
185
+ supportedO3rWidgetParam: Array.from(supportedO3rWidgetParam).join(', ')
137
186
  },
138
- suggest: Array.from(supportedO3rWidgets).map((suggestedWidget) => ({
187
+ suggest: Array.from(supportedO3rWidgetParam).map((suggestedParam) => ({
139
188
  messageId: 'suggestReplaceO3rWidgetType',
140
189
  data: {
141
- currentType: widgetType,
142
- suggestedType: suggestedWidget
190
+ currentType: widgetParameterName,
191
+ suggestedType: suggestedParam
143
192
  },
144
193
  fix: (fixer) => {
145
- return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(`@o3rWidget ${widgetType}`, `@o3rWidget ${suggestedWidget}`)));
194
+ return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(`@o3rWidgetParam ${widgetParameterName}`, `@o3rWidgetParam ${suggestedParam}`)));
146
195
  }
147
196
  }))
148
197
  });
149
198
  }
150
- const widgetParameters = widgetParameterTexts.map((text) => {
151
- const [name, ...values] = text.split(' ');
152
- return {
153
- name,
154
- textValue: values.join(' ')
155
- };
156
- });
157
- const widgetParameterNames = widgetParameters.map(({ name }) => name);
158
- const supportedO3rWidgetParam = new Set(Object.keys(options.widgets[widgetType]));
159
- const checkedParam = new Set();
160
- for (const widgetParameterName of widgetParameterNames) {
161
- if (checkedParam.has(widgetParameterName)) {
162
- const fix = (fixer) => {
163
- return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/(.*(@o3rWidgetParam ).*(\n.*)*)(\n.*)\2.*/m, '$1')));
164
- };
165
- return context.report({
166
- messageId: 'duplicatedParam',
167
- node,
168
- loc,
169
- data: {
170
- o3rWidgetParam: widgetParameterName
171
- },
172
- fix,
173
- suggest: [{
174
- messageId: 'suggestRemoveDuplicatedO3rWidget',
175
- fix
176
- }]
177
- });
178
- }
179
- if (!supportedO3rWidgetParam.has(widgetParameterName)) {
180
- return context.report({
181
- messageId: 'notSupportedParamForType',
182
- node,
183
- loc,
199
+ checkedParam.add(widgetParameterName);
200
+ }
201
+ const firstRequiredParam = Object.entries(options.widgets[widgetType]).find(([param, { required }]) => required && !checkedParam.has(param));
202
+ if (firstRequiredParam) {
203
+ const [firstRequiredParamName] = firstRequiredParam;
204
+ const fix = (fixer) => {
205
+ return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/((.*)@o3rWidget (.*))/, `$1\n$2@o3rWidgetParam ${firstRequiredParamName} value`)));
206
+ };
207
+ return context.report({
208
+ messageId: 'requiredParamMissing',
209
+ node,
210
+ loc,
211
+ data: {
212
+ o3rWidgetParam: firstRequiredParamName,
213
+ o3rWidgetType: widgetType
214
+ },
215
+ fix,
216
+ suggest: [{
217
+ messageId: 'suggestParamMissing',
184
218
  data: {
185
- o3rWidgetParam: widgetParameterName,
186
- o3rWidgetType: widgetType,
187
- supportedO3rWidgetParam: Array.from(supportedO3rWidgetParam).join(', ')
219
+ o3rWidgetParam: firstRequiredParamName
188
220
  },
189
- suggest: Array.from(supportedO3rWidgetParam).map((suggestedParam) => ({
190
- messageId: 'suggestReplaceO3rWidgetType',
191
- data: {
192
- currentType: widgetType,
193
- suggestedType: suggestedParam
194
- },
195
- fix: (fixer) => {
196
- return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(`@o3rWidgetParam ${widgetType}`, `@o3rWidgetParam ${suggestedParam}`)));
197
- }
198
- }))
199
- });
200
- }
201
- checkedParam.add(widgetParameterName);
202
- }
203
- const firstRequiredParam = Object.entries(options.widgets[widgetType]).find(([param, { required }]) => required && !checkedParam.has(param));
204
- if (firstRequiredParam) {
205
- const [firstRequiredParamName] = firstRequiredParam;
206
- const fix = (fixer) => {
207
- return fixer.replaceTextRange(comment.range, (0, utils_1.createCommentString)(comment.value.replace(/((.*)@o3rWidget (.*))/, `$1\n$2@o3rWidgetParam ${firstRequiredParamName} value`)));
208
- };
209
- return context.report({
210
- messageId: 'requiredParamMissing',
211
- node,
212
- loc,
213
- data: {
214
- o3rWidgetParam: firstRequiredParamName,
215
- o3rWidgetType: widgetType
216
- },
217
- fix,
218
- suggest: [{
219
- messageId: 'suggestParamMissing',
220
- data: {
221
- o3rWidgetParam: firstRequiredParamName
222
- },
223
- fix
224
- }]
225
- });
226
- }
227
- for (const widgetParameter of widgetParameters) {
228
- const { name, textValue } = widgetParameter;
229
- const supportedTypeForParam = options.widgets[widgetType][name];
230
- try {
231
- const value = JSON.parse(textValue);
232
- if (supportedTypeForParam.type.endsWith('[]')) {
233
- if (Array.isArray(value) && value.every((element) => typeof element === supportedTypeForParam.type.substring(0, -2))) {
234
- continue;
235
- }
236
- }
237
- else if (typeof value === supportedTypeForParam.type) {
221
+ fix
222
+ }]
223
+ });
224
+ }
225
+ for (const widgetParameter of widgetParameters) {
226
+ const { name, textValue } = widgetParameter;
227
+ const supportedTypeForParam = options.widgets[widgetType][name];
228
+ try {
229
+ const value = JSON.parse(textValue);
230
+ if (supportedTypeForParam.type.endsWith('[]')) {
231
+ if (Array.isArray(value) && value.every((element) => typeof element === supportedTypeForParam.type.substring(0, -2))) {
238
232
  continue;
239
233
  }
240
234
  }
241
- catch { }
242
- return context.report({
243
- messageId: 'invalidParamValueType',
244
- node,
245
- loc,
246
- data: {
247
- o3rWidgetParam: name,
248
- o3rWidgetParamType: supportedTypeForParam.type
249
- }
250
- });
235
+ else if (typeof value === supportedTypeForParam.type) {
236
+ continue;
237
+ }
251
238
  }
239
+ catch { }
240
+ return context.report({
241
+ messageId: 'invalidParamValueType',
242
+ node,
243
+ loc,
244
+ data: {
245
+ o3rWidgetParam: name,
246
+ o3rWidgetParamType: supportedTypeForParam.type
247
+ }
248
+ });
252
249
  }
253
250
  };
251
+ return {
252
+ TSPropertySignature: rule
253
+ };
254
254
  }
255
255
  });
@@ -1,6 +1,6 @@
1
1
  import { ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
2
2
  /** ESLint rule generator */
3
- export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds>>) => ESLintUtils.RuleModule<MessageIds, Options>;
3
+ export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
4
4
  /** Default supported interface names */
5
5
  export declare const defaultSupportedInterfaceNames: string[];
6
6
  /**
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCommentString = exports.getNodeComment = exports.isExtendingConfiguration = exports.defaultSupportedInterfaceNames = exports.createRule = void 0;
4
- const utils_1 = require("@typescript-eslint/utils");
5
4
  const node_fs_1 = require("node:fs");
6
5
  const path = require("node:path");
6
+ const utils_1 = require("@typescript-eslint/utils");
7
7
  /** Current package version (format: <major>.<minor>)*/
8
- const version = JSON.parse((0, node_fs_1.readFileSync)(path.resolve(__dirname, '..', '..', 'package.json'), { encoding: 'utf-8' })).version?.split('.').slice(0, 2).join('.') || '0.0';
8
+ const version = JSON.parse((0, node_fs_1.readFileSync)(path.resolve(__dirname, '..', '..', 'package.json'), { encoding: 'utf8' })).version?.split('.').slice(0, 2).join('.') || '0.0';
9
9
  /** ESLint rule generator */
10
- // eslint-disable-next-line new-cap
10
+ // eslint-disable-next-line new-cap -- naming convention imposed by typescript-eslint
11
11
  exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => {
12
- if (version === '0.0') {
13
- return 'file:' + path.resolve(__dirname, '..', '..', '..', '..', '..', 'docs', 'linter', 'eslint-plugin', 'rules', `${name}.md`);
14
- }
15
- return `https://github.com/AmadeusITGroup/otter/tree/release/${version}/docs/linter/eslint-plugin/rules/${name}.md`;
12
+ return `https://github.com/AmadeusITGroup/otter/tree/release/${version === '0.0' ? 'main' : version}/docs/linter/eslint-plugin/rules/${name}.md`;
16
13
  });
17
14
  /** Default supported interface names */
18
15
  exports.defaultSupportedInterfaceNames = ['Configuration', 'NestedConfiguration'];
@@ -15,7 +15,7 @@ function isYamlParserServices(parserServices) {
15
15
  * @param context Rule context
16
16
  */
17
17
  function getYamlParserServices(context) {
18
- const parserService = context.parserServices;
18
+ const parserService = context.sourceCode.parserServices;
19
19
  if (!isYamlParserServices(parserService)) {
20
20
  /*
21
21
  * The user needs to have configured "parser" in their eslint config and set it
@@ -31,7 +31,7 @@ function getYamlParserServices(context) {
31
31
  * @param context
32
32
  */
33
33
  function ensureJsoncParser(context) {
34
- if (!(context.parserServices)) {
34
+ if (!(context.sourceCode.parserServices)) {
35
35
  /*
36
36
  * The user needs to have configured "parser" in their eslint config and set it
37
37
  * to yaml-eslint-parser
@@ -1,4 +1,4 @@
1
- interface Options {
1
+ export interface YarnrcPackageExtensionsHarmonizeOptions {
2
2
  /** List of package.json to ignore when determining the dependencies versions */
3
3
  excludePackages: string[];
4
4
  /** List of dependency types in package.json to parse */
@@ -8,5 +8,5 @@ interface Options {
8
8
  /** List of dependency types to validate in .yarnrc.yml */
9
9
  yarnrcDependencyTypes: string[];
10
10
  }
11
- declare const _default: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"error" | "versionUpdate", [Options, ...any[]], import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
11
+ declare const _default: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"error" | "versionUpdate", [YarnrcPackageExtensionsHarmonizeOptions, ...any[]], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
12
12
  export default _default;
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("node:path");
4
4
  const semver = require("semver");
5
- const utils_1 = require("../../utils");
6
- const utils_2 = require("../utils");
7
5
  const yaml_eslint_parser_1 = require("yaml-eslint-parser");
8
6
  const version_harmonize_1 = require("../../json/json-dependency-versions-harmonize/version-harmonize");
7
+ const utils_1 = require("../../utils");
8
+ const utils_2 = require("../utils");
9
9
  const defaultOptions = [{
10
10
  ignoredDependencies: [],
11
11
  excludePackages: [],
@@ -67,55 +67,55 @@ exports.default = (0, utils_1.createRule)({
67
67
  defaultOptions,
68
68
  create: (context, [options]) => {
69
69
  const parserServices = (0, utils_2.getYamlParserServices)(context);
70
- const dirname = path.dirname(context.getFilename());
70
+ const dirname = path.dirname(context.filename);
71
71
  const workspace = (0, version_harmonize_1.findWorkspacePackageJsons)(dirname);
72
- const bestRanges = workspace ?
73
- (0, version_harmonize_1.getBestRanges)(options.dependencyTypesInPackages, workspace.packages.filter(({ content }) => !content.name || !options.excludePackages.includes(content.name))) :
74
- {};
75
- const ignoredDependencies = options.ignoredDependencies.map((dep) => new RegExp(dep.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')));
72
+ const bestRanges = workspace
73
+ ? (0, version_harmonize_1.getBestRanges)(options.dependencyTypesInPackages, workspace.packages.filter(({ content }) => !content.name || !options.excludePackages.includes(content.name)))
74
+ : {};
75
+ const ignoredDependencies = options.ignoredDependencies.map((dep) => new RegExp(dep.replace(/[$()+.?[\\\]^{|}]/g, '\\$&').replace(/\*/g, '.*')));
76
76
  if (parserServices.isYAML) {
77
- return {
78
- // eslint-disable-next-line @typescript-eslint/naming-convention
79
- 'YAMLPair': (node) => {
80
- if (node.value) {
81
- const range = (0, yaml_eslint_parser_1.getStaticYAMLValue)(node.value)?.toString();
82
- const parent = node.parent.parent && node.parent.parent.type === 'YAMLPair' && (0, yaml_eslint_parser_1.getStaticYAMLValue)(node.parent.parent.key)?.toString();
83
- const baseNode = node.parent.parent.parent.parent?.parent?.parent;
84
- const isCorrectNode = baseNode && baseNode.type === 'YAMLPair' && (0, yaml_eslint_parser_1.getStaticYAMLValue)(baseNode.key)?.toString() === 'packageExtensions';
85
- if (isCorrectNode && semver.validRange(range) && parent && options.yarnrcDependencyTypes.some((t) => t === parent)) {
86
- const depName = node.key && (0, yaml_eslint_parser_1.getStaticYAMLValue)(node.key)?.toString();
87
- if (!depName || !bestRanges[depName] || ignoredDependencies.some((ignore) => ignore.test(depName))) {
88
- return;
89
- }
90
- const minYarnrcVersion = semver.minVersion(range);
91
- const minBestRangeVersion = semver.minVersion(bestRanges[depName].range);
92
- if (minYarnrcVersion && minBestRangeVersion && semver.lt(minYarnrcVersion, minBestRangeVersion)) {
93
- const version = bestRanges[depName].range;
94
- const packageJsonFile = bestRanges[depName].path;
95
- context.report({
96
- loc: node.value.loc,
97
- messageId: 'error',
98
- data: {
99
- depName,
100
- version,
101
- packageJsonFile
102
- },
103
- fix: (fixer) => fixer.replaceTextRange(node.value.range, `${version}`),
104
- suggest: [
105
- {
106
- messageId: 'versionUpdate',
107
- data: {
108
- version
109
- },
110
- fix: (fixer) => fixer.replaceTextRange(node.value.range, `${version}`)
111
- }
112
- ]
113
- });
114
- }
77
+ const rule = (node) => {
78
+ if (node.value) {
79
+ const range = (0, yaml_eslint_parser_1.getStaticYAMLValue)(node.value)?.toString();
80
+ const parent = node.parent.parent && node.parent.parent.type === 'YAMLPair' && (0, yaml_eslint_parser_1.getStaticYAMLValue)(node.parent.parent.key)?.toString();
81
+ const baseNode = node.parent.parent.parent.parent?.parent?.parent;
82
+ const isCorrectNode = baseNode && baseNode.type === 'YAMLPair' && (0, yaml_eslint_parser_1.getStaticYAMLValue)(baseNode.key)?.toString() === 'packageExtensions';
83
+ if (isCorrectNode && semver.validRange(range) && parent && options.yarnrcDependencyTypes.includes(parent)) {
84
+ const depName = node.key && (0, yaml_eslint_parser_1.getStaticYAMLValue)(node.key)?.toString();
85
+ if (!depName || !bestRanges[depName] || ignoredDependencies.some((ignore) => ignore.test(depName))) {
86
+ return;
87
+ }
88
+ const minYarnrcVersion = semver.minVersion(range);
89
+ const minBestRangeVersion = semver.minVersion(bestRanges[depName].range);
90
+ if (minYarnrcVersion && minBestRangeVersion && semver.lt(minYarnrcVersion, minBestRangeVersion)) {
91
+ const version = bestRanges[depName].range;
92
+ const packageJsonFile = bestRanges[depName].path;
93
+ context.report({
94
+ loc: node.value.loc,
95
+ messageId: 'error',
96
+ data: {
97
+ depName,
98
+ version,
99
+ packageJsonFile
100
+ },
101
+ fix: (fixer) => fixer.replaceTextRange(node.value.range, `${version}`),
102
+ suggest: [
103
+ {
104
+ messageId: 'versionUpdate',
105
+ data: {
106
+ version
107
+ },
108
+ fix: (fixer) => fixer.replaceTextRange(node.value.range, `${version}`)
109
+ }
110
+ ]
111
+ });
115
112
  }
116
113
  }
117
114
  }
118
115
  };
116
+ return {
117
+ YAMLPair: rule
118
+ };
119
119
  }
120
120
  return {};
121
121
  }