no-object-super-properties.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. messages: {
  18. forbidden:
  19. "ES2015 'super' property accesses in object literals are forbidden.",
  20. },
  21. schema: [],
  22. type: "problem",
  23. },
  24. create(context) {
  25. let stack = null
  26. return {
  27. Super(node) {
  28. if (stack && stack.inObjectMethod) {
  29. context.report({ node, messageId: "forbidden" })
  30. }
  31. },
  32. ":matches(FunctionExpression, FunctionDeclaration)"(node) {
  33. const { type, method } = node.parent
  34. stack = {
  35. inObjectMethod: type === "Property" && method === true,
  36. upper: stack,
  37. }
  38. },
  39. ":matches(FunctionExpression, FunctionDeclaration):exit"() {
  40. stack = stack.upper
  41. },
  42. }
  43. },
  44. }