no-unsupported-features.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2015 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. "use strict"
  7. //------------------------------------------------------------------------------
  8. // Requirements
  9. //------------------------------------------------------------------------------
  10. const semver = require("semver")
  11. const features = require("../util/features")
  12. const getDocsUrl = require("../util/get-docs-url")
  13. const getPackageJson = require("../util/get-package-json")
  14. const getValueIfString = require("../util/get-value-if-string")
  15. //------------------------------------------------------------------------------
  16. // Helpers
  17. //------------------------------------------------------------------------------
  18. const VERSION_MAP = new Map([
  19. [0.1, "0.10.0"],
  20. [0.12, "0.12.0"],
  21. [4, "4.0.0"],
  22. [5, "5.0.0"],
  23. [6, "6.0.0"],
  24. [6.5, "6.5.0"],
  25. [7, "7.0.0"],
  26. [7.6, "7.6.0"],
  27. [8, "8.0.0"],
  28. [8.3, "8.3.0"],
  29. [9, "9.0.0"],
  30. [10, "10.0.0"],
  31. ])
  32. const VERSION_SCHEMA = {
  33. anyOf: [
  34. { enum: Array.from(VERSION_MAP.keys()) },
  35. {
  36. type: "string",
  37. pattern: "^(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)$",
  38. },
  39. ],
  40. }
  41. const DEFAULT_VERSION = "4.0.0"
  42. const OPTIONS = Object.keys(features)
  43. const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/
  44. const CLASS_TYPE = /^Class(?:Declaration|Expression)$/
  45. const DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/
  46. const TOPLEVEL_SCOPE_TYPE = /^(?:global|function|module)$/
  47. const BINARY_NUMBER = /^0[bB]/
  48. const OCTAL_NUMBER = /^0[oO]/
  49. const UNICODE_ESC = /(\\+)u\{[0-9a-fA-F]+?\}/g
  50. const GET_OR_SET = /^(?:g|s)et$/
  51. const NEW_BUILTIN_TYPES = [
  52. "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array",
  53. "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "DataView",
  54. "Map", "Set", "WeakMap", "WeakSet", "Proxy", "Reflect", "Promise", "Symbol",
  55. "SharedArrayBuffer", "Atomics",
  56. ]
  57. const SUBCLASSING_TEST_TARGETS = [
  58. "Array", "RegExp", "Function", "Promise", "Boolean", "Number", "String",
  59. "Map", "Set",
  60. ]
  61. const PROPERTY_TEST_TARGETS = {
  62. Object: [
  63. "assign", "is", "getOwnPropertySymbols", "setPrototypeOf", "values",
  64. "entries", "getOwnPropertyDescriptors",
  65. ],
  66. String: ["raw", "fromCodePoint"],
  67. Array: ["from", "of"],
  68. Number: [
  69. "isFinite", "isInteger", "isSafeInteger", "isNaN", "EPSILON",
  70. "MIN_SAFE_INTEGER", "MAX_SAFE_INTEGER",
  71. ],
  72. Math: [
  73. "clz32", "imul", "sign", "log10", "log2", "log1p", "expm1", "cosh",
  74. "sinh", "tanh", "acosh", "asinh", "atanh", "trunc", "fround", "cbrt",
  75. "hypot",
  76. ],
  77. Symbol: [
  78. "hasInstance", "isConcatSpreadablec", "iterator", "species", "replace",
  79. "search", "split", "match", "toPrimitive", "toStringTag", "unscopables",
  80. ],
  81. Atomics: [
  82. "add", "and", "compareExchange", "exchange", "wait", "wake",
  83. "isLockFree", "load", "or", "store", "sub", "xor",
  84. ],
  85. }
  86. const REGEXP_NAMED_GROUP = /(\\*)\(\?<[_$\w]/
  87. const REGEXP_LOOKBEHIND = /(\\*)\(\?<[=!]/
  88. const REGEXP_UNICODE_PROPERTY = /(\\*)\\[pP]{.+?}/
  89. /**
  90. * Gets default version configuration of this rule.
  91. *
  92. * This finds and reads 'package.json' file, then parses 'engines.node' field.
  93. * If it's nothing, this returns null.
  94. *
  95. * @param {string} filename - The file name of the current linting file.
  96. * @returns {string} The default version configuration.
  97. */
  98. function getDefaultVersion(filename) {
  99. const info = getPackageJson(filename)
  100. const nodeVersion = info && info.engines && info.engines.node
  101. return semver.validRange(nodeVersion) || DEFAULT_VERSION
  102. }
  103. /**
  104. * Gets values of the `ignores` option.
  105. *
  106. * @returns {string[]} Values of the `ignores` option.
  107. */
  108. function getIgnoresEnum() {
  109. return Object.keys(OPTIONS.reduce(
  110. (retv, key) => {
  111. for (const alias of features[key].alias) {
  112. retv[alias] = true
  113. }
  114. retv[key] = true
  115. return retv
  116. },
  117. Object.create(null)
  118. ))
  119. }
  120. /**
  121. * Checks whether a given key should be ignored or not.
  122. *
  123. * @param {string} key - A key to check.
  124. * @param {string[]} ignores - An array of keys and aliases to be ignored.
  125. * @returns {boolean} `true` if the key should be ignored.
  126. */
  127. function isIgnored(key, ignores) {
  128. return (
  129. ignores.indexOf(key) !== -1 ||
  130. features[key].alias.some(alias => ignores.indexOf(alias) !== -1)
  131. )
  132. }
  133. /**
  134. * Parses the options.
  135. *
  136. * @param {number|string|object|undefined} options - An option object to parse.
  137. * @param {number} defaultVersion - The default version to use if the version option was omitted.
  138. * @returns {object} Parsed value.
  139. */
  140. function parseOptions(options, defaultVersion) {
  141. let version = null
  142. let range = null
  143. let ignores = []
  144. if (typeof options === "number") {
  145. version = VERSION_MAP.get(options)
  146. }
  147. else if (typeof options === "string") {
  148. version = options
  149. }
  150. else if (typeof options === "object") {
  151. version = (typeof options.version === "number")
  152. ? VERSION_MAP.get(options.version)
  153. : options.version
  154. ignores = options.ignores || []
  155. }
  156. range = semver.validRange(version ? `>=${version}` : defaultVersion)
  157. if (!version) {
  158. version = defaultVersion
  159. }
  160. return Object.freeze({
  161. version,
  162. features: Object.freeze(OPTIONS.reduce(
  163. (retv, key) => {
  164. const feature = features[key]
  165. if (isIgnored(key, ignores)) {
  166. retv[key] = Object.freeze({
  167. name: feature.name,
  168. singular: Boolean(feature.singular),
  169. supported: true,
  170. supportedInStrict: true,
  171. })
  172. }
  173. else if (typeof feature.node === "string") {
  174. retv[key] = Object.freeze({
  175. name: feature.name,
  176. singular: Boolean(feature.singular),
  177. supported: !semver.intersects(range, `<${feature.node}`),
  178. supportedInStrict: !semver.intersects(range, `<${feature.node}`),
  179. })
  180. }
  181. else {
  182. retv[key] = Object.freeze({
  183. name: feature.name,
  184. singular: Boolean(feature.singular),
  185. supported:
  186. feature.node != null &&
  187. feature.node.sloppy != null &&
  188. !semver.intersects(range, `<${feature.node.sloppy}`),
  189. supportedInStrict:
  190. feature.node != null &&
  191. feature.node.strict != null &&
  192. !semver.intersects(range, `<${feature.node.strict}`),
  193. })
  194. }
  195. return retv
  196. },
  197. Object.create(null)
  198. )),
  199. })
  200. }
  201. /**
  202. * Checks whether or not the current configure has a special lexical environment.
  203. * If it's modules or globalReturn then it has a special lexical environment.
  204. *
  205. * @param {RuleContext} context - A context to check.
  206. * @returns {boolean} `true` if the current configure is modules or globalReturn.
  207. */
  208. function checkSpecialLexicalEnvironment(context) {
  209. const parserOptions = context.parserOptions
  210. const ecmaFeatures = parserOptions.ecmaFeatures
  211. return Boolean(
  212. parserOptions.sourceType === "module" ||
  213. (ecmaFeatures && ecmaFeatures.globalReturn)
  214. )
  215. }
  216. /**
  217. * Gets the name of a given node.
  218. *
  219. * @param {ASTNode} node - An Identifier node to get.
  220. * @returns {string} The name of the node.
  221. */
  222. function getIdentifierName(node) {
  223. return node.name
  224. }
  225. /**
  226. * Checks whether the given string has `\u{90ABCDEF}`-like escapes.
  227. *
  228. * @param {string} raw - The string to check.
  229. * @returns {boolean} `true` if the string has Unicode code point escapes.
  230. */
  231. function hasUnicodeCodePointEscape(raw) {
  232. let match = null
  233. UNICODE_ESC.lastIndex = 0
  234. while ((match = UNICODE_ESC.exec(raw)) != null) {
  235. if (match[1].length % 2 === 1) {
  236. return true
  237. }
  238. }
  239. return false
  240. }
  241. /**
  242. * Check a given string has a given pattern.
  243. * @param {string} s A string to check.
  244. * @param {RegExp} pattern A RegExp object to check.
  245. * @returns {boolean} `true` if the string has the pattern.
  246. */
  247. function hasPattern(s, pattern) {
  248. const m = pattern.exec(s)
  249. return m != null && ((m[1] || "").length % 2) === 0
  250. }
  251. /**
  252. * The definition of this rule.
  253. *
  254. * @param {RuleContext} context - The rule context to check.
  255. * @returns {object} The definition of this rule.
  256. */
  257. function create(context) {
  258. const sourceCode = context.getSourceCode()
  259. const supportInfo = parseOptions(
  260. context.options[0],
  261. getDefaultVersion(context.getFilename())
  262. )
  263. const hasSpecialLexicalEnvironment = checkSpecialLexicalEnvironment(context)
  264. /**
  265. * Gets the references of the specified global variables.
  266. *
  267. * @param {string[]} names - Variable names to get.
  268. * @returns {void}
  269. */
  270. function* getReferences(names) {
  271. const globalScope = context.getScope()
  272. for (const name of names) {
  273. const variable = globalScope.set.get(name)
  274. if (variable && variable.defs.length === 0) {
  275. yield* variable.references
  276. }
  277. }
  278. }
  279. /**
  280. * Checks whether or not the current scope is strict mode.
  281. *
  282. * @returns {boolean}
  283. * `true` if the current scope is strict mode. Otherwise `false`.
  284. */
  285. function isStrict() {
  286. let scope = context.getScope()
  287. if (scope.type === "global" && hasSpecialLexicalEnvironment) {
  288. scope = scope.childScopes[0]
  289. }
  290. return scope.isStrict
  291. }
  292. /**
  293. * Checks whether the given function has trailing commas or not.
  294. *
  295. * @param {ASTNode} node - The function node to check.
  296. * @returns {boolean} `true` if the function has trailing commas.
  297. */
  298. function hasTrailingCommaForFunction(node) {
  299. const length = node.params.length
  300. return (
  301. length >= 1 &&
  302. sourceCode.getTokenAfter(node.params[length - 1]).value === ","
  303. )
  304. }
  305. /**
  306. * Checks whether the given call expression has trailing commas or not.
  307. *
  308. * @param {ASTNode} node - The call expression node to check.
  309. * @returns {boolean} `true` if the call expression has trailing commas.
  310. */
  311. function hasTrailingCommaForCall(node) {
  312. return (
  313. node.arguments.length >= 1 &&
  314. sourceCode.getLastToken(node, 1).value === ","
  315. )
  316. }
  317. /**
  318. * Checks whether the given class extends from null or not.
  319. *
  320. * @param {ASTNode} node - The class node to check.
  321. * @returns {boolean} `true` if the class extends from null.
  322. */
  323. function extendsNull(node) {
  324. return (
  325. node.superClass != null &&
  326. node.superClass.type === "Literal" &&
  327. node.superClass.value === null
  328. )
  329. }
  330. /**
  331. * Reports a given node if the specified feature is not supported.
  332. *
  333. * @param {ASTNode} node - A node to be reported.
  334. * @param {string} key - A feature name to report.
  335. * @returns {void}
  336. */
  337. function report(node, key) {
  338. const version = supportInfo.version
  339. const feature = supportInfo.features[key]
  340. if (feature.supported) {
  341. return
  342. }
  343. if (!feature.supportedInStrict) {
  344. context.report({
  345. node,
  346. message: "{{feature}} {{be}} not supported yet on Node {{version}}.",
  347. data: {
  348. feature: feature.name,
  349. be: feature.singular ? "is" : "are",
  350. version,
  351. },
  352. })
  353. }
  354. else if (!isStrict()) {
  355. context.report({
  356. node,
  357. message: "{{feature}} {{be}} not supported yet on Node {{version}}.",
  358. data: {
  359. feature: `${feature.name} in non-strict mode`,
  360. be: feature.singular ? "is" : "are",
  361. version,
  362. },
  363. })
  364. }
  365. }
  366. /**
  367. * Validate RegExp syntax.
  368. * @param {string} pattern A RegExp pattern to check.
  369. * @param {string} flags A RegExp flags to check.
  370. * @param {ASTNode} node A node to report.
  371. * @returns {void}
  372. */
  373. function validateRegExp(pattern, flags, node) {
  374. if (typeof pattern === "string") {
  375. if (hasPattern(pattern, REGEXP_NAMED_GROUP)) {
  376. report(node, "regexpNamedCaptureGroups")
  377. }
  378. if (hasPattern(pattern, REGEXP_LOOKBEHIND)) {
  379. report(node, "regexpLookbehind")
  380. }
  381. if (hasPattern(pattern, REGEXP_UNICODE_PROPERTY)) {
  382. report(node, "regexpUnicodeProperties")
  383. }
  384. }
  385. if (typeof flags === "string") {
  386. if (flags.indexOf("y") !== -1) {
  387. report(node, "regexpY")
  388. }
  389. if (flags.indexOf("u") !== -1) {
  390. report(node, "regexpU")
  391. }
  392. if (flags.indexOf("s") !== -1) {
  393. report(node, "regexpS")
  394. }
  395. }
  396. }
  397. /**
  398. * Validate RegExp syntax in a RegExp literal.
  399. * @param {ASTNode} node A Literal node to check.
  400. * @returns {void}
  401. */
  402. function validateRegExpLiteral(node) {
  403. validateRegExp(node.regex.pattern, node.regex.flags, node)
  404. }
  405. /**
  406. * Validate RegExp syntax in the first argument of `new RegExp()`.
  407. * @param {ASTNode} node A NewExpression node to check.
  408. * @returns {void}
  409. */
  410. function validateRegExpString(node) {
  411. const patternNode = node.arguments[0]
  412. const flagsNode = node.arguments[1]
  413. const pattern = (patternNode && patternNode.type === "Literal" && typeof patternNode.value === "string") ? patternNode.value : null
  414. const flags = (flagsNode && flagsNode.type === "Literal" && typeof flagsNode.value === "string") ? flagsNode.value : null
  415. validateRegExp(pattern, flags, node)
  416. }
  417. return {
  418. //----------------------------------------------------------------------
  419. // Program
  420. //----------------------------------------------------------------------
  421. //eslint-disable-next-line complexity
  422. "Program:exit"() {
  423. // Check new global variables.
  424. for (const name of NEW_BUILTIN_TYPES) {
  425. for (const reference of getReferences([name])) {
  426. // Ignore if it's using new static methods.
  427. const node = reference.identifier
  428. const parentNode = node.parent
  429. const properties = PROPERTY_TEST_TARGETS[name]
  430. if (properties && parentNode.type === "MemberExpression") {
  431. const propertyName = (parentNode.computed ? getValueIfString : getIdentifierName)(parentNode.property)
  432. if (properties.indexOf(propertyName) !== -1) {
  433. continue
  434. }
  435. }
  436. report(reference.identifier, name)
  437. }
  438. }
  439. // Check static methods.
  440. for (const reference of getReferences(Object.keys(PROPERTY_TEST_TARGETS))) {
  441. const node = reference.identifier
  442. const parentNode = node.parent
  443. if (parentNode.type !== "MemberExpression" ||
  444. parentNode.object !== node
  445. ) {
  446. continue
  447. }
  448. const objectName = node.name
  449. const properties = PROPERTY_TEST_TARGETS[objectName]
  450. const propertyName = (parentNode.computed ? getValueIfString : getIdentifierName)(parentNode.property)
  451. if (propertyName && properties.indexOf(propertyName) !== -1) {
  452. report(parentNode, `${objectName}.${propertyName}`)
  453. }
  454. }
  455. // Check subclassing
  456. for (const reference of getReferences(SUBCLASSING_TEST_TARGETS)) {
  457. const node = reference.identifier
  458. const parentNode = node.parent
  459. if (CLASS_TYPE.test(parentNode.type) &&
  460. parentNode.superClass === node
  461. ) {
  462. report(node, `extends${node.name}`)
  463. }
  464. }
  465. },
  466. //----------------------------------------------------------------------
  467. // Functions
  468. //----------------------------------------------------------------------
  469. "ArrowFunctionExpression"(node) {
  470. report(node, "arrowFunctions")
  471. if (node.async) {
  472. report(node, "asyncAwait")
  473. }
  474. if (hasTrailingCommaForFunction(node)) {
  475. report(node, "trailingCommasInFunctions")
  476. }
  477. },
  478. "AssignmentPattern"(node) {
  479. if (FUNC_TYPE.test(node.parent.type)) {
  480. report(node, "defaultParameters")
  481. }
  482. },
  483. "FunctionDeclaration"(node) {
  484. const scope = context.getScope().upper
  485. if (!TOPLEVEL_SCOPE_TYPE.test(scope.type)) {
  486. report(node, "blockScopedFunctions")
  487. }
  488. if (node.generator) {
  489. report(node, "generatorFunctions")
  490. }
  491. if (node.async) {
  492. report(node, "asyncAwait")
  493. }
  494. if (hasTrailingCommaForFunction(node)) {
  495. report(node, "trailingCommasInFunctions")
  496. }
  497. if (node.async && node.generator) {
  498. report(node, "asyncGenerators")
  499. }
  500. },
  501. "FunctionExpression"(node) {
  502. if (node.generator) {
  503. report(node, "generatorFunctions")
  504. }
  505. if (node.async) {
  506. report(node, "asyncAwait")
  507. }
  508. if (hasTrailingCommaForFunction(node)) {
  509. report(node, "trailingCommasInFunctions")
  510. }
  511. if (node.async && node.generator) {
  512. report(node, "asyncGenerators")
  513. }
  514. },
  515. "MetaProperty"(node) {
  516. const meta = node.meta.name || node.meta
  517. const property = node.property.name || node.property
  518. if (meta === "new" && property === "target") {
  519. report(node, "new.target")
  520. }
  521. },
  522. //----------------------------------------------------------------------
  523. // Classes
  524. //----------------------------------------------------------------------
  525. "ClassDeclaration"(node) {
  526. report(node, "classes")
  527. if (extendsNull(node)) {
  528. report(node, "extendsNull")
  529. }
  530. },
  531. "ClassExpression"(node) {
  532. report(node, "classes")
  533. if (extendsNull(node)) {
  534. report(node, "extendsNull")
  535. }
  536. },
  537. //----------------------------------------------------------------------
  538. // Statements
  539. //----------------------------------------------------------------------
  540. "ForOfStatement"(node) {
  541. report(node, "forOf")
  542. if (node.await) {
  543. report(node, "forAwaitOf")
  544. }
  545. },
  546. "VariableDeclaration"(node) {
  547. if (node.kind === "const") {
  548. report(node, "const")
  549. }
  550. else if (node.kind === "let") {
  551. report(node, "let")
  552. }
  553. },
  554. //----------------------------------------------------------------------
  555. // Expressions
  556. //----------------------------------------------------------------------
  557. "ArrayPattern"(node) {
  558. if (DESTRUCTURING_PARENT_TYPE.test(node.parent.type)) {
  559. report(node, "destructuring")
  560. }
  561. },
  562. "AssignmentExpression"(node) {
  563. if (node.operator === "**=") {
  564. report(node, "exponentialOperators")
  565. }
  566. },
  567. "AwaitExpression"(node) {
  568. report(node, "asyncAwait")
  569. },
  570. "BinaryExpression"(node) {
  571. if (node.operator === "**") {
  572. report(node, "exponentialOperators")
  573. }
  574. },
  575. "CallExpression"(node) {
  576. if (hasTrailingCommaForCall(node)) {
  577. report(node, "trailingCommasInFunctions")
  578. }
  579. },
  580. "Identifier"(node) {
  581. const raw = sourceCode.getText(node)
  582. if (hasUnicodeCodePointEscape(raw)) {
  583. report(node, "unicodeCodePointEscapes")
  584. }
  585. },
  586. "Literal"(node) {
  587. if (typeof node.value === "number") {
  588. if (BINARY_NUMBER.test(node.raw)) {
  589. report(node, "binaryNumberLiterals")
  590. }
  591. else if (OCTAL_NUMBER.test(node.raw)) {
  592. report(node, "octalNumberLiterals")
  593. }
  594. }
  595. else if (typeof node.value === "string") {
  596. if (hasUnicodeCodePointEscape(node.raw)) {
  597. report(node, "unicodeCodePointEscapes")
  598. }
  599. }
  600. else if (node.regex) {
  601. validateRegExpLiteral(node)
  602. }
  603. },
  604. "NewExpression"(node) {
  605. if (node.callee.type === "Identifier" && node.callee.name === "RegExp") {
  606. validateRegExpString(node)
  607. }
  608. if (hasTrailingCommaForCall(node)) {
  609. report(node, "trailingCommasInFunctions")
  610. }
  611. },
  612. "ObjectPattern"(node) {
  613. if (DESTRUCTURING_PARENT_TYPE.test(node.parent.type)) {
  614. report(node, "destructuring")
  615. }
  616. },
  617. "Property"(node) {
  618. if (node.parent.type === "ObjectExpression" &&
  619. (node.computed || node.shorthand || node.method)
  620. ) {
  621. if (node.shorthand && GET_OR_SET.test(node.key.name)) {
  622. report(node, "objectPropertyShorthandOfGetSet")
  623. }
  624. else {
  625. report(node, "objectLiteralExtensions")
  626. }
  627. }
  628. },
  629. "RestElement"(node) {
  630. if (FUNC_TYPE.test(node.parent.type)) {
  631. report(node, "restParameters")
  632. }
  633. else if (node.parent.type === "ObjectPattern") {
  634. report(node, "restProperties")
  635. }
  636. },
  637. "SpreadElement"(node) {
  638. if (node.parent.type === "ObjectExpression") {
  639. report(node, "spreadProperties")
  640. }
  641. else {
  642. report(node, "spreadOperators")
  643. }
  644. },
  645. "TemplateElement"(node) {
  646. if (node.value.cooked == null) {
  647. report(node, "templateLiteralRevision")
  648. }
  649. },
  650. "TemplateLiteral"(node) {
  651. report(node, "templateStrings")
  652. },
  653. //----------------------------------------------------------------------
  654. // Legacy
  655. //----------------------------------------------------------------------
  656. "ExperimentalRestProperty"(node) {
  657. report(node, "restProperties")
  658. },
  659. "ExperimentalSpreadProperty"(node) {
  660. report(node, "spreadProperties")
  661. },
  662. "RestProperty"(node) {
  663. report(node, "restProperties")
  664. },
  665. "SpreadProperty"(node) {
  666. report(node, "spreadProperties")
  667. },
  668. //----------------------------------------------------------------------
  669. // Modules
  670. //----------------------------------------------------------------------
  671. "ExportAllDeclaration"(node) {
  672. report(node, "modules")
  673. },
  674. "ExportDefaultDeclaration"(node) {
  675. report(node, "modules")
  676. },
  677. "ExportNamedDeclaration"(node) {
  678. report(node, "modules")
  679. },
  680. "ImportDeclaration"(node) {
  681. report(node, "modules")
  682. },
  683. }
  684. }
  685. //------------------------------------------------------------------------------
  686. // Rule Definition
  687. //------------------------------------------------------------------------------
  688. module.exports = {
  689. create,
  690. meta: {
  691. docs: {
  692. description: "disallow unsupported ECMAScript features on the specified version",
  693. category: "Possible Errors",
  694. recommended: true,
  695. url: getDocsUrl("no-unsupported-features.md"),
  696. },
  697. fixable: false,
  698. schema: [
  699. {
  700. anyOf: [
  701. VERSION_SCHEMA.anyOf[0],
  702. VERSION_SCHEMA.anyOf[1],
  703. {
  704. type: "object",
  705. properties: {
  706. version: VERSION_SCHEMA,
  707. ignores: {
  708. type: "array",
  709. items: { enum: getIgnoresEnum() },
  710. uniqueItems: true,
  711. },
  712. },
  713. additionalProperties: false,
  714. },
  715. ],
  716. },
  717. ],
  718. },
  719. }