es-builtins.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { READ } = require("eslint-utils")
  7. const checkUnsupportedBuiltins = require("../../util/check-unsupported-builtins")
  8. const enumeratePropertyNames = require("../../util/enumerate-property-names")
  9. const trackMap = {
  10. globals: {
  11. Array: {
  12. from: { [READ]: { supported: "4.0.0" } },
  13. of: { [READ]: { supported: "4.0.0" } },
  14. },
  15. BigInt: {
  16. [READ]: { supported: "10.4.0" },
  17. },
  18. Map: {
  19. [READ]: { supported: "0.12.0" },
  20. },
  21. Math: {
  22. acosh: { [READ]: { supported: "0.12.0" } },
  23. asinh: { [READ]: { supported: "0.12.0" } },
  24. atanh: { [READ]: { supported: "0.12.0" } },
  25. cbrt: { [READ]: { supported: "0.12.0" } },
  26. clz32: { [READ]: { supported: "0.12.0" } },
  27. cosh: { [READ]: { supported: "0.12.0" } },
  28. expm1: { [READ]: { supported: "0.12.0" } },
  29. fround: { [READ]: { supported: "0.12.0" } },
  30. hypot: { [READ]: { supported: "0.12.0" } },
  31. imul: { [READ]: { supported: "0.12.0" } },
  32. log10: { [READ]: { supported: "0.12.0" } },
  33. log1p: { [READ]: { supported: "0.12.0" } },
  34. log2: { [READ]: { supported: "0.12.0" } },
  35. sign: { [READ]: { supported: "0.12.0" } },
  36. sinh: { [READ]: { supported: "0.12.0" } },
  37. tanh: { [READ]: { supported: "0.12.0" } },
  38. trunc: { [READ]: { supported: "0.12.0" } },
  39. },
  40. Number: {
  41. EPSILON: { [READ]: { supported: "0.12.0" } },
  42. isFinite: { [READ]: { supported: "0.10.0" } },
  43. isInteger: { [READ]: { supported: "0.12.0" } },
  44. isNaN: { [READ]: { supported: "0.10.0" } },
  45. isSafeInteger: { [READ]: { supported: "0.12.0" } },
  46. MAX_SAFE_INTEGER: { [READ]: { supported: "0.12.0" } },
  47. MIN_SAFE_INTEGER: { [READ]: { supported: "0.12.0" } },
  48. parseFloat: { [READ]: { supported: "0.12.0" } },
  49. parseInt: { [READ]: { supported: "0.12.0" } },
  50. },
  51. Object: {
  52. assign: { [READ]: { supported: "4.0.0" } },
  53. fromEntries: { [READ]: { supported: "12.0.0" } },
  54. getOwnPropertySymbols: { [READ]: { supported: "0.12.0" } },
  55. is: { [READ]: { supported: "0.10.0" } },
  56. setPrototypeOf: { [READ]: { supported: "0.12.0" } },
  57. values: { [READ]: { supported: "7.0.0" } },
  58. entries: { [READ]: { supported: "7.0.0" } },
  59. getOwnPropertyDescriptors: { [READ]: { supported: "7.0.0" } },
  60. },
  61. Promise: {
  62. [READ]: { supported: "0.12.0" },
  63. allSettled: { [READ]: { supported: "12.9.0" } },
  64. },
  65. Proxy: {
  66. [READ]: { supported: "6.0.0" },
  67. },
  68. Reflect: {
  69. [READ]: { supported: "6.0.0" },
  70. },
  71. Set: {
  72. [READ]: { supported: "0.12.0" },
  73. },
  74. String: {
  75. fromCodePoint: { [READ]: { supported: "4.0.0" } },
  76. raw: { [READ]: { supported: "4.0.0" } },
  77. },
  78. Symbol: {
  79. [READ]: { supported: "0.12.0" },
  80. },
  81. Int8Array: {
  82. [READ]: { supported: "0.10.0" },
  83. },
  84. Uint8Array: {
  85. [READ]: { supported: "0.10.0" },
  86. },
  87. Uint8ClampedArray: {
  88. [READ]: { supported: "0.10.0" },
  89. },
  90. Int16Array: {
  91. [READ]: { supported: "0.10.0" },
  92. },
  93. Uint16Array: {
  94. [READ]: { supported: "0.10.0" },
  95. },
  96. Int32Array: {
  97. [READ]: { supported: "0.10.0" },
  98. },
  99. Uint32Array: {
  100. [READ]: { supported: "0.10.0" },
  101. },
  102. BigInt64Array: {
  103. [READ]: { supported: "10.4.0" },
  104. },
  105. BigUint64Array: {
  106. [READ]: { supported: "10.4.0" },
  107. },
  108. Float32Array: {
  109. [READ]: { supported: "0.10.0" },
  110. },
  111. Float64Array: {
  112. [READ]: { supported: "0.10.0" },
  113. },
  114. DataView: {
  115. [READ]: { supported: "0.10.0" },
  116. },
  117. WeakMap: {
  118. [READ]: { supported: "0.12.0" },
  119. },
  120. WeakSet: {
  121. [READ]: { supported: "0.12.0" },
  122. },
  123. Atomics: {
  124. [READ]: { supported: "8.10.0" },
  125. },
  126. SharedArrayBuffer: {
  127. [READ]: { supported: "8.10.0" },
  128. },
  129. globalThis: {
  130. [READ]: { supported: "12.0.0" },
  131. },
  132. },
  133. }
  134. module.exports = {
  135. meta: {
  136. docs: {
  137. description:
  138. "disallow unsupported ECMAScript built-ins on the specified version",
  139. category: "Possible Errors",
  140. recommended: true,
  141. url:
  142. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-unsupported-features/es-builtins.md",
  143. },
  144. type: "problem",
  145. fixable: null,
  146. schema: [
  147. {
  148. type: "object",
  149. properties: {
  150. version: {
  151. type: "string",
  152. },
  153. ignores: {
  154. type: "array",
  155. items: {
  156. enum: Array.from(
  157. enumeratePropertyNames(trackMap.globals)
  158. ),
  159. },
  160. uniqueItems: true,
  161. },
  162. },
  163. additionalProperties: false,
  164. },
  165. ],
  166. messages: {
  167. unsupported:
  168. "The '{{name}}' is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
  169. },
  170. },
  171. create(context) {
  172. return {
  173. "Program:exit"() {
  174. checkUnsupportedBuiltins(context, trackMap)
  175. },
  176. }
  177. },
  178. }