Merge branch 'master' into pmd/7.0.x
This commit is contained in:
commit
2c3f945b4d
@ -7088,6 +7088,25 @@
|
||||
"contributions": [
|
||||
"bug"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "pguyot",
|
||||
"name": "Paul Guyot",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/168407?v=4",
|
||||
"profile": "http://paul-guyot.com/",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "dawiddc",
|
||||
"name": "Dawid Ciok",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/26235980?v=4",
|
||||
"profile": "https://github.com/dawiddc",
|
||||
"contributions": [
|
||||
"bug",
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
@ -17,12 +17,12 @@ It uses JavaCC and Antlr to parse source files into abstract syntax trees (AST)
|
||||
Rules can be written in Java or using a XPath query.
|
||||
|
||||
It supports Java, JavaScript, Salesforce.com Apex and Visualforce,
|
||||
Modelica, PLSQL, Apache Velocity, XML, XSL.
|
||||
Modelica, PLSQL, Apache Velocity, HTML, XML and XSL.
|
||||
Scala is supported, but there are currently no Scala rules available.
|
||||
|
||||
Additionally it includes **CPD**, the copy-paste-detector. CPD finds duplicated code in
|
||||
C/C++, C#, Dart, Fortran, Go, Groovy, Java, JavaScript, JSP, Kotlin, Lua, Matlab, Modelica,
|
||||
Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift, Visualforce and XML.
|
||||
Additionally, it includes **CPD**, the copy-paste-detector. CPD finds duplicated code in
|
||||
C/C++, C#, Dart, Fortran, Gherkin, Go, Groovy, HTML, Java, JavaScript, JSP, Kotlin, Lua, Matlab, Modelica,
|
||||
Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex and Visualforce, Scala, Swift, T-SQL and XML.
|
||||
|
||||
In the future we hope to add support for data/control flow analysis and automatic (quick) fixes where
|
||||
it makes sense.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,18 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### New and noteworthy
|
||||
|
||||
#### T-SQL support
|
||||
Thanks to the contribution from [Paul Guyot](https://github.com/pguyot) PMD now has CPD support
|
||||
for T-SQL (Transact-SQL).
|
||||
|
||||
Being based on a proper Antlr grammar, CPD can:
|
||||
|
||||
* ignore comments
|
||||
* honor [comment-based suppressions](pmd_userdocs_cpd.html#suppression)
|
||||
|
||||
### Fixed Issues
|
||||
* java-errorprone
|
||||
* [#4393](https://github.com/pmd/pmd/issues/4393): \[java] MissingStaticMethodInNonInstantiatableClass false-positive for Lombok's @UtilityClass for classes with non-private fields
|
||||
|
||||
### API Changes
|
||||
|
||||
@ -30,6 +41,8 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### External Contributions
|
||||
* [#4384](https://github.com/pmd/pmd/pull/4384): \[swift] Add more swift 5.x support (#unavailable mainly) - [Richard B.](https://github.com/kenji21) (@kenji21)
|
||||
* [#4390](https://github.com/pmd/pmd/pull/4390): Add support for T-SQL using Antlr4 lexer - [Paul Guyot](https://github.com/pguyot) (@pguyot)
|
||||
* [#4392](https://github.com/pmd/pmd/pull/4392): \[java] Fix #4393 MissingStaticMethodInNonInstantiatableClass: Fix false-positive for field-only class - [Dawid Ciok](https://github.com/dawiddc) (@dawiddc)
|
||||
|
||||
{% endtocmaker %}
|
||||
|
||||
|
@ -267,6 +267,11 @@
|
||||
<artifactId>pmd-swift</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-tsql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-ui</artifactId>
|
||||
|
@ -28,7 +28,8 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
SUPPORTED_LANGUAGES_CPD = "Valid values: apex, cpp, cs, dart, ecmascript," + System.lineSeparator()
|
||||
+ " fortran, gherkin, go, groovy, html, java, jsp," + System.lineSeparator()
|
||||
+ " kotlin, lua, matlab, modelica, objectivec, perl," + System.lineSeparator()
|
||||
+ " php, plsql, python, ruby, scala, swift, vf, xml";
|
||||
+ " php, plsql, python, ruby, scala, swift, tsql," + System.lineSeparator()
|
||||
+ " vf, xml";
|
||||
SUPPORTED_LANGUAGES_PMD = "Valid values: apex-54, ecmascript-ES6, html-," + System.lineSeparator()
|
||||
+ " java-1.10, java-1.3, java-1.4, java-1.5, java-1." + System.lineSeparator()
|
||||
+ " 6, java-1.7, java-1.8, java-1.9, java-10," + System.lineSeparator()
|
||||
|
@ -2355,12 +2355,23 @@ See the property `annotations`.
|
||||
[pmd-java:hasAnnotation('lombok.experimental.UtilityClass')]
|
||||
[ClassOrInterfaceBody
|
||||
[
|
||||
(: no methods :)
|
||||
not(MethodDeclaration)
|
||||
or
|
||||
(: only private methods :)
|
||||
count(MethodDeclaration) = count(MethodDeclaration[@Private=true()])
|
||||
]
|
||||
(
|
||||
(: no methods :)
|
||||
not(MethodDeclaration)
|
||||
or
|
||||
(: only private methods :)
|
||||
count(MethodDeclaration) = count(MethodDeclaration[@Private=true()])
|
||||
)
|
||||
and
|
||||
(
|
||||
(: no fields :)
|
||||
not(FieldDeclaration)
|
||||
or
|
||||
(: only private fields :)
|
||||
count(FieldDeclaration) = count(FieldDeclaration[@Private=true()])
|
||||
|
||||
)
|
||||
]
|
||||
]
|
||||
|
|
||||
//ClassOrInterfaceDeclaration[@Nested= false() and @Local= false()]
|
||||
|
@ -453,6 +453,45 @@ public final class Test {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#4393 [java] MissingStaticMethodInNonInstantiatableClass should consider lombok's UtilityClass</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public final class Test {
|
||||
int x;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#4393 [java] MissingStaticMethodInNonInstantiatableClass should consider lombok's UtilityClass</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public final class Test {
|
||||
public static final String CONSTANT = "Constant";
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#4393 [java] MissingStaticMethodInNonInstantiatableClass should consider lombok's UtilityClass</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public final class Test {
|
||||
private static final String CONSTANT = "Constant";
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#4225 [java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @NoArgsConstructor</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
|
57
pmd-tsql/pom.xml
Normal file
57
pmd-tsql/pom.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pmd-tsql</artifactId>
|
||||
<name>PMD TSql</name>
|
||||
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
<delimiters>
|
||||
<delimiter>${*}</delimiter>
|
||||
</delimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-lang-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql.ast;
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql.cpd;
|
||||
|
||||
// Copied from: https://github.com/antlr/antlr4/blob/4.9.1/doc/resources/CaseChangingCharStream.java
|
||||
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
|
||||
/**
|
||||
* This class supports case-insensitive lexing by wrapping an existing
|
||||
* {@link CharStream} and forcing the lexer to see either upper or
|
||||
* lowercase characters. Grammar literals should then be either upper or
|
||||
* lower case such as 'BEGIN' or 'begin'. The text of the character
|
||||
* stream is unaffected. Example: input 'BeGiN' would match lexer rule
|
||||
* 'BEGIN' if constructor parameter upper=true but getText() would return
|
||||
* 'BeGiN'.
|
||||
*/
|
||||
class CaseChangingCharStream implements CharStream {
|
||||
|
||||
final CharStream stream;
|
||||
final boolean upper;
|
||||
|
||||
/**
|
||||
* Constructs a new CaseChangingCharStream wrapping the given {@link CharStream} forcing
|
||||
* all characters to upper case or lower case.
|
||||
* @param stream The stream to wrap.
|
||||
* @param upper If true force each symbol to upper case, otherwise force to lower.
|
||||
*/
|
||||
CaseChangingCharStream(CharStream stream, boolean upper) {
|
||||
this.stream = stream;
|
||||
this.upper = upper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Interval interval) {
|
||||
return stream.getText(interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume() {
|
||||
stream.consume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int LA(int i) {
|
||||
int c = stream.LA(i);
|
||||
if (c <= 0) {
|
||||
return c;
|
||||
}
|
||||
if (upper) {
|
||||
return Character.toUpperCase(c);
|
||||
}
|
||||
return Character.toLowerCase(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int mark() {
|
||||
return stream.mark();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(int marker) {
|
||||
stream.release(marker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int index() {
|
||||
return stream.index();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(int index) {
|
||||
stream.seek(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return stream.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return stream.getSourceName();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql.cpd;
|
||||
|
||||
import net.sourceforge.pmd.cpd.AbstractLanguage;
|
||||
|
||||
/**
|
||||
* @author pguyot@kallisys.net
|
||||
*/
|
||||
public class TSqlLanguage extends AbstractLanguage {
|
||||
|
||||
public TSqlLanguage() {
|
||||
super("TSql", "tsql", new TSqlTokenizer(), ".sql");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql.cpd;
|
||||
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
|
||||
import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.lang.tsql.ast.TSqlLexer;
|
||||
|
||||
public class TSqlTokenizer extends AntlrTokenizer {
|
||||
|
||||
@Override
|
||||
protected Lexer getLexerForSource(CharStream charStream) {
|
||||
return new TSqlLexer(new CaseChangingCharStream(charStream, true));
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
net.sourceforge.pmd.lang.tsql.cpd.TSqlLanguage
|
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql.cpd;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.cpd.Tokenizer;
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
|
||||
public class TSqlTokenizerTest extends CpdTextComparisonTest {
|
||||
|
||||
public TSqlTokenizerTest() {
|
||||
super(".sql");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tokenizer newTokenizer(Properties properties) {
|
||||
return new TSqlTokenizer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResourcePrefix() {
|
||||
return "../cpd/testdata";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTest() {
|
||||
doTest("simple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mailJobTimeLineTest() {
|
||||
doTest("MailJobTimeLine");
|
||||
}
|
||||
}
|
685
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.sql
vendored
Normal file
685
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.sql
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2344
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.txt
vendored
Normal file
2344
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.sql
vendored
Normal file
5
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.sql
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
create procedure p (@v int) as begin
|
||||
declare @f int
|
||||
set @f = @v + 2
|
||||
select @f
|
||||
end
|
28
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.txt
vendored
Normal file
28
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.txt
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L1
|
||||
[create] 1 6
|
||||
[procedure] 8 16
|
||||
[p] 18 18
|
||||
[(] 20 20
|
||||
[@v] 21 22
|
||||
[int] 24 26
|
||||
[)] 27 27
|
||||
[as] 29 30
|
||||
[begin] 32 36
|
||||
L2
|
||||
[declare] 2 8
|
||||
[@f] 10 11
|
||||
[int] 13 15
|
||||
L3
|
||||
[set] 2 4
|
||||
[@f] 6 7
|
||||
[=] 9 9
|
||||
[@v] 11 12
|
||||
[+] 14 14
|
||||
[2] 16 16
|
||||
L4
|
||||
[select] 2 7
|
||||
[@f] 9 10
|
||||
L5
|
||||
[end] 1 3
|
||||
EOF
|
14
pom.xml
14
pom.xml
@ -9,12 +9,17 @@
|
||||
|
||||
<description>
|
||||
PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks,
|
||||
unnecessary object creation, and so forth. It supports Java, JavaScript, Salesforce.com Apex and Visualforce,
|
||||
Modelica, PLSQL, Apache Velocity, HTML, XML, XSL, Scala.
|
||||
unnecessary object creation, and so forth. It supports many languages. It can be extended with custom rules.
|
||||
It uses JavaCC and Antlr to parse source files into abstract syntax trees (AST) and runs rules against them to find violations.
|
||||
Rules can be written in Java or using a XPath query.
|
||||
|
||||
Additionally it includes CPD, the copy-paste-detector. CPD finds duplicated code in
|
||||
It supports Java, JavaScript, Salesforce.com Apex and Visualforce,
|
||||
Modelica, PLSQL, Apache Velocity, HTML, XML and XSL.
|
||||
Scala is supported, but there are currently no Scala rules available.
|
||||
|
||||
Additionally, it includes CPD, the copy-paste-detector. CPD finds duplicated code in
|
||||
C/C++, C#, Dart, Fortran, Gherkin, Go, Groovy, HTML, Java, JavaScript, JSP, Kotlin, Lua, Matlab, Modelica,
|
||||
Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift and Visualforce.
|
||||
Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex and Visualforce, Scala, Swift, T-SQL and XML.
|
||||
</description>
|
||||
|
||||
<url>https://pmd.github.io/</url>
|
||||
@ -1171,6 +1176,7 @@
|
||||
<module>pmd-swift</module>
|
||||
<module>pmd-test</module>
|
||||
<module>pmd-test-schema</module>
|
||||
<module>pmd-tsql</module>
|
||||
<module>pmd-visualforce</module>
|
||||
<module>pmd-vm</module>
|
||||
<module>pmd-xml</module>
|
||||
|
Loading…
x
Reference in New Issue
Block a user