no-regexp-s-flag.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 { getRegExpCalls } = require("../utils")
  7. module.exports = {
  8. meta: {
  9. docs: {
  10. description: "disallow RegExp `s` flag.",
  11. category: "ES2018",
  12. recommended: false,
  13. url:
  14. "http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-s-flag.html",
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. forbidden: "ES2018 RegExp 's' flag is forbidden.",
  20. },
  21. },
  22. create(context) {
  23. return {
  24. "Literal[regex]"(node) {
  25. if (node.regex.flags.includes("s")) {
  26. context.report({ node, messageId: "forbidden" })
  27. }
  28. },
  29. "Program:exit"() {
  30. const scope = context.getScope()
  31. for (const { node, flags } of getRegExpCalls(scope)) {
  32. if (flags && flags.includes("s")) {
  33. context.report({ node, messageId: "forbidden" })
  34. }
  35. }
  36. },
  37. }
  38. },
  39. }