es-builtins.js 5.5 KB

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