@o3r/eslint-plugin 11.6.0-prerelease.24 → 11.6.0-prerelease.26

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/eslint-plugin",
3
- "version": "11.6.0-prerelease.24",
3
+ "version": "11.6.0-prerelease.26",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -65,9 +65,9 @@
65
65
  "@eslint/eslintrc": "^3.0.0",
66
66
  "@nx/eslint-plugin": "~19.5.0",
67
67
  "@nx/jest": "~19.5.0",
68
- "@o3r/build-helpers": "^11.6.0-prerelease.24",
69
- "@o3r/eslint-config": "^11.6.0-prerelease.24",
70
- "@o3r/test-helpers": "^11.6.0-prerelease.24",
68
+ "@o3r/build-helpers": "^11.6.0-prerelease.26",
69
+ "@o3r/eslint-config": "^11.6.0-prerelease.26",
70
+ "@o3r/test-helpers": "^11.6.0-prerelease.26",
71
71
  "@stylistic/eslint-plugin": "~2.7.0",
72
72
  "@types/eslint": "~9.6.0",
73
73
  "@types/jest": "~29.5.2",
package/src/index.js CHANGED
@@ -37,17 +37,30 @@ module.exports = {
37
37
  '@o3r/template-async-number-limitation': 'off'
38
38
  }
39
39
  },
40
+ // deprecated: should use `angular-template-recommended` instead. Will be removed in v13.
40
41
  'template-recommended': {
41
42
  rules: {
42
43
  '@o3r/no-folder-import-for-module': 'error',
43
44
  '@o3r/template-async-number-limitation': 'warn'
44
45
  }
45
46
  },
47
+ // deprecated: should use `monorepo-recommended` instead. Will be removed in v13.
46
48
  'json-recommended': {
47
49
  rules: {
48
50
  '@o3r/json-dependency-versions-harmonize': 'error'
49
51
  }
50
52
  },
53
+ 'angular-template-recommended': {
54
+ rules: {
55
+ '@o3r/no-inner-html': 'off',
56
+ '@o3r/template-async-number-limitation': 'error'
57
+ }
58
+ },
59
+ 'monorepo-recommended': {
60
+ rules: {
61
+ '@o3r/json-dependency-versions-harmonize': 'error'
62
+ }
63
+ },
51
64
  'yarn-recommended': {
52
65
  rules: {
53
66
  '@o3r/yarnrc-package-extensions-harmonize': 'error'
@@ -2,10 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("node:path");
4
4
  const semver = require("semver");
5
- const yaml_eslint_parser_1 = require("yaml-eslint-parser");
6
5
  const version_harmonize_1 = require("../../json/json-dependency-versions-harmonize/version-harmonize");
7
6
  const utils_1 = require("../../utils");
8
7
  const utils_2 = require("../utils");
8
+ const isYAMLScalar = (node) => node?.type === 'YAMLScalar';
9
+ const getStaticYAMLValue = (node) => {
10
+ return isYAMLScalar(node)
11
+ ? node.value?.toString()
12
+ : undefined;
13
+ };
9
14
  const defaultOptions = [{
10
15
  ignoredDependencies: [],
11
16
  excludePackages: [],
@@ -74,48 +79,48 @@ exports.default = (0, utils_1.createRule)({
74
79
  : {};
75
80
  const ignoredDependencies = options.ignoredDependencies.map((dep) => new RegExp(dep.replace(/[$()+.?[\\\]^{|}]/g, '\\$&').replace(/\*/g, '.*')));
76
81
  if (parserServices.isYAML) {
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
- });
82
+ return {
83
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- name required by Yaml Eslint parser
84
+ YAMLPair: (node) => {
85
+ if (node.value) {
86
+ const range = getStaticYAMLValue(node.value)?.toString();
87
+ const parent = node.parent.parent && node.parent.parent.type === 'YAMLPair' && getStaticYAMLValue(node.parent.parent.key)?.toString();
88
+ const baseNode = node.parent.parent.parent.parent?.parent?.parent;
89
+ const isCorrectNode = baseNode && baseNode.type === 'YAMLPair' && getStaticYAMLValue(baseNode.key)?.toString() === 'packageExtensions';
90
+ if (isCorrectNode && semver.validRange(range) && parent && options.yarnrcDependencyTypes.includes(parent)) {
91
+ const depName = node.key && getStaticYAMLValue(node.key)?.toString();
92
+ if (!depName || !bestRanges[depName] || ignoredDependencies.some((ignore) => ignore.test(depName))) {
93
+ return;
94
+ }
95
+ const minYarnrcVersion = semver.minVersion(range);
96
+ const minBestRangeVersion = semver.minVersion(bestRanges[depName].range);
97
+ if (minYarnrcVersion && minBestRangeVersion && semver.lt(minYarnrcVersion, minBestRangeVersion)) {
98
+ const version = bestRanges[depName].range;
99
+ const packageJsonFile = bestRanges[depName].path;
100
+ context.report({
101
+ loc: node.value.loc,
102
+ messageId: 'error',
103
+ data: {
104
+ depName,
105
+ version,
106
+ packageJsonFile
107
+ },
108
+ fix: (fixer) => fixer.replaceTextRange(node.value.range, `${version}`),
109
+ suggest: [
110
+ {
111
+ messageId: 'versionUpdate',
112
+ data: {
113
+ version
114
+ },
115
+ fix: (fixer) => fixer.replaceTextRange(node.value.range, `${version}`)
116
+ }
117
+ ]
118
+ });
119
+ }
112
120
  }
113
121
  }
114
122
  }
115
123
  };
116
- return {
117
- YAMLPair: rule
118
- };
119
124
  }
120
125
  return {};
121
126
  }