summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/lib/rules/no-constructor-return.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/lib/rules/no-constructor-return.js')
-rw-r--r--tools/node_modules/eslint/lib/rules/no-constructor-return.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/lib/rules/no-constructor-return.js b/tools/node_modules/eslint/lib/rules/no-constructor-return.js
new file mode 100644
index 0000000000..4757770b7c
--- /dev/null
+++ b/tools/node_modules/eslint/lib/rules/no-constructor-return.js
@@ -0,0 +1,62 @@
+/**
+ * @fileoverview Rule to disallow returning value from constructor.
+ * @author Pig Fang <https://github.com/g-plane>
+ */
+
+"use strict";
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = {
+ meta: {
+ type: "problem",
+
+ docs: {
+ description: "disallow returning value from constructor",
+ category: "Best Practices",
+ recommended: false,
+ url: "https://eslint.org/docs/rules/no-constructor-return"
+ },
+
+ schema: {},
+
+ fixable: null,
+
+ messages: {
+ unexpected: "Unexpected return statement in constructor."
+ }
+ },
+
+ create(context) {
+ const stack = [];
+
+ return {
+ onCodePathStart(_, node) {
+ stack.push(node);
+ },
+ onCodePathEnd() {
+ stack.pop();
+ },
+ ReturnStatement(node) {
+ const last = stack[stack.length - 1];
+
+ if (!last.parent) {
+ return;
+ }
+
+ if (
+ last.parent.type === "MethodDefinition" &&
+ last.parent.kind === "constructor" &&
+ (node.parent.parent === last || node.argument)
+ ) {
+ context.report({
+ node,
+ messageId: "unexpected"
+ });
+ }
+ }
+ };
+ }
+};