[gjs: 39/43] CI: Add a rule to prevent unnecessary _init() functions



commit f52d56095dede8646ebecdea3ff19840ecaff3e0
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Aug 4 16:43:43 2019 -0700

    CI: Add a rule to prevent unnecessary _init() functions
    
    We have a built-in eslint rule to prevent unnecessary constructors that
    only chain up to super(). We should have an analogous rule for GObject
    _init() functions, which play the same role as a constructor. We can
    build a custom rule with no-restricted-syntax.

 .eslintrc.yml | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 60f21be3..53d5fbd3 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -114,6 +114,21 @@ rules:
     - object: imports
       property: mainloop
       message: Use GLib main loops and timeouts
+  no-restricted-syntax:
+    - error
+    - selector: >-
+        MethodDefinition[key.name="_init"] >
+        FunctionExpression[params.length=1] >
+        BlockStatement[body.length=1]
+        CallExpression[arguments.length=1][callee.object.type="Super"][callee.property.name="_init"] >
+        Identifier:first-child
+      message: _init() that only calls super._init() is unnecessary
+    - selector: >-
+        MethodDefinition[key.name="_init"] >
+        FunctionExpression[params.length=0] >
+        BlockStatement[body.length=1]
+        CallExpression[arguments.length=0][callee.object.type="Super"][callee.property.name="_init"]
+      message: _init() that only calls super._init() is unnecessary
   no-return-assign: error
   no-return-await: error
   no-self-compare: error


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]