-
Notifications
You must be signed in to change notification settings - Fork 0
add feature config #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb680be
add feature config
SirCotare 85fff61
1.2.0-RC1
aboutbits-tech 766dcb1
break up rules
SirCotare 44b0829
update deps
SirCotare 4a0206e
update rules and add new
SirCotare dd97568
remove version tag from junit-jupiter-params dependency
SirCotare 67b1df9
fix check to work for all classes extending SortMappings
SirCotare 3f1c49a
add utility methods to fetch line numbers from source code elements
SirCotare 96d4efa
replace direct line number fetching with `LineNumberUtil.getLineNumber`
SirCotare f951ffe
update ArchTest annotation to use fully qualified path
SirCotare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
530 changes: 0 additions & 530 deletions
530
src/main/java/it/aboutbits/archunit/toolbox/ArchitectureTestBase.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/main/java/it/aboutbits/archunit/toolbox/BaseArchRuleCollection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package it.aboutbits.archunit.toolbox; | ||
|
|
||
| import it.aboutbits.archunit.toolbox.rule.base.BlacklistAnnotationsArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.BlacklistClassesArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.BlacklistMethodsArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.EnforceJspecifyArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.NoSystemOutOrErrArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.RecordPropertiesMustBeAccessedViaAccessorArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.TestClassInCorrectPackageArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.TestClassVisibilityArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.TestMethodVisibilityArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.TestNestedClassMatchNameArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.base.TestNestedClassVisibilityArchRule; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @NullMarked | ||
| public interface BaseArchRuleCollection extends | ||
| BlacklistAnnotationsArchRule, | ||
| BlacklistClassesArchRule, | ||
| BlacklistMethodsArchRule, | ||
| EnforceJspecifyArchRule, | ||
| NoSystemOutOrErrArchRule, | ||
| RecordPropertiesMustBeAccessedViaAccessorArchRule, | ||
| TestClassInCorrectPackageArchRule, | ||
| TestClassVisibilityArchRule, | ||
| TestMethodVisibilityArchRule, | ||
| TestNestedClassMatchNameArchRule, | ||
| TestNestedClassVisibilityArchRule { | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/it/aboutbits/archunit/toolbox/CommonArchRuleCollection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package it.aboutbits.archunit.toolbox; | ||
|
|
||
| import it.aboutbits.archunit.toolbox.rule.common.ControllerRequestMappingsMustBeSecurityTested; | ||
| import it.aboutbits.archunit.toolbox.rule.common.SortMappingsExhaustiveArchRule; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @NullMarked | ||
| public interface CommonArchRuleCollection extends | ||
| ControllerRequestMappingsMustBeSecurityTested, | ||
| SortMappingsExhaustiveArchRule { | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/it/aboutbits/archunit/toolbox/config/ArchRuleConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package it.aboutbits.archunit.toolbox.config; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| @NullMarked | ||
| public final class ArchRuleConfig { | ||
| private ArchRuleConfig() { | ||
| } | ||
|
|
||
| /** | ||
| * List of supported test class name suffixes. | ||
| * <p> | ||
| * When introducing a new test type (e.g. IntegrationTest), add its suffix here | ||
| * instead of directly modifying the regex pattern. | ||
| **/ | ||
| public static final Set<String> TEST_CLASS_SUFFIXES = new HashSet<>( | ||
| Set.of( | ||
| "Test", | ||
| "CacheTest", | ||
| "EventTest", | ||
| "SecurityTest" | ||
| ) | ||
| ); | ||
| } |
141 changes: 141 additions & 0 deletions
141
src/main/java/it/aboutbits/archunit/toolbox/rule/base/BlacklistAnnotationsArchRule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| package it.aboutbits.archunit.toolbox.rule.base; | ||
|
|
||
| import com.tngtech.archunit.core.domain.JavaClass; | ||
| import com.tngtech.archunit.core.domain.JavaClasses; | ||
| import com.tngtech.archunit.junit.ArchTest; | ||
| import com.tngtech.archunit.lang.ArchCondition; | ||
| import com.tngtech.archunit.lang.ConditionEvents; | ||
| import com.tngtech.archunit.lang.SimpleConditionEvent; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
| import static it.aboutbits.archunit.toolbox.util.LineNumberUtil.getLineNumber; | ||
|
|
||
| @SuppressWarnings({"checkstyle:InterfaceIsType", "java:S1214"}) | ||
| @NullMarked | ||
| public interface BlacklistAnnotationsArchRule { | ||
| @SuppressWarnings("java:S2386") | ||
| Set<String> BLACKLISTED_ANNOTATIONS = new HashSet<>( | ||
| Set.of( | ||
| "org.junit.After", | ||
| "org.junit.AfterClass", | ||
| "org.junit.Before", | ||
| "org.junit.BeforeClass", | ||
| "org.junit.ClassRule", | ||
| "org.junit.FixMethodOrder", | ||
| "org.junit.Ignore", | ||
| "org.junit.Rule", | ||
| "org.junit.Test", | ||
| // @NonNull (allowed is only org.jspecify.annotations.NonNull) | ||
| "lombok.NonNull", | ||
| "edu.umd.cs.findbugs.annotations.NonNull", | ||
| "io.micrometer.common.lang.NonNull", | ||
| "io.micrometer.core.lang.NonNull", | ||
| "org.springframework.lang.NonNull", | ||
| "org.testcontainers.shaded.org.checkerframework.checker.nullness.qual.NonNull", | ||
| // @NotNull (allowed is only jakarta.validation.constraints.NotNull) | ||
| "com.drew.lang.annotations.NotNull", | ||
| "com.sun.istack.NotNull", | ||
| "org.antlr.v4.runtime.misc.NotNull", | ||
| "org.jetbrains.annotations.NotNull", | ||
| "software.amazon.awssdk.annotations.NotNull", | ||
| // @Nullable (allowed is only org.jspecify.annotations.Nullable) | ||
| "org.springframework.lang.Nullable", | ||
| "com.drew.lang.annotations.Nullable", | ||
| "com.sun.istack.Nullable", | ||
| "edu.umd.cs.findbugs.annotations.Nullable", | ||
| "io.micrometer.common.lang.Nullable", | ||
| "io.micrometer.core.lang.Nullable", | ||
| "jakarta.annotation.Nullable", | ||
| "javax.annotation.Nullable", | ||
| "org.jetbrains.annotations.Nullable", | ||
| "org.testcontainers.shaded.org.checkerframework.checker.nullness.qual.Nullable", | ||
| // @Transactional (allowed is only org.springframework.transaction.annotation.Transactional) | ||
| "jakarta.transaction.Transactional" | ||
| ) | ||
| ); | ||
|
|
||
| @SuppressWarnings({"unused", "checkstyle:MethodName", "java:S100"}) | ||
| @ArchTest | ||
| default void no_blacklisted_annotations_are_used(JavaClasses classes) { | ||
| classes() | ||
| .should(new NotUseBlacklistedAnnotations()) | ||
| .check(classes); | ||
| } | ||
|
|
||
| class NotUseBlacklistedAnnotations extends ArchCondition<JavaClass> { | ||
| public NotUseBlacklistedAnnotations() { | ||
| super("not use blacklisted annotations on classes, methods, method parameters, or fields"); | ||
| } | ||
|
|
||
| @Override | ||
| public void check(JavaClass javaClass, ConditionEvents events) { | ||
| // Check annotations on the class itself | ||
| for (var annotation : javaClass.getAnnotations()) { | ||
| if (BLACKLISTED_ANNOTATIONS.contains(annotation.getRawType().getFullName())) { | ||
| var message = String.format( | ||
| "Class %s is annotated with blacklisted annotation @%s (%s.java:%d)", | ||
| javaClass.getFullName(), | ||
| annotation.getRawType().getFullName(), | ||
| javaClass.getSimpleName(), | ||
| getLineNumber(javaClass) | ||
| ); | ||
| events.add(SimpleConditionEvent.violated(javaClass, message)); | ||
| } | ||
| } | ||
|
|
||
| // Check annotations on methods and their parameters | ||
| for (var method : javaClass.getMethods()) { | ||
| // Check method annotations | ||
| for (var annotation : method.getAnnotations()) { | ||
| if (BLACKLISTED_ANNOTATIONS.contains(annotation.getRawType().getFullName())) { | ||
| var message = String.format( | ||
| "Method %s is annotated with blacklisted annotation @%s (%s.java:%d)", | ||
| method.getFullName(), | ||
| annotation.getRawType().getFullName(), | ||
| javaClass.getSimpleName(), | ||
| getLineNumber(method) | ||
| ); | ||
| events.add(SimpleConditionEvent.violated(method, message)); | ||
| } | ||
| } | ||
| // Check method parameter annotations | ||
| for (var parameter : method.getParameters()) { | ||
| for (var annotation : parameter.getAnnotations()) { | ||
| if (BLACKLISTED_ANNOTATIONS.contains(annotation.getRawType().getFullName())) { | ||
| var message = String.format( | ||
| "Parameter %s of method %s is annotated with blacklisted annotation @%s (%s.java:%d)", | ||
| parameter.getIndex(), | ||
| method.getFullName(), | ||
| annotation.getRawType().getFullName(), | ||
| javaClass.getSimpleName(), | ||
| getLineNumber(method) | ||
| ); // Parameter doesn't have its own SLOC, use method's | ||
| events.add(SimpleConditionEvent.violated(parameter, message)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check annotations on fields (ArchUnit includes record components as fields) | ||
| for (var field : javaClass.getFields()) { | ||
| for (var annotation : field.getAnnotations()) { | ||
| if (BLACKLISTED_ANNOTATIONS.contains(annotation.getRawType().getFullName())) { | ||
| var message = String.format( | ||
| "Field %s in class %s is annotated with blacklisted annotation @%s (%s.java:%d)", | ||
| field.getName(), | ||
| javaClass.getFullName(), | ||
| annotation.getRawType().getFullName(), | ||
| javaClass.getSimpleName(), | ||
| getLineNumber(field) | ||
| ); | ||
| events.add(SimpleConditionEvent.violated(field, message)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/main/java/it/aboutbits/archunit/toolbox/rule/base/BlacklistClassesArchRule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package it.aboutbits.archunit.toolbox.rule.base; | ||
|
|
||
| import com.tngtech.archunit.base.DescribedPredicate; | ||
| import com.tngtech.archunit.core.domain.JavaClass; | ||
| import com.tngtech.archunit.core.domain.JavaClasses; | ||
| import com.tngtech.archunit.junit.ArchTest; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
|
||
| @SuppressWarnings({"checkstyle:InterfaceIsType", "java:S1214"}) | ||
| @NullMarked | ||
| public interface BlacklistClassesArchRule { | ||
| @SuppressWarnings("java:S2386") | ||
| Set<String> BLACKLISTED_CLASSES = new HashSet<>( | ||
| Set.of( | ||
| // use FakerExtended from toolbox | ||
| "net.datafaker.Faker" | ||
| ) | ||
| ); | ||
|
|
||
| @SuppressWarnings({"unused", "checkstyle:MethodName", "java:S100"}) | ||
| @ArchTest | ||
| default void no_blacklisted_classes_are_used(JavaClasses classes) { | ||
| noClasses() | ||
| .should() | ||
| .dependOnClassesThat( | ||
| new DescribedPredicate<>("not use blacklisted classes") { | ||
| @Override | ||
| public boolean test(JavaClass javaClass) { | ||
| return BLACKLISTED_CLASSES.contains(javaClass.getFullName()); | ||
| } | ||
| } | ||
| ) | ||
| .check(classes); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.