oxlint-plugin-eslint 1.52.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.
Files changed (305) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +36 -0
  3. package/common/ast-utils.cjs +5843 -0
  4. package/common/chunk.cjs +9 -0
  5. package/common/eslint-utils.cjs +1633 -0
  6. package/common/fix-tracker.cjs +89 -0
  7. package/common/ignore.cjs +123 -0
  8. package/common/keywords.cjs +15 -0
  9. package/common/regexpp.cjs +1720 -0
  10. package/common/regular-expressions.cjs +40 -0
  11. package/common/string-utils.cjs +39 -0
  12. package/index.js +7477 -0
  13. package/package.json +34 -0
  14. package/rules/accessor-pairs.cjs +233 -0
  15. package/rules/array-bracket-newline.cjs +172 -0
  16. package/rules/array-bracket-spacing.cjs +184 -0
  17. package/rules/array-callback-return.cjs +262 -0
  18. package/rules/array-element-newline.cjs +178 -0
  19. package/rules/arrow-body-style.cjs +135 -0
  20. package/rules/arrow-parens.cjs +130 -0
  21. package/rules/arrow-spacing.cjs +129 -0
  22. package/rules/block-scoped-var.cjs +101 -0
  23. package/rules/block-spacing.cjs +125 -0
  24. package/rules/brace-style.cjs +141 -0
  25. package/rules/callback-return.cjs +117 -0
  26. package/rules/camelcase.cjs +194 -0
  27. package/rules/capitalized-comments.cjs +168 -0
  28. package/rules/class-methods-use-this.cjs +155 -0
  29. package/rules/comma-dangle.cjs +274 -0
  30. package/rules/comma-spacing.cjs +111 -0
  31. package/rules/comma-style.cjs +180 -0
  32. package/rules/complexity.cjs +100 -0
  33. package/rules/computed-property-spacing.cjs +155 -0
  34. package/rules/consistent-return.cjs +113 -0
  35. package/rules/consistent-this.cjs +109 -0
  36. package/rules/constructor-super.cjs +207 -0
  37. package/rules/curly.cjs +173 -0
  38. package/rules/default-case-last.cjs +36 -0
  39. package/rules/default-case.cjs +50 -0
  40. package/rules/default-param-last.cjs +61 -0
  41. package/rules/dot-location.cjs +87 -0
  42. package/rules/dot-notation.cjs +77 -0
  43. package/rules/eol-last.cjs +91 -0
  44. package/rules/eqeqeq.cjs +127 -0
  45. package/rules/for-direction.cjs +94 -0
  46. package/rules/func-call-spacing.cjs +127 -0
  47. package/rules/func-name-matching.cjs +138 -0
  48. package/rules/func-names.cjs +121 -0
  49. package/rules/func-style.cjs +103 -0
  50. package/rules/function-call-argument-newline.cjs +109 -0
  51. package/rules/function-paren-newline.cjs +173 -0
  52. package/rules/generator-star-spacing.cjs +174 -0
  53. package/rules/getter-return.cjs +129 -0
  54. package/rules/global-require.cjs +84 -0
  55. package/rules/grouped-accessor-pairs.cjs +146 -0
  56. package/rules/guard-for-in.cjs +39 -0
  57. package/rules/handle-callback-err.cjs +86 -0
  58. package/rules/id-blacklist.cjs +135 -0
  59. package/rules/id-denylist.cjs +126 -0
  60. package/rules/id-length.cjs +119 -0
  61. package/rules/id-match.cjs +139 -0
  62. package/rules/implicit-arrow-linebreak.cjs +76 -0
  63. package/rules/indent-legacy.cjs +520 -0
  64. package/rules/indent.cjs +842 -0
  65. package/rules/init-declarations.cjs +88 -0
  66. package/rules/jsx-quotes.cjs +84 -0
  67. package/rules/key-spacing.cjs +399 -0
  68. package/rules/keyword-spacing.cjs +464 -0
  69. package/rules/line-comment-position.cjs +75 -0
  70. package/rules/linebreak-style.cjs +89 -0
  71. package/rules/lines-around-comment.cjs +290 -0
  72. package/rules/lines-around-directive.cjs +129 -0
  73. package/rules/lines-between-class-members.cjs +212 -0
  74. package/rules/logical-assignment-operators.cjs +305 -0
  75. package/rules/max-classes-per-file.cjs +61 -0
  76. package/rules/max-depth.cjs +117 -0
  77. package/rules/max-len.cjs +256 -0
  78. package/rules/max-lines-per-function.cjs +116 -0
  79. package/rules/max-lines.cjs +109 -0
  80. package/rules/max-nested-callbacks.cjs +78 -0
  81. package/rules/max-params.cjs +78 -0
  82. package/rules/max-statements-per-line.cjs +147 -0
  83. package/rules/max-statements.cjs +119 -0
  84. package/rules/multiline-comment-style.cjs +319 -0
  85. package/rules/multiline-ternary.cjs +106 -0
  86. package/rules/new-cap.cjs +139 -0
  87. package/rules/new-parens.cjs +70 -0
  88. package/rules/newline-after-var.cjs +159 -0
  89. package/rules/newline-before-return.cjs +128 -0
  90. package/rules/newline-per-chained-call.cjs +100 -0
  91. package/rules/no-alert.cjs +84 -0
  92. package/rules/no-array-constructor.cjs +91 -0
  93. package/rules/no-async-promise-executor.cjs +33 -0
  94. package/rules/no-await-in-loop.cjs +75 -0
  95. package/rules/no-bitwise.cjs +106 -0
  96. package/rules/no-buffer-constructor.cjs +51 -0
  97. package/rules/no-caller.cjs +34 -0
  98. package/rules/no-case-declarations.cjs +56 -0
  99. package/rules/no-catch-shadow.cjs +57 -0
  100. package/rules/no-class-assign.cjs +55 -0
  101. package/rules/no-compare-neg-zero.cjs +52 -0
  102. package/rules/no-cond-assign.cjs +104 -0
  103. package/rules/no-confusing-arrow.cjs +87 -0
  104. package/rules/no-console.cjs +138 -0
  105. package/rules/no-const-assign.cjs +50 -0
  106. package/rules/no-constant-binary-expression.cjs +284 -0
  107. package/rules/no-constant-condition.cjs +119 -0
  108. package/rules/no-constructor-return.cjs +43 -0
  109. package/rules/no-continue.cjs +33 -0
  110. package/rules/no-control-regex.cjs +74 -0
  111. package/rules/no-debugger.cjs +33 -0
  112. package/rules/no-delete-var.cjs +32 -0
  113. package/rules/no-div-regex.cjs +39 -0
  114. package/rules/no-dupe-args.cjs +61 -0
  115. package/rules/no-dupe-class-members.cjs +77 -0
  116. package/rules/no-dupe-else-if.cjs +74 -0
  117. package/rules/no-dupe-keys.cjs +88 -0
  118. package/rules/no-duplicate-case.cjs +49 -0
  119. package/rules/no-duplicate-imports.cjs +166 -0
  120. package/rules/no-else-return.cjs +182 -0
  121. package/rules/no-empty-character-class.cjs +47 -0
  122. package/rules/no-empty-function.cjs +141 -0
  123. package/rules/no-empty-pattern.cjs +50 -0
  124. package/rules/no-empty-static-block.cjs +50 -0
  125. package/rules/no-empty.cjs +78 -0
  126. package/rules/no-eq-null.cjs +34 -0
  127. package/rules/no-eval.cjs +165 -0
  128. package/rules/no-ex-assign.cjs +45 -0
  129. package/rules/no-extend-native.cjs +103 -0
  130. package/rules/no-extra-bind.cjs +127 -0
  131. package/rules/no-extra-boolean-cast.cjs +159 -0
  132. package/rules/no-extra-label.cjs +116 -0
  133. package/rules/no-extra-parens.cjs +665 -0
  134. package/rules/no-extra-semi.cjs +103 -0
  135. package/rules/no-fallthrough.cjs +136 -0
  136. package/rules/no-floating-decimal.cjs +66 -0
  137. package/rules/no-func-assign.cjs +63 -0
  138. package/rules/no-global-assign.cjs +62 -0
  139. package/rules/no-implicit-coercion.cjs +219 -0
  140. package/rules/no-implicit-globals.cjs +77 -0
  141. package/rules/no-implied-eval.cjs +87 -0
  142. package/rules/no-import-assign.cjs +123 -0
  143. package/rules/no-inline-comments.cjs +57 -0
  144. package/rules/no-inner-declarations.cjs +82 -0
  145. package/rules/no-invalid-regexp.cjs +130 -0
  146. package/rules/no-invalid-this.cjs +90 -0
  147. package/rules/no-irregular-whitespace.cjs +157 -0
  148. package/rules/no-iterator.cjs +34 -0
  149. package/rules/no-label-var.cjs +46 -0
  150. package/rules/no-labels.cjs +106 -0
  151. package/rules/no-lone-blocks.cjs +75 -0
  152. package/rules/no-lonely-if.cjs +42 -0
  153. package/rules/no-loop-func.cjs +143 -0
  154. package/rules/no-loss-of-precision.cjs +160 -0
  155. package/rules/no-magic-numbers.cjs +222 -0
  156. package/rules/no-misleading-character-class.cjs +500 -0
  157. package/rules/no-mixed-operators.cjs +197 -0
  158. package/rules/no-mixed-requires.cjs +117 -0
  159. package/rules/no-mixed-spaces-and-tabs.cjs +87 -0
  160. package/rules/no-multi-assign.cjs +38 -0
  161. package/rules/no-multi-spaces.cjs +95 -0
  162. package/rules/no-multi-str.cjs +44 -0
  163. package/rules/no-multiple-empty-lines.cjs +112 -0
  164. package/rules/no-native-reassign.cjs +72 -0
  165. package/rules/no-negated-condition.cjs +77 -0
  166. package/rules/no-negated-in-lhs.cjs +43 -0
  167. package/rules/no-nested-ternary.cjs +33 -0
  168. package/rules/no-new-func.cjs +50 -0
  169. package/rules/no-new-native-nonconstructor.cjs +42 -0
  170. package/rules/no-new-object.cjs +47 -0
  171. package/rules/no-new-require.cjs +50 -0
  172. package/rules/no-new-symbol.cjs +48 -0
  173. package/rules/no-new-wrappers.cjs +44 -0
  174. package/rules/no-new.cjs +33 -0
  175. package/rules/no-nonoctal-decimal-escape.cjs +80 -0
  176. package/rules/no-obj-calls.cjs +64 -0
  177. package/rules/no-object-constructor.cjs +69 -0
  178. package/rules/no-octal-escape.cjs +35 -0
  179. package/rules/no-octal.cjs +32 -0
  180. package/rules/no-param-reassign.cjs +135 -0
  181. package/rules/no-path-concat.cjs +52 -0
  182. package/rules/no-plusplus.cjs +64 -0
  183. package/rules/no-process-env.cjs +51 -0
  184. package/rules/no-process-exit.cjs +50 -0
  185. package/rules/no-promise-executor-return.cjs +131 -0
  186. package/rules/no-proto.cjs +34 -0
  187. package/rules/no-prototype-builtins.cjs +85 -0
  188. package/rules/no-redeclare.cjs +103 -0
  189. package/rules/no-regex-spaces.cjs +115 -0
  190. package/rules/no-restricted-exports.cjs +117 -0
  191. package/rules/no-restricted-globals.cjs +147 -0
  192. package/rules/no-restricted-imports.cjs +421 -0
  193. package/rules/no-restricted-modules.cjs +144 -0
  194. package/rules/no-restricted-properties.cjs +123 -0
  195. package/rules/no-restricted-syntax.cjs +49 -0
  196. package/rules/no-return-assign.cjs +45 -0
  197. package/rules/no-return-await.cjs +88 -0
  198. package/rules/no-script-url.cjs +49 -0
  199. package/rules/no-self-assign.cjs +88 -0
  200. package/rules/no-self-compare.cjs +53 -0
  201. package/rules/no-sequences.cjs +81 -0
  202. package/rules/no-setter-return.cjs +110 -0
  203. package/rules/no-shadow-restricted-names.cjs +60 -0
  204. package/rules/no-shadow.cjs +302 -0
  205. package/rules/no-spaced-func.cjs +69 -0
  206. package/rules/no-sparse-arrays.cjs +40 -0
  207. package/rules/no-sync.cjs +58 -0
  208. package/rules/no-tabs.cjs +73 -0
  209. package/rules/no-template-curly-in-string.cjs +33 -0
  210. package/rules/no-ternary.cjs +33 -0
  211. package/rules/no-this-before-super.cjs +177 -0
  212. package/rules/no-throw-literal.cjs +40 -0
  213. package/rules/no-trailing-spaces.cjs +123 -0
  214. package/rules/no-unassigned-vars.cjs +54 -0
  215. package/rules/no-undef-init.cjs +46 -0
  216. package/rules/no-undef.cjs +51 -0
  217. package/rules/no-undefined.cjs +58 -0
  218. package/rules/no-underscore-dangle.cjs +211 -0
  219. package/rules/no-unexpected-multiline.cjs +76 -0
  220. package/rules/no-unmodified-loop-condition.cjs +849 -0
  221. package/rules/no-unneeded-ternary.cjs +112 -0
  222. package/rules/no-unreachable-loop.cjs +128 -0
  223. package/rules/no-unreachable.cjs +195 -0
  224. package/rules/no-unsafe-finally.cjs +67 -0
  225. package/rules/no-unsafe-negation.cjs +86 -0
  226. package/rules/no-unsafe-optional-chaining.cjs +164 -0
  227. package/rules/no-unused-expressions.cjs +163 -0
  228. package/rules/no-unused-labels.cjs +97 -0
  229. package/rules/no-unused-private-class-members.cjs +69 -0
  230. package/rules/no-unused-vars.cjs +639 -0
  231. package/rules/no-use-before-define.cjs +245 -0
  232. package/rules/no-useless-assignment.cjs +250 -0
  233. package/rules/no-useless-backreference.cjs +137 -0
  234. package/rules/no-useless-call.cjs +57 -0
  235. package/rules/no-useless-catch.cjs +38 -0
  236. package/rules/no-useless-computed-key.cjs +106 -0
  237. package/rules/no-useless-concat.cjs +78 -0
  238. package/rules/no-useless-constructor.cjs +152 -0
  239. package/rules/no-useless-escape.cjs +164 -0
  240. package/rules/no-useless-rename.cjs +94 -0
  241. package/rules/no-useless-return.cjs +229 -0
  242. package/rules/no-var.cjs +235 -0
  243. package/rules/no-void.cjs +39 -0
  244. package/rules/no-warning-comments.cjs +112 -0
  245. package/rules/no-whitespace-before-property.cjs +72 -0
  246. package/rules/no-with.cjs +32 -0
  247. package/rules/nonblock-statement-body-position.cjs +107 -0
  248. package/rules/object-curly-newline.cjs +194 -0
  249. package/rules/object-curly-spacing.cjs +225 -0
  250. package/rules/object-property-newline.cjs +81 -0
  251. package/rules/object-shorthand.cjs +284 -0
  252. package/rules/one-var-declaration-per-line.cjs +75 -0
  253. package/rules/one-var.cjs +378 -0
  254. package/rules/operator-assignment.cjs +146 -0
  255. package/rules/operator-linebreak.cjs +150 -0
  256. package/rules/padded-blocks.cjs +192 -0
  257. package/rules/padding-line-between-statements.cjs +377 -0
  258. package/rules/prefer-arrow-callback.cjs +185 -0
  259. package/rules/prefer-const.cjs +240 -0
  260. package/rules/prefer-destructuring.cjs +188 -0
  261. package/rules/prefer-exponentiation-operator.cjs +100 -0
  262. package/rules/prefer-named-capture-group.cjs +111 -0
  263. package/rules/prefer-numeric-literals.cjs +75 -0
  264. package/rules/prefer-object-has-own.cjs +54 -0
  265. package/rules/prefer-object-spread.cjs +170 -0
  266. package/rules/prefer-promise-reject-errors.cjs +62 -0
  267. package/rules/prefer-reflect.cjs +100 -0
  268. package/rules/prefer-regex-literals.cjs +256 -0
  269. package/rules/prefer-rest-params.cjs +80 -0
  270. package/rules/prefer-spread.cjs +57 -0
  271. package/rules/prefer-template.cjs +147 -0
  272. package/rules/preserve-caught-error.cjs +196 -0
  273. package/rules/quote-props.cjs +224 -0
  274. package/rules/quotes.cjs +187 -0
  275. package/rules/radix.cjs +124 -0
  276. package/rules/require-atomic-updates.cjs +197 -0
  277. package/rules/require-await.cjs +90 -0
  278. package/rules/require-unicode-regexp.cjs +101 -0
  279. package/rules/require-yield.cjs +56 -0
  280. package/rules/rest-spread-spacing.cjs +99 -0
  281. package/rules/semi-spacing.cjs +215 -0
  282. package/rules/semi-style.cjs +116 -0
  283. package/rules/semi.cjs +239 -0
  284. package/rules/sort-imports.cjs +140 -0
  285. package/rules/sort-keys.cjs +165 -0
  286. package/rules/sort-vars.cjs +50 -0
  287. package/rules/space-before-blocks.cjs +132 -0
  288. package/rules/space-before-function-paren.cjs +126 -0
  289. package/rules/space-in-parens.cjs +175 -0
  290. package/rules/space-infix-ops.cjs +133 -0
  291. package/rules/space-unary-ops.cjs +237 -0
  292. package/rules/spaced-comment.cjs +233 -0
  293. package/rules/strict.cjs +206 -0
  294. package/rules/switch-colon-spacing.cjs +114 -0
  295. package/rules/symbol-description.cjs +49 -0
  296. package/rules/template-curly-spacing.cjs +112 -0
  297. package/rules/template-tag-spacing.cjs +82 -0
  298. package/rules/unicode-bom.cjs +52 -0
  299. package/rules/use-isnan.cjs +144 -0
  300. package/rules/valid-typeof.cjs +104 -0
  301. package/rules/vars-on-top.cjs +94 -0
  302. package/rules/wrap-iife.cjs +131 -0
  303. package/rules/wrap-regex.cjs +57 -0
  304. package/rules/yield-star-spacing.cjs +115 -0
  305. package/rules/yoda.cjs +185 -0
@@ -0,0 +1,160 @@
1
+ //#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-loss-of-precision.js
2
+ /**
3
+ * @fileoverview Rule to flag numbers that will lose significant figure precision at runtime
4
+ * @author Jacob Moore
5
+ */
6
+ var require_no_loss_of_precision = /* @__PURE__ */ require("../common/chunk.cjs").t(((exports, module) => {
7
+ /** Class representing a number in scientific notation. */
8
+ var ScientificNotation = class {
9
+ /** @type {string} The digits of the coefficient. A decimal point is implied after the first digit. */
10
+ coefficient;
11
+ /** @type {number} The order of magnitude. */
12
+ magnitude;
13
+ constructor(coefficient, magnitude) {
14
+ this.coefficient = coefficient, this.magnitude = magnitude;
15
+ }
16
+ /* c8 ignore start -- debug only */
17
+ toString() {
18
+ return `${this.coefficient[0]}${this.coefficient.length > 1 ? `.${this.coefficient.slice(1)}` : ""}e${this.magnitude}`;
19
+ }
20
+ };
21
+ /**
22
+ * Returns whether the node is number literal
23
+ * @param {Node} node the node literal being evaluated
24
+ * @returns {boolean} true if the node is a number literal
25
+ */
26
+ function isNumber(node) {
27
+ return typeof node.value == "number";
28
+ }
29
+ /**
30
+ * Gets the source code of the given number literal. Removes `_` numeric separators from the result.
31
+ * @param {Node} node the number `Literal` node
32
+ * @returns {string} raw source code of the literal, without numeric separators
33
+ */
34
+ function getRaw(node) {
35
+ return node.raw.replace(/_/gu, "");
36
+ }
37
+ /**
38
+ * Checks whether the number is base ten
39
+ * @param {ASTNode} node the node being evaluated
40
+ * @returns {boolean} true if the node is in base ten
41
+ */
42
+ function isBaseTen(node) {
43
+ return [
44
+ "0x",
45
+ "0X",
46
+ "0b",
47
+ "0B",
48
+ "0o",
49
+ "0O"
50
+ ].every((prefix) => !node.raw.startsWith(prefix)) && !/^0[0-7]+$/u.test(node.raw);
51
+ }
52
+ /**
53
+ * Checks that the user-intended non-base ten number equals the actual number after is has been converted to the Number type
54
+ * @param {Node} node the node being evaluated
55
+ * @returns {boolean} true if they do not match
56
+ */
57
+ function notBaseTenLosesPrecision(node) {
58
+ let rawString = getRaw(node).toUpperCase(), base;
59
+ return base = rawString.startsWith("0B") ? 2 : rawString.startsWith("0X") ? 16 : 8, !rawString.endsWith(node.value.toString(base).toUpperCase());
60
+ }
61
+ /**
62
+ * Returns the number stripped of leading zeros
63
+ * @param {string} numberAsString the string representation of the number
64
+ * @returns {string} the stripped string
65
+ */
66
+ function removeLeadingZeros(numberAsString) {
67
+ for (let i = 0; i < numberAsString.length; i++) if (numberAsString[i] !== "0") return numberAsString.slice(i);
68
+ return numberAsString;
69
+ }
70
+ /**
71
+ * Returns the number stripped of trailing zeros
72
+ * @param {string} numberAsString the string representation of the number
73
+ * @returns {string} the stripped string
74
+ */
75
+ function removeTrailingZeros(numberAsString) {
76
+ for (let i = numberAsString.length - 1; i >= 0; i--) if (numberAsString[i] !== "0") return numberAsString.slice(0, i + 1);
77
+ return numberAsString;
78
+ }
79
+ /**
80
+ * Converts an integer to an object containing the integer's coefficient and order of magnitude
81
+ * @param {string} stringInteger the string representation of the integer being converted
82
+ * @returns {ScientificNotation} the object containing the integer's coefficient and order of magnitude
83
+ */
84
+ function normalizeInteger(stringInteger) {
85
+ let trimmedInteger = removeLeadingZeros(stringInteger);
86
+ return new ScientificNotation(removeTrailingZeros(trimmedInteger), trimmedInteger.length - 1);
87
+ }
88
+ /**
89
+ * Converts a float to an object containing the float's coefficient and order of magnitude
90
+ * @param {string} stringFloat the string representation of the float being converted
91
+ * @returns {ScientificNotation} the object containing the float's coefficient and order of magnitude
92
+ */
93
+ function normalizeFloat(stringFloat) {
94
+ let trimmedFloat = removeLeadingZeros(stringFloat), indexOfDecimalPoint = trimmedFloat.indexOf(".");
95
+ switch (indexOfDecimalPoint) {
96
+ case 0: {
97
+ let significantDigits = removeLeadingZeros(trimmedFloat.slice(1));
98
+ return new ScientificNotation(significantDigits, significantDigits.length - trimmedFloat.length);
99
+ }
100
+ case -1: return new ScientificNotation(trimmedFloat, trimmedFloat.length - 1);
101
+ default: return new ScientificNotation(trimmedFloat.replace(".", ""), indexOfDecimalPoint - 1);
102
+ }
103
+ }
104
+ /**
105
+ * Converts a base ten number to proper scientific notation
106
+ * @param {string} stringNumber the string representation of the base ten number to be converted
107
+ * @param {boolean} parseAsFloat if true, the coefficient will be always parsed as a float, regardless of whether a decimal point is present
108
+ * @returns {ScientificNotation} the object containing the number's coefficient and order of magnitude
109
+ */
110
+ function convertNumberToScientificNotation(stringNumber, parseAsFloat) {
111
+ let splitNumber = stringNumber.split("e"), originalCoefficient = splitNumber[0], normalizedNumber = parseAsFloat || stringNumber.includes(".") ? normalizeFloat(originalCoefficient) : normalizeInteger(originalCoefficient);
112
+ return splitNumber.length > 1 && (normalizedNumber.magnitude += parseInt(splitNumber[1], 10)), normalizedNumber;
113
+ }
114
+ /**
115
+ * Checks that the user-intended base ten number equals the actual number after is has been converted to the Number type
116
+ * @param {Node} node the node being evaluated
117
+ * @returns {boolean} true if they do not match
118
+ */
119
+ function baseTenLosesPrecision(node) {
120
+ let normalizedRawNumber = convertNumberToScientificNotation(getRaw(node).toLowerCase(), !1), requestedPrecision = normalizedRawNumber.coefficient.length;
121
+ if (requestedPrecision > 100) return !0;
122
+ let normalizedStoredNumber = convertNumberToScientificNotation(node.value.toPrecision(requestedPrecision), !0);
123
+ return normalizedRawNumber.magnitude !== normalizedStoredNumber.magnitude || normalizedRawNumber.coefficient !== normalizedStoredNumber.coefficient;
124
+ }
125
+ /**
126
+ * Checks that the user-intended number equals the actual number after is has been converted to the Number type
127
+ * @param {Node} node the node being evaluated
128
+ * @returns {boolean} true if they do not match
129
+ */
130
+ function losesPrecision(node) {
131
+ return isBaseTen(node) ? baseTenLosesPrecision(node) : notBaseTenLosesPrecision(node);
132
+ }
133
+ /** @type {import('../types').Rule.RuleModule} */
134
+ module.exports = {
135
+ meta: {
136
+ type: "problem",
137
+ dialects: ["typescript", "javascript"],
138
+ language: "javascript",
139
+ docs: {
140
+ description: "Disallow literal numbers that lose precision",
141
+ recommended: !0,
142
+ url: "https://eslint.org/docs/latest/rules/no-loss-of-precision"
143
+ },
144
+ schema: [],
145
+ messages: { noLossOfPrecision: "This number literal will lose precision at runtime." }
146
+ },
147
+ create(context) {
148
+ return { Literal(node) {
149
+ node.value && isNumber(node) && losesPrecision(node) && context.report({
150
+ messageId: "noLossOfPrecision",
151
+ node
152
+ });
153
+ } };
154
+ }
155
+ };
156
+ }));
157
+ //#endregion
158
+ //#region src-js/generated/plugin-eslint/rules/no-loss-of-precision.cjs
159
+ module.exports = require_no_loss_of_precision().create;
160
+ //#endregion
@@ -0,0 +1,222 @@
1
+ const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
2
+ //#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/no-magic-numbers.js
3
+ /**
4
+ * @fileoverview Rule to flag statements that use magic numbers (adapted from https://github.com/danielstjules/buddy.js)
5
+ * @author Vincent Lemeunier
6
+ */
7
+ var require_no_magic_numbers = /* @__PURE__ */ require_chunk.t(((exports, module) => {
8
+ let astUtils = require_ast_utils$1.t(), MAX_ARRAY_LENGTH = 2 ** 32 - 1;
9
+ /**
10
+ * Convert the value to bigint if it's a string. Otherwise return the value as-is.
11
+ * @param {bigint|number|string} x The value to normalize.
12
+ * @returns {bigint|number} The normalized value.
13
+ */
14
+ function normalizeIgnoreValue(x) {
15
+ return typeof x == "string" ? BigInt(x.slice(0, -1)) : x;
16
+ }
17
+ /**
18
+ * Checks if the node parent is a TypeScript enum member
19
+ * @param {ASTNode} node The node to be validated
20
+ * @returns {boolean} True if the node parent is a TypeScript enum member
21
+ */
22
+ function isParentTSEnumDeclaration(node) {
23
+ return node.parent.type === "TSEnumMember";
24
+ }
25
+ /**
26
+ * Checks if the node is a valid TypeScript numeric literal type.
27
+ * @param {ASTNode} node The node to be validated
28
+ * @returns {boolean} True if the node is a TypeScript numeric literal type
29
+ */
30
+ function isTSNumericLiteralType(node) {
31
+ let ancestor = node.parent;
32
+ for (; ancestor.parent.type === "TSUnionType";) ancestor = ancestor.parent;
33
+ return ancestor.parent.type === "TSTypeAliasDeclaration";
34
+ }
35
+ /**
36
+ * Checks if the node parent is a readonly class property
37
+ * @param {ASTNode} node The node to be validated
38
+ * @returns {boolean} True if the node parent is a readonly class property
39
+ */
40
+ function isParentTSReadonlyPropertyDefinition(node) {
41
+ return !!(node.parent?.type === "PropertyDefinition" && node.parent.readonly);
42
+ }
43
+ /**
44
+ * Checks if the node is part of a type indexed access (eg. Foo[4])
45
+ * @param {ASTNode} node The node to be validated
46
+ * @returns {boolean} True if the node is part of an indexed access
47
+ */
48
+ function isAncestorTSIndexedAccessType(node) {
49
+ let ancestor = node.parent;
50
+ for (; ancestor.parent.type === "TSUnionType" || ancestor.parent.type === "TSIntersectionType";) ancestor = ancestor.parent;
51
+ return ancestor.parent.type === "TSIndexedAccessType";
52
+ }
53
+ /** @type {import('../types').Rule.RuleModule} */
54
+ module.exports = {
55
+ meta: {
56
+ type: "suggestion",
57
+ dialects: ["typescript", "javascript"],
58
+ language: "javascript",
59
+ docs: {
60
+ description: "Disallow magic numbers",
61
+ recommended: !1,
62
+ frozen: !0,
63
+ url: "https://eslint.org/docs/latest/rules/no-magic-numbers"
64
+ },
65
+ schema: [{
66
+ type: "object",
67
+ properties: {
68
+ detectObjects: {
69
+ type: "boolean",
70
+ default: !1
71
+ },
72
+ enforceConst: {
73
+ type: "boolean",
74
+ default: !1
75
+ },
76
+ ignore: {
77
+ type: "array",
78
+ items: { anyOf: [{ type: "number" }, {
79
+ type: "string",
80
+ pattern: "^[+-]?(?:0|[1-9][0-9]*)n$"
81
+ }] },
82
+ uniqueItems: !0
83
+ },
84
+ ignoreArrayIndexes: {
85
+ type: "boolean",
86
+ default: !1
87
+ },
88
+ ignoreDefaultValues: {
89
+ type: "boolean",
90
+ default: !1
91
+ },
92
+ ignoreClassFieldInitialValues: {
93
+ type: "boolean",
94
+ default: !1
95
+ },
96
+ ignoreEnums: {
97
+ type: "boolean",
98
+ default: !1
99
+ },
100
+ ignoreNumericLiteralTypes: {
101
+ type: "boolean",
102
+ default: !1
103
+ },
104
+ ignoreReadonlyClassProperties: {
105
+ type: "boolean",
106
+ default: !1
107
+ },
108
+ ignoreTypeIndexes: {
109
+ type: "boolean",
110
+ default: !1
111
+ }
112
+ },
113
+ additionalProperties: !1
114
+ }],
115
+ messages: {
116
+ useConst: "Number constants declarations must use 'const'.",
117
+ noMagic: "No magic number: {{raw}}."
118
+ }
119
+ },
120
+ create(context) {
121
+ let config = context.options[0] || {}, detectObjects = !!config.detectObjects, enforceConst = !!config.enforceConst, ignore = new Set((config.ignore || []).map(normalizeIgnoreValue)), ignoreArrayIndexes = !!config.ignoreArrayIndexes, ignoreDefaultValues = !!config.ignoreDefaultValues, ignoreClassFieldInitialValues = !!config.ignoreClassFieldInitialValues, ignoreEnums = !!config.ignoreEnums, ignoreNumericLiteralTypes = !!config.ignoreNumericLiteralTypes, ignoreReadonlyClassProperties = !!config.ignoreReadonlyClassProperties, ignoreTypeIndexes = !!config.ignoreTypeIndexes, okTypes = detectObjects ? [] : [
122
+ "ObjectExpression",
123
+ "Property",
124
+ "AssignmentExpression"
125
+ ];
126
+ /**
127
+ * Returns whether the rule is configured to ignore the given value
128
+ * @param {bigint|number} value The value to check
129
+ * @returns {boolean} true if the value is ignored
130
+ */
131
+ function isIgnoredValue(value) {
132
+ return ignore.has(value);
133
+ }
134
+ /**
135
+ * Returns whether the number is a default value assignment.
136
+ * @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node
137
+ * @returns {boolean} true if the number is a default value
138
+ */
139
+ function isDefaultValue(fullNumberNode) {
140
+ let parent = fullNumberNode.parent;
141
+ return parent.type === "AssignmentPattern" && parent.right === fullNumberNode;
142
+ }
143
+ /**
144
+ * Returns whether the number is the initial value of a class field.
145
+ * @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node
146
+ * @returns {boolean} true if the number is the initial value of a class field.
147
+ */
148
+ function isClassFieldInitialValue(fullNumberNode) {
149
+ let parent = fullNumberNode.parent;
150
+ return parent.type === "PropertyDefinition" && parent.value === fullNumberNode;
151
+ }
152
+ /**
153
+ * Returns whether the given node is used as a radix within parseInt() or Number.parseInt()
154
+ * @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node
155
+ * @returns {boolean} true if the node is radix
156
+ */
157
+ function isParseIntRadix(fullNumberNode) {
158
+ let parent = fullNumberNode.parent;
159
+ return parent.type === "CallExpression" && fullNumberNode === parent.arguments[1] && (astUtils.isSpecificId(parent.callee, "parseInt") || astUtils.isSpecificMemberAccess(parent.callee, "Number", "parseInt"));
160
+ }
161
+ /**
162
+ * Returns whether the given node is a direct child of a JSX node.
163
+ * In particular, it aims to detect numbers used as prop values in JSX tags.
164
+ * Example: <input maxLength={10} />
165
+ * @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node
166
+ * @returns {boolean} true if the node is a JSX number
167
+ */
168
+ function isJSXNumber(fullNumberNode) {
169
+ return fullNumberNode.parent.type.indexOf("JSX") === 0;
170
+ }
171
+ /**
172
+ * Returns whether the given node is used as an array index.
173
+ * Value must coerce to a valid array index name: "0", "1", "2" ... "4294967294".
174
+ *
175
+ * All other values, like "-1", "2.5", or "4294967295", are just "normal" object properties,
176
+ * which can be created and accessed on an array in addition to the array index properties,
177
+ * but they don't affect array's length and are not considered by methods such as .map(), .forEach() etc.
178
+ *
179
+ * The maximum array length by the specification is 2 ** 32 - 1 = 4294967295,
180
+ * thus the maximum valid index is 2 ** 32 - 2 = 4294967294.
181
+ *
182
+ * All notations are allowed, as long as the value coerces to one of "0", "1", "2" ... "4294967294".
183
+ *
184
+ * Valid examples:
185
+ * a[0], a[1], a[1.2e1], a[0xAB], a[0n], a[1n]
186
+ * a[-0] (same as a[0] because -0 coerces to "0")
187
+ * a[-0n] (-0n evaluates to 0n)
188
+ *
189
+ * Invalid examples:
190
+ * a[-1], a[-0xAB], a[-1n], a[2.5], a[1.23e1], a[12e-1]
191
+ * a[4294967295] (above the max index, it's an access to a regular property a["4294967295"])
192
+ * a[999999999999999999999] (even if it wasn't above the max index, it would be a["1e+21"])
193
+ * a[1e310] (same as a["Infinity"])
194
+ * @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node
195
+ * @param {bigint|number} value Value expressed by the fullNumberNode
196
+ * @returns {boolean} true if the node is a valid array index
197
+ */
198
+ function isArrayIndex(fullNumberNode, value) {
199
+ let parent = fullNumberNode.parent;
200
+ return parent.type === "MemberExpression" && parent.property === fullNumberNode && (Number.isInteger(value) || typeof value == "bigint") && value >= 0 && value < MAX_ARRAY_LENGTH;
201
+ }
202
+ return { Literal(node) {
203
+ if (!astUtils.isNumericLiteral(node)) return;
204
+ let fullNumberNode, value, raw;
205
+ node.parent.type === "UnaryExpression" && ["-", "+"].includes(node.parent.operator) ? (fullNumberNode = node.parent, value = node.parent.operator === "-" ? -node.value : node.value, raw = `${node.parent.operator}${node.raw}`) : (fullNumberNode = node, value = node.value, raw = node.raw);
206
+ let parent = fullNumberNode.parent;
207
+ isIgnoredValue(value) || ignoreDefaultValues && isDefaultValue(fullNumberNode) || ignoreClassFieldInitialValues && isClassFieldInitialValue(fullNumberNode) || ignoreEnums && isParentTSEnumDeclaration(fullNumberNode) || ignoreNumericLiteralTypes && isTSNumericLiteralType(fullNumberNode) || ignoreTypeIndexes && isAncestorTSIndexedAccessType(fullNumberNode) || ignoreReadonlyClassProperties && isParentTSReadonlyPropertyDefinition(fullNumberNode) || isParseIntRadix(fullNumberNode) || isJSXNumber(fullNumberNode) || ignoreArrayIndexes && isArrayIndex(fullNumberNode, value) || (parent.type === "VariableDeclarator" ? enforceConst && parent.parent.kind !== "const" && context.report({
208
+ node: fullNumberNode,
209
+ messageId: "useConst"
210
+ }) : (!okTypes.includes(parent.type) || parent.type === "AssignmentExpression" && parent.left.type === "Identifier") && context.report({
211
+ node: fullNumberNode,
212
+ messageId: "noMagic",
213
+ data: { raw }
214
+ }));
215
+ } };
216
+ }
217
+ };
218
+ }));
219
+ //#endregion
220
+ //#region src-js/generated/plugin-eslint/rules/no-magic-numbers.cjs
221
+ module.exports = require_no_magic_numbers().create;
222
+ //#endregion