Skip to content

Commit

Permalink
Issue #11214: Specified violation messages in VariableDeclarationUsag…
Browse files Browse the repository at this point in the history
…eDistanceCheck
  • Loading branch information
jxr98 authored and romani committed Mar 17, 2023
1 parent ae21018 commit b2e5cb2
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public final class InlineConfigParser {
"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck",
"com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheck",
"com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck",
"com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck",
"com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck"));
"com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck"));

/**
* Inlined configs can not be used in non-java checks, as Inlined config is java style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int howMany1(int k) {
}

case 2: {
int arg = 9; // violation
int arg = 9; // violation 'Distance .* is 2.'
int d = 0;
for (int i = 0; i < 10; i++) {
d++;
Expand Down Expand Up @@ -77,8 +77,8 @@ int howMany1(int k) {
default: {
int b = 0;
int c = 0;
int m = 0; // violation
int n = 0; // violation
int m = 0; // violation 'Distance between .* declaration and its first usage is 3.'
int n = 0; // violation 'Distance between .* declaration and its first usage is 2.'
{
c++;
b++;
Expand Down Expand Up @@ -110,7 +110,7 @@ int howMany2(int k) {
yield 2;
}
case 2 -> {
int arg = 9; // violation
int arg = 9; // violation 'Distance .* is 2.'
int d = 0;
for (int i = 0; i < 10; i++) {
d++;
Expand Down Expand Up @@ -152,8 +152,8 @@ int howMany2(int k) {
default -> {
int b = 0;
int c = 0;
int m = 0; // violation
int n = 0; // violation
int m = 0; // violation 'Distance between .* declaration and its first usage is 3.'
int n = 0; // violation 'Distance between .* declaration and its first usage is 2.'
{
c++;
b++;
Expand All @@ -174,7 +174,7 @@ public boolean equals1(Object obj) {
int b = 6;
switch (i) {
case 1:
int count; // violation
int count; // violation 'Distance between .* declaration and its first usage is 3.'
a = a + b;
b = a + a;
count = b;
Expand All @@ -194,7 +194,7 @@ public boolean equals2(Object obj) {
int b = 6;
switch (i) {
case 1 -> {
int count; // violation
int count; // violation 'Distance between .* declaration and its first usage is 3.'
a = a + b;
b = a + a;
count = b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testMethod2() {
}

public void testMethod3() {
int count; // violation
int count; // violation 'Distance between .* declaration and its first usage is 4.'
int a = 3;
int b = 3;
a = a + b;
Expand Down Expand Up @@ -228,7 +228,7 @@ public void testMethod13() {

public void testMethod14() {
Session s = openSession();
Transaction t = s.beginTransaction(); // violation
Transaction t = s.beginTransaction(); // violation 'Distance .* is 5.'
A a = new A();
E d1 = new E();
C1 c = new C1();
Expand Down Expand Up @@ -488,7 +488,7 @@ public void testIssue32_8(Writer w1, Writer w2, Writer w3) {

public void testIssue32_9() {
Options options = new Options();
Option myOption = null; // violation
Option myOption = null; // violation 'Distance .* is 7.'
options.addBindFile(null);
options.addBindFile(null);
options.addBindFile(null);
Expand All @@ -500,7 +500,7 @@ public void testIssue32_9() {

public void testIssue32_10() {
Options options = new Options();
Option myOption = null; // violation
Option myOption = null; // violation 'Distance .* is 6.'
options.addBindFile(null);
options.addBindFile(null);
options.addBindFile(null);
Expand All @@ -513,7 +513,7 @@ public void testIssue32_10() {
public int testIssue32_11(String toDir)
throws Exception
{
int count = 0; // violation
int count = 0; // violation 'Distance .* is 4.'
String[] files = {};

System.identityHashCode("Data archival started");
Expand Down Expand Up @@ -900,7 +900,7 @@ void d() {
}

void f() {
int a = 1; // violation
int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
System.lineSeparator();
System.lineSeparator();
System.lineSeparator();
Expand All @@ -910,7 +910,7 @@ void f() {
}

void h() {
int a = 1; // violation
int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
System.lineSeparator();
System.lineSeparator();
System.lineSeparator();
Expand Down Expand Up @@ -976,7 +976,7 @@ void l() {
}

void tryWithoutFinally() {
int a = 1; // violation
int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
System.lineSeparator();
System.lineSeparator();
System.lineSeparator();
Expand Down Expand Up @@ -1063,7 +1063,7 @@ private void launch(Integer number ) {
static int field;

private void n() {
long a = 0; // violation
long a = 0; // violation 'Distance between .* declaration and its first usage is 4.'

New2.field = 1;
New2.field = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class InputVariableDeclarationUsageDistanceAnonymous {
public void method() {
JMenuItem prefs = new JMenuItem("Preferences..."); // violation
JMenuItem prefs = new JMenuItem("Preferences..."); // violation 'Distance .* is 4.'

nothing();
nothing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testMethod2() {
}

public void testMethod3() {
int count; // violation
int count; // violation 'Distance between .* declaration and its first usage is 4.'
int a = 3;
int b = 3;
a = a + b;
Expand Down Expand Up @@ -228,7 +228,7 @@ public void testMethod13() {

public void testMethod14() {
Session s = openSession();
Transaction t = s.beginTransaction(); // violation
Transaction t = s.beginTransaction(); // violation 'Distance .* is 5.'
A a = new A();
E d1 = new E();
C1 c = new C1();
Expand Down Expand Up @@ -488,7 +488,7 @@ public void testIssue32_8(Writer w1, Writer w2, Writer w3) {

public void testIssue32_9() {
Options options = new Options();
Option myOption = null; // violation
Option myOption = null; // violation 'Distance .* is 7.'
options.addBindFile(null);
options.addBindFile(null);
options.addBindFile(null);
Expand All @@ -500,7 +500,7 @@ public void testIssue32_9() {

public void testIssue32_10() {
Options options = new Options();
Option myOption = null; // violation
Option myOption = null; // violation 'Distance .* is 6.'
options.addBindFile(null);
options.addBindFile(null);
options.addBindFile(null);
Expand Down Expand Up @@ -551,7 +551,7 @@ private TreeMapNode buildTree(Object[][] tree)
for (Object[] s : tree) {
Integer id = (Integer) s[0];
String label = (String) s[1];
Integer parentId = (Integer) s[2]; // violation
Integer parentId = (Integer) s[2]; // violation 'Distance .* is 4.'
Number weight = (Number) s[3];
Number value = (Number) s[4];
Integer childCount = (Integer) s[5];
Expand Down Expand Up @@ -1033,7 +1033,7 @@ void test() {
System.identityHashCode(b);
}

int c = 0; // violation
int c = 0; // violation 'Distance .* is 4.'
System.lineSeparator();
System.lineSeparator();
System.lineSeparator();
Expand Down Expand Up @@ -1063,7 +1063,7 @@ private void launch(Integer number ) {
static int field;

private void n() {
long a = 0; // violation
long a = 0; // violation 'Distance .* is 4.'

New6.field = 1;
New6.field = 2;
Expand Down

0 comments on commit b2e5cb2

Please sign in to comment.