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.

no-div-regex.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileoverview Rule to check for ambiguous div operator in regexes
  3. * @author Matt DuVall <http://www.mattduvall.com>
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow division operators explicitly at the beginning of regular expressions",
  14. category: "Best Practices",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-div-regex"
  17. },
  18. schema: [],
  19. messages: {
  20. unexpected: "A regular expression literal can be confused with '/='."
  21. }
  22. },
  23. create(context) {
  24. const sourceCode = context.getSourceCode();
  25. return {
  26. Literal(node) {
  27. const token = sourceCode.getFirstToken(node);
  28. if (token.type === "RegularExpression" && token.value[1] === "=") {
  29. context.report({ node, messageId: "unexpected" });
  30. }
  31. }
  32. };
  33. }
  34. };