SmartBear / soapui

SoapUI is a free and open source cross-platform functional testing solution for APIs and web services.
http://www.soapui.org
Other
1.56k stars 607 forks source link

[RSPEC-1940] Boolean checks should not be inverted. #791

Open jlerbsc opened 9 months ago

jlerbsc commented 9 months ago

First of all I'd like to say that, as a contributor to an Open Source project, I'm very grateful for the work you do and the benefits you bring to the community.

Please don't be angry with me for the rest of my comments, my intention is just to make a small contribution to your project by demonstrating the usefulness of the product we've developed, the main aim of which is to significantly improve the quality of developments.

This tool is completely free for open source projects. It is very easy to use and you can use it on your own. If you want to quickly improve the quality of your project, you can find all the information you need at https://www.indepth.fr

The documentation on this rule is here https://www.indepth.fr/documentation.html#BooleanChecksShouldNotBeInvertedRule

We used our automatic code remediation solution to check whether the project's source code contained violations of certain Sonar rules. In particular, the tool detected 3 violations of the rule "Boolean checks should not be inverted.". Given the small number of violations, you can make these changes manually... But there are also a larger number of violations that would require automatic modifications.

com\eviware\soapui\impl\wsdl\panels\teststeps\support\PropertyHolderTable.java
@@ -358,5  +358,5 @@

                while (line != null) {
\-                        if (line.trim().length() > 0 && !(line.charAt(0) == '#')) {
\+                        if (line.trim().length() > 0 && line.charAt(0) != '#') {
                        int ix = line.indexOf('=');
                        if (ix > 0) {
@@ -448,5  +448,5 @@
    private File ensurePathExistsAndIsDirectory(String path) {
        File file = new File(path);
\-            while (!(file == null) && !file.exists()) {
\+            while (file != null && !file.exists()) {
            file = file.getParentFile();
        }

com\eviware\soapui\support\dnd\SoapUIDragAndDropHandler.java
@@ -287,5  +287,5 @@
        }

\-            if (!(modelItem == _pathLast)) {
\+            if (modelItem != _pathLast) {
            // movement trend
            _pathLast = modelItem;
jlerbsc commented 9 months ago

We also noticed that you had 60 violations of rule [S2129] Constructors should not be used to instantiate 'String', 'BigInteger', 'BigDecimal' and primitive-wrapper classes.

This fix eliminates the need to use the constructor for objects that wrap primitives, which improves the readability of the code and the memory footprint.

https://indepth.fr/documentation.html#ConstructorsShouldNotBeUsedToInstantiateRule

jlerbsc commented 9 months ago

You also have 151 violations of rule [S1148] Throwable.printStackTrace(...) should never be called.

https://www.indepth.fr/documentation.html#BooleanChecksShouldNotBeInvertedRule

jlerbsc commented 9 months ago

You also have 60 violations of the rule [S1130] "throws" declarations should not be superfluous

https://www.indepth.fr/documentation.html#ThrowsDeclarationsShouldNotBeSuperfluousRule

jlerbsc commented 9 months ago

You can also improve the readability of some methods by applying the following patches which correct the Sonar RSPEC-2692 violation "Checking if a value is included in a String or List using indexOf(value)>-1 or indexOf(value)>=0 can be replaced with contains(value)"

com\eviware\soapui\impl\wsdl\support\PathUtils.java
@@ -159,5  +159,5 @@
    }
\-        if (StringUtils.isNullOrEmpty(project.getPath()) && project.getResourceRoot().indexOf("${projectDir}") >= 0) {
\+        if (StringUtils.isNullOrEmpty(project.getPath()) && project.getResourceRoot().contains("${projectDir}")) {
        if (UISupport.confirm("Save project before setting path?", "Project has not been saved")) {
            try {

com\eviware\soapui\model\propertyexpansion\PropertyExpansionUtils.java
@@ -460,5  +460,5 @@
public static boolean containsPropertyExpansion(String str) {
\-        return str != null && str.indexOf("${") >= 0 && str.indexOf('}') > 2;
\+        return str != null && str.contains("${") && str.indexOf('}') > 2;
}
}

com\eviware\soapui\support\SecurityScanUtil.java
@@ -101,5  +101,5 @@
            }
        } else {
\-                if (content.toUpperCase().indexOf(replToken.toUpperCase()) >= 0) {
\+                if (content.toUpperCase().contains(replToken.toUpperCase())) {
                result = replToken;
            }