no-regexp-s-flag.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. messages: {
  18. forbidden: "ES2018 RegExp 's' flag is forbidden.",
  19. },
  20. schema: [],
  21. type: "problem",
  22. },
  23. create(context) {
  24. return {
  25. "Literal[regex]"(node) {
  26. if (node.regex.flags.includes("s")) {
  27. context.report({ node, messageId: "forbidden" })
  28. }
  29. },
  30. "Program:exit"() {
  31. const scope = context.getScope()
  32. for (const { node, flags } of getRegExpCalls(scope)) {
  33. if (flags && flags.includes("s")) {
  34. context.report({ node, messageId: "forbidden" })
  35. }
  36. }
  37. },
  38. }
  39. },
  40. }