no-bigint.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const { ReferenceTracker } = require("eslint-utils")
  7. module.exports = {
  8. meta: {
  9. docs: {
  10. description: "disallow `bigint` syntax and built-ins",
  11. category: "ES2020",
  12. recommended: false,
  13. url:
  14. "http://mysticatea.github.io/eslint-plugin-es/rules/no-bigint.html",
  15. },
  16. fixable: null,
  17. messages: {
  18. forbidden: "ES2020 BigInt is forbidden.",
  19. },
  20. schema: [],
  21. type: "problem",
  22. },
  23. create(context) {
  24. return {
  25. Literal(node) {
  26. if (node.bigint != null) {
  27. context.report({ messageId: "forbidden", node })
  28. }
  29. },
  30. "Program:exit"() {
  31. const tracker = new ReferenceTracker(context.getScope())
  32. const references = tracker.iterateGlobalReferences({
  33. BigInt: { [ReferenceTracker.READ]: true },
  34. BigInt64Array: { [ReferenceTracker.READ]: true },
  35. BigUint64Array: { [ReferenceTracker.READ]: true },
  36. })
  37. for (const { node } of references) {
  38. context.report({ messageId: "forbidden", node })
  39. }
  40. },
  41. }
  42. },
  43. }