Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-isnan.js 969B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @fileoverview Rule to flag comparisons to the value NaN
  3. * @author James Allardice
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "problem",
  12. docs: {
  13. description: "require calls to `isNaN()` when checking for `NaN`",
  14. category: "Possible Errors",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/use-isnan"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. return {
  22. BinaryExpression(node) {
  23. if (/^(?:[<>]|[!=]=)=?$/.test(node.operator) && (node.left.name === "NaN" || node.right.name === "NaN")) {
  24. context.report({ node, message: "Use the isNaN function to compare with NaN." });
  25. }
  26. }
  27. };
  28. }
  29. };