Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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-constructor-return.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @fileoverview Rule to disallow returning value from constructor.
  3. * @author Pig Fang <https://github.com/g-plane>
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "problem",
  12. docs: {
  13. description: "disallow returning value from constructor",
  14. category: "Best Practices",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-constructor-return"
  17. },
  18. schema: {},
  19. fixable: null,
  20. messages: {
  21. unexpected: "Unexpected return statement in constructor."
  22. }
  23. },
  24. create(context) {
  25. const stack = [];
  26. return {
  27. onCodePathStart(_, node) {
  28. stack.push(node);
  29. },
  30. onCodePathEnd() {
  31. stack.pop();
  32. },
  33. ReturnStatement(node) {
  34. const last = stack[stack.length - 1];
  35. if (!last.parent) {
  36. return;
  37. }
  38. if (
  39. last.parent.type === "MethodDefinition" &&
  40. last.parent.kind === "constructor" &&
  41. (node.parent.parent === last || node.argument)
  42. ) {
  43. context.report({
  44. node,
  45. messageId: "unexpected"
  46. });
  47. }
  48. }
  49. };
  50. }
  51. };