Skip to content

Commit

Permalink
Ensures that there is at least one character before default matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mnhock authored and mnhock committed Jun 20, 2024
1 parent 3e2d595 commit 52a266e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/enofex/taikai/internal/Modifiers.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ public static boolean isFieldProtected(JavaField field) {
public static boolean isFieldFinal(JavaField field) {
return field.getModifiers().contains(JavaModifier.FINAL);
}

/**
* Checks if a field is synthetic.
*
* @param field the Java field to check
* @return true if the field is synthetic, false otherwise
*/
public static boolean isFieldSynthetic(JavaField field) {
return field.getModifiers().contains(JavaModifier.SYNTHETIC);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/enofex/taikai/java/ConstantNaming.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enofex.taikai.java;

import static com.enofex.taikai.internal.Modifiers.isFieldSynthetic;

import com.tngtech.archunit.core.domain.JavaField;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ConditionEvents;
Expand All @@ -17,7 +19,7 @@ static ArchCondition<JavaField> shouldFollowConstantNamingConvention() {
return new ArchCondition<>("follow constant naming convention") {
@Override
public void check(JavaField field, ConditionEvents events) {
if (!field.getOwner().isEnum()
if (!isFieldSynthetic(field)
&& !"serialVersionUID".equals(field.getName())
&& !CONSTANT_NAME_PATTERN.matcher(field.getName()).matches()) {
events.add(SimpleConditionEvent.violated(field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public final class ConfigurationsConfigurer extends AbstractConfigurer {

private static final String DEFAULT_CONFIGURATION_NAME_MATCHING = ".*Configuration";
private static final String DEFAULT_CONFIGURATION_NAME_MATCHING = ".+Configuration";

ConfigurationsConfigurer(ConfigurerContext configurerContext) {
super(configurerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public final class ControllersConfigurer extends AbstractConfigurer {

private static final String DEFAULT_CONTROLLER_NAME_MATCHING = ".*Controller";
private static final String DEFAULT_CONTROLLER_NAME_MATCHING = ".+Controller";

ControllersConfigurer(ConfigurerContext configurerContext) {
super(configurerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public final class RepositoriesConfigurer extends AbstractConfigurer {

private static final String DEFAULT_REPOSITORY_NAME_MATCHING = ".*Repository";
private static final String DEFAULT_REPOSITORY_NAME_MATCHING = ".+Repository";

RepositoriesConfigurer(ConfigurerContext configurerContext) {
super(configurerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public final class ServicesConfigurer extends AbstractConfigurer {

private static final String DEFAULT_SERVICE_NAME_MATCHING = ".*Service";
private static final String DEFAULT_SERVICE_NAME_MATCHING = ".+Service";

ServicesConfigurer(ConfigurerContext configurerContext) {
super(configurerContext);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/enofex/taikai/test/JUnit5Configurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import static com.enofex.taikai.test.JUnit5DescribedPredicates.ANNOTATION_PARAMETRIZED_TEST;
import static com.enofex.taikai.test.JUnit5DescribedPredicates.ANNOTATION_TEST;
import static com.enofex.taikai.test.JUnit5DescribedPredicates.annotatedWithTestOrParameterizedTest;
import static com.tngtech.archunit.base.DescribedPredicate.not;
import static com.tngtech.archunit.lang.conditions.ArchConditions.beInterfaces;

import static com.tngtech.archunit.lang.conditions.ArchPredicates.are;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
Expand Down Expand Up @@ -45,7 +48,7 @@ public JUnit5Configurer classesShouldBePackagePrivate(String regex) {

public JUnit5Configurer classesShouldBePackagePrivate(String regex, Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().haveNameMatching(regex)
.that().areNotInterfaces().and().haveNameMatching(regex)
.should().bePackagePrivate()
.as("Classes with names matching %s should be package-private".formatted(regex)),
configuration));
Expand Down

0 comments on commit 52a266e

Please sign in to comment.