no-object-super-properties.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. module.exports = {
  7. meta: {
  8. docs: {
  9. description:
  10. "disallow `super` property accesses in object literals.",
  11. category: "ES2015",
  12. recommended: false,
  13. url:
  14. "http://mysticatea.github.io/eslint-plugin-es/rules/no-object-super-properties.html",
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. forbidden:
  20. "ES2015 'super' property accesses in object literals are forbidden.",
  21. },
  22. },
  23. create(context) {
  24. let stack = null
  25. return {
  26. Super(node) {
  27. if (stack && stack.inObjectMethod) {
  28. context.report({ node, messageId: "forbidden" })
  29. }
  30. },
  31. ":matches(FunctionExpression, FunctionDeclaration)"(node) {
  32. const { type, method } = node.parent
  33. stack = {
  34. inObjectMethod: type === "Property" && method === true,
  35. upper: stack,
  36. }
  37. },
  38. ":matches(FunctionExpression, FunctionDeclaration):exit"() {
  39. stack = stack.upper
  40. },
  41. }
  42. },
  43. }