Skip to content

Commit

Permalink
Merge branch 'release/2.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasPohl committed Dec 8, 2018
2 parents 31ca4d3 + 9db4b31 commit 1c632b6
Show file tree
Hide file tree
Showing 78 changed files with 1,052 additions and 477 deletions.
2 changes: 1 addition & 1 deletion esql-checks-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.exxeta.iss</groupId>
<artifactId>sonar-esql-plugin</artifactId>
<version>2.3.4</version>
<version>2.3.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion esql-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.exxeta.iss</groupId>
<artifactId>sonar-esql-plugin</artifactId>
<version>2.3.4</version>
<version>2.3.5</version>
</parent>

<artifactId>esql-checks</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import static com.exxeta.iss.sonar.esql.api.tree.Tree.Kind.INDEX;
/**
* This Java class is created to implement the logic for all binary operators
* should be separated from their operands by spaces.
Expand All @@ -49,7 +50,7 @@ public class BinaryOperatorSeparatedBySpaceCheck extends SubscriptionVisitorChec
@Override
public void visitNode(Tree tree) {
String token =((InternalSyntaxToken)tree).text();
if (BINARY_OPERATOR.contains(token) || SPACE_AFTER.contains(token)) {
if ((BINARY_OPERATOR.contains(token) || SPACE_AFTER.contains(token)) && !tree.parent().is(INDEX)) {
Iterator<Tree> childIterator = tree.parent().childrenStream().iterator();
Tree prevChild = null;
while (childIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public static List<Class> getChecks() {
TrailingCommentsCheck.class,
CommentsCheck.class,
DeclareCombineCheck.class,
BinaryOperatorSeparatedBySpaceCheck.class
BinaryOperatorSeparatedBySpaceCheck.class,
TrailingWhitespaceCheck.class



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
*/
package com.exxeta.iss.sonar.esql.check;

import java.util.List;

import org.sonar.check.Rule;

import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;
import com.exxeta.iss.sonar.esql.api.tree.statement.CreateModuleStatementTree;
import com.exxeta.iss.sonar.esql.api.tree.statement.StatementTree;
import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CreateRoutineTreeImpl;

/**
* This java class is created to implement the logic for checking there should be one blank line between procedure and function.
Expand All @@ -37,34 +36,23 @@ public class InsertBlankLineBetweenFuncProcCheck extends DoubleDispatchVisitorCh
private static final String MESSAGE = "Insert one blank line between functions and procedures.";


@Override
public void visitProgram(ProgramTree tree) {
EsqlFile file = getContext().getEsqlFile();
List<String> lines = CheckUtils.readLines(file);

int linecounter = 0;
for (String line : lines) {

linecounter = linecounter + 1;


if(isEndStatement(line)){


if(linecounter<lines.size()){
String nextLine = lines.get(linecounter);

if(!nextLine.trim().isEmpty()){
addIssue(new LineIssue(this, linecounter, MESSAGE));
}

@Override
public void visitCreateModuleStatement(CreateModuleStatementTree tree) {
StatementTree previousStatement = null;
for (StatementTree statement : tree.moduleStatementsList().statements()) {
if (statement instanceof CreateRoutineTreeImpl && previousStatement instanceof CreateRoutineTreeImpl) {
if (!(previousStatement.lastToken().endLine()<statement.firstToken().line()-1)) {
addIssue(new LineIssue(this, previousStatement.lastToken(), MESSAGE));
}
}
}
}

public static boolean isEndStatement(String s) {
String withoutSpace = s.replace(" ", "").toUpperCase();
return withoutSpace.contains("END;");
previousStatement=statement;
}
if (previousStatement instanceof CreateRoutineTreeImpl && !(previousStatement.lastToken().endLine() < tree.endKeyword().line()-1)) {
addIssue(new LineIssue(this, previousStatement.lastToken(), MESSAGE));
}

super.visitCreateModuleStatement(tree);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import org.sonar.check.Rule;
Expand Down Expand Up @@ -137,15 +138,15 @@ private void processSingleModuleForReferences( int startingLine, List<String> m
}
}
} while(true);
iterator = allKeys.keySet().iterator();
Iterator<Entry<String, Integer>> entrySetIterator = allKeys.entrySet().iterator();

while (iterator.hasNext())
while (entrySetIterator.hasNext())
{
String key = iterator.next();
Integer count = allKeys.get(key);
Entry<String, Integer> entry = entrySetIterator.next();
Integer count = entry.getValue();
if(count.intValue() > threshold )
{
Integer lineNumber = CheckUtils.findLineInText(moduleLines, key);
Integer lineNumber = CheckUtils.findLineInText(moduleLines, entry.getKey());
if(lineNumber != null){
Integer absLine = Integer.valueOf(lineNumber.intValue() + startingLine);
violatingLinesWithPossibleReference.add(absLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 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
* 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,
Expand All @@ -17,17 +17,11 @@
*/
package com.exxeta.iss.sonar.esql.check;

import java.util.List;
import java.util.regex.Pattern;

import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree;
import com.exxeta.iss.sonar.esql.api.tree.statement.SetStatementTree;
import org.sonar.check.Rule;

import com.exxeta.iss.sonar.esql.api.tree.ProgramTree;

import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;

import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;

/**
* This java class is created to implement the logic to check sub-elements
Expand All @@ -46,48 +40,25 @@ public class SubElementNameCheck extends DoubleDispatchVisitorCheck {
private static final String LOWERCASE_FORMAT = "^[a-z][a-zA-Z0-9]*$";

@Override
public void visitProgram(ProgramTree tree) {
EsqlFile file = getContext().getEsqlFile();
List<String> lines = CheckUtils.readLines(file);
int i = 0;
for (String line : lines) {
i = i + 1;

if (line.trim().startsWith("SET Environment")) {

String[] strArr1 = line.split(Pattern.quote("="));

if (strArr1.length > 0) {

String envSubElement = strArr1[0];
String envSubElement1 = null;
if (!(line.indexOf("Environment") + 12 > line.length())) {
if (!(line.indexOf("Environment") + 12 > envSubElement.length())) {
envSubElement1 = envSubElement.substring(line.indexOf("Environment") + 12, line.indexOf('='));
public void visitSetStatement(SetStatementTree tree) {
if (tree.variableReference() instanceof FieldReferenceTree) {
FieldReferenceTree fieldRef = (FieldReferenceTree) tree.variableReference();
if ("Environment".equalsIgnoreCase(fieldRef.pathElement().name().name().name())) {
int subElementsSize = fieldRef.pathElements().size();
if (subElementsSize > 0) {
for (int i = 0; i < subElementsSize - 1; i++) {
String subElement = fieldRef.pathElements().get(i).name().name().name();
if (!subElement.matches(UPPERCASE_FORMAT)) {
addIssue(tree, MESSAGE);
}
String[] strArray = envSubElement1.split(Pattern.quote("."));

int strCount = 0;
for (String str : strArray) {
strCount++;

if (!str.matches(UPPERCASE_FORMAT) && (strCount != strArray.length)) {

addIssue(new LineIssue(this, i, MESSAGE));
}

}

String lastElement = strArray[strArray.length - 1].trim();
if (!lastElement.matches(LOWERCASE_FORMAT)) {
addIssue(new LineIssue(this, i, MESSAGE));
}

}
String lastElement = fieldRef.pathElements().get(subElementsSize - 1).name().name().name();
if (!lastElement.matches(LOWERCASE_FORMAT)) {
addIssue(tree, MESSAGE);
}
}

}
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Sonar ESQL Plugin
* Copyright (C) 2013-2018 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed 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 com.exxeta.iss.sonar.esql.check;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import org.sonar.check.Rule;

import com.exxeta.iss.sonar.esql.api.tree.Tree;
import com.exxeta.iss.sonar.esql.api.visitors.EsqlFile;
import com.exxeta.iss.sonar.esql.api.visitors.LineIssue;
import com.exxeta.iss.sonar.esql.api.visitors.SubscriptionVisitorCheck;
import com.exxeta.iss.sonar.esql.lexer.EsqlLexer;


@Rule(key = "TrailingWhitespace")
public class TrailingWhitespaceCheck extends SubscriptionVisitorCheck {

private static final String MESSAGE = "Remove the useless trailing whitespaces at the end of this line.";

@Override
public Set<Tree.Kind> nodesToVisit() {
return Collections.emptySet();
}

@Override
public void visitFile(Tree scriptTree) {
EsqlFile javaScriptFile = getContext().getEsqlFile();
List<String> lines = CheckUtils.readLines(javaScriptFile);

for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);

if (line.length() > 0 && Pattern.matches("[" + EsqlLexer.WHITESPACE + "]", line.subSequence(line.length() - 1, line.length()))) {
addIssue(new LineIssue(this, i + 1, MESSAGE));
}
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@Rule(key = "UnusedVariable")
public class UnusedVariableCheck extends DoubleDispatchVisitorCheck {

private static final String MESSAGE = "Remove the unused Variable.";
private static final String MESSAGE = "Remove the unused '%s' variable.";

@Override
public void visitProgram(ProgramTree tree) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>Trailing whitespaces are simply useless and should not stay in code. They may generate noise when comparing different versions of the same
file.</p>
<p>If you encounter issues from this rule, this probably means that you are not using an automated code formatter - which you should if you have the
opportunity to do so. </p>
<h2>Noncompliant Code Example</h2>
<pre>
-- The following string will error if there is a whitespace after '\'
SET str = 'Hello \
World';
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"title": "Lines should not end with trailing whitespaces",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "1min"
},
"tags": [
"convention"
],
"defaultSeverity": "Minor",
"ruleSpecification": "RSPEC-1131",
"sqKey": "S1131"
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void test() throws Exception {
.next().atLine(14).withMessage("Remove this commented out code.")
.next().atLine(18).withMessage("Remove this commented out code.")
.next().atLine(22).withMessage("Remove this commented out code.")
.next().atLine(32).withMessage("Remove this commented out code.")
.next().atLine(35).withMessage("Remove this commented out code.")
.noMore();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class SubElementNameCheckTest {
public void test() {
EsqlCheck check = new SubElementNameCheck();
EsqlCheckVerifier.issues(check, new File("src/test/resources/SubElementName.esql"))
.next().atLine(5).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.")
.next().atLine(6).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.").noMore();
.next().atLine(5).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.")
.next().atLine(6).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.")
.next().atLine(9).withMessage("sub-elements should be in UpperCamel-case and elements containing simple value should be in lowercase.").noMore();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void test() {
EsqlCheckVerifier.issues(check, new File("src/test/resources/leaveIterate.esql"))
.next().atLine(7).withMessage("Loops should not contain more than a single \"ITERATE\" or \"LEAVE\" statement.")
.next().atLine(25).withMessage("Loops should not contain more than a single \"ITERATE\" or \"LEAVE\" statement.")
.next().atLine(66).withMessage("Loops should not contain more than a single \"ITERATE\" or \"LEAVE\" statement.")
.noMore();
}
}
Loading

0 comments on commit 1c632b6

Please sign in to comment.