This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 913e17abd0ab4423dc27ee8622cb5a37d6dda118
Author: Josh Tynjala <[email protected]>
AuthorDate: Mon Sep 26 14:53:53 2022 -0700

    linter: void-operator
---
 .../main/java/org/apache/royale/linter/LINTER.java |  4 ++
 .../apache/royale/linter/config/Configuration.java | 16 ++++++
 .../royale/linter/rules/VoidOperatorRule.java      | 64 ++++++++++++++++++++++
 3 files changed, 84 insertions(+)

diff --git a/linter/src/main/java/org/apache/royale/linter/LINTER.java 
b/linter/src/main/java/org/apache/royale/linter/LINTER.java
index 1cb85902d..85a855985 100644
--- a/linter/src/main/java/org/apache/royale/linter/LINTER.java
+++ b/linter/src/main/java/org/apache/royale/linter/LINTER.java
@@ -89,6 +89,7 @@ import org.apache.royale.linter.rules.TraceRule;
 import org.apache.royale.linter.rules.UnsafeNegationRule;
 import org.apache.royale.linter.rules.ValidTypeofRule;
 import org.apache.royale.linter.rules.VariablesOnTopRule;
+import org.apache.royale.linter.rules.VoidOperatorRule;
 import org.apache.royale.linter.rules.WildcardImportRule;
 import org.apache.royale.linter.rules.WithRule;
 import org.apache.royale.utils.FilenameNormalization;
@@ -378,6 +379,9 @@ public class LINTER {
                        if (configuration.getVarsOnTop()) {
                                rules.add(new VariablesOnTopRule());
                        }
+                       if (configuration.getVoidOperator()) {
+                               rules.add(new VoidOperatorRule());
+                       }
                        if (configuration.getWildcardImport()) {
                                rules.add(new WildcardImportRule());
                        }
diff --git 
a/linter/src/main/java/org/apache/royale/linter/config/Configuration.java 
b/linter/src/main/java/org/apache/royale/linter/config/Configuration.java
index 9459b370a..53498ec5c 100644
--- a/linter/src/main/java/org/apache/royale/linter/config/Configuration.java
+++ b/linter/src/main/java/org/apache/royale/linter/config/Configuration.java
@@ -874,6 +874,22 @@ public class Configuration {
         this.varsOnTop = b;
     }
 
+    //
+    // 'void-operator' option
+    //
+
+    private boolean voidOperator = false;
+
+    public boolean getVoidOperator() {
+        return voidOperator;
+    }
+
+    @Config
+    @Mapping("void-operator")
+    public void setVoidOperator(ConfigurationValue cv, boolean b) {
+        this.voidOperator = b;
+    }
+
     //
     // 'wildcard-import' option
     //
diff --git 
a/linter/src/main/java/org/apache/royale/linter/rules/VoidOperatorRule.java 
b/linter/src/main/java/org/apache/royale/linter/rules/VoidOperatorRule.java
new file mode 100644
index 000000000..5c1788dc7
--- /dev/null
+++ b/linter/src/main/java/org/apache/royale/linter/rules/VoidOperatorRule.java
@@ -0,0 +1,64 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package org.apache.royale.linter.rules;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.royale.compiler.problems.CompilerProblem;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.tree.ASTNodeID;
+import org.apache.royale.compiler.tree.as.IOperatorNode.OperatorType;
+import org.apache.royale.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.NodeVisitor;
+import org.apache.royale.linter.TokenQuery;
+
+/**
+ * Checks for uses of 'void' operator. Using 'void' as return type is allowed.
+ */
+public class VoidOperatorRule extends LinterRule {
+       @Override
+       public Map<ASTNodeID, NodeVisitor> getNodeVisitors() {
+               Map<ASTNodeID, NodeVisitor> result = new HashMap<>();
+               result.put(ASTNodeID.Op_VoidID, (node, tokenQuery, problems) -> 
{
+                       checkUnaryOperatorNode((IUnaryOperatorNode) node, 
tokenQuery, problems);
+               });
+               return result;
+       }
+
+       private void checkUnaryOperatorNode(IUnaryOperatorNode 
unaryOperatorNode, TokenQuery tokenQuery,
+                       Collection<ICompilerProblem> problems) {
+               if (!OperatorType.VOID.equals(unaryOperatorNode.getOperator())) 
{
+                       return;
+               }
+               problems.add(new VoidOperatorLinterProblem(unaryOperatorNode));
+       }
+
+       public static class VoidOperatorLinterProblem extends CompilerProblem {
+               public static final String DESCRIPTION = "Must not use 'void' 
operator";
+
+               public VoidOperatorLinterProblem(IUnaryOperatorNode node)
+               {
+                       super(node);
+               }
+       }
+}

Reply via email to