no-number-epsilon.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 { READ, ReferenceTracker } = require("eslint-utils")
  7. module.exports = {
  8. meta: {
  9. docs: {
  10. description: "disallow the `Number.EPSILON` property.",
  11. category: "ES2015",
  12. recommended: false,
  13. url:
  14. "http://mysticatea.github.io/eslint-plugin-es/rules/no-number-epsilon.html",
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. forbidden: "ES2015 '{{name}}' property is forbidden.",
  20. },
  21. },
  22. create(context) {
  23. return {
  24. "Program:exit"() {
  25. const tracker = new ReferenceTracker(context.getScope())
  26. for (const { node, path } of tracker.iterateGlobalReferences({
  27. Number: {
  28. EPSILON: { [READ]: true },
  29. },
  30. })) {
  31. context.report({
  32. node,
  33. messageId: "forbidden",
  34. data: { name: path.join(".") },
  35. })
  36. }
  37. },
  38. }
  39. },
  40. }