Skip to content
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

raise error for empty violation store and delete empty rule file #1405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxxkia
Copy link

@maxxkia maxxkia commented Jan 18, 2025

These changes introduce two new features for FreezingRule default store

  • Raise error when a freezing rule has zero violations. This can be enabled by setting the property default.warnEmptyRuleViolation=true. For backward compatibility it is disabled by default.
  • Skip rule violation file creation or delete if it already exists, when there are zero violations. This can be enabled by setting the property default.deleteEmptyRuleViolation=true, it is disabled by default.

Signed-off-by: Masoud Kiaeeha [email protected]

Resolves #1264

@maxxkia maxxkia force-pushed the extension-for-empty-frozen-rule branch 5 times, most recently from a833065 to 90c5338 Compare January 19, 2025 11:24
@maxxkia maxxkia marked this pull request as ready for review January 19, 2025 11:34
@@ -73,11 +73,17 @@ public final class TextFileBasedViolationStore implements ViolationStore {
private static final String ALLOW_STORE_CREATION_DEFAULT = "false";
private static final String ALLOW_STORE_UPDATE_PROPERTY_NAME = "default.allowStoreUpdate";
private static final String ALLOW_STORE_UPDATE_DEFAULT = "true";
private static final String DELETE_EMPTY_RULE_VIOLATION_PROPERTY_NAME = "default.deleteEmptyRuleViolation";
private static final String DELETE_EMPTY_RULE_VIOLATION_DEFAULT = "false";
Copy link
Author

@maxxkia maxxkia Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can discuss the above default value. I would prefer to have default true here, but I'd like to first hear the opinions from the maintainers.

@@ -140,15 +148,38 @@ public boolean contains(ArchRule rule) {
@Override
public void save(ArchRule rule, List<String> violations) {
log.trace("Storing evaluated rule '{}' with {} violations: {}", rule.getDescription(), violations.size(), violations);
if (violations.isEmpty() && warnEmptyRuleViolation) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check has to be placed here at the top, because for empty frozen rule violations you don't necessarily need to update the store. By seeing such warning the developer could change the test to non-freezing rather than decide to update the store.

@maxxkia maxxkia changed the title raise error for empty violation store raise error for empty violation store and delete empty rule file Jan 19, 2025
These changes introduce two new features for FreezingRule default store
* Raise error when a freezing rule has zero violations. This can be enabled by setting the property `default.warnEmptyRuleViolation=true`. For backward compatibility it is disabled by default.
* Skip rule violation file creation or delete if it already exists, when there are zero violations. This can be enabled by setting the property `default.deleteEmptyRuleViolation=true`, it is disabled by default.

Signed-off-by: Masoud Kiaeeha <[email protected]>

Resolves TNG#1264
@maxxkia maxxkia force-pushed the extension-for-empty-frozen-rule branch from 90c5338 to 60de7ab Compare January 19, 2025 14:03
throw new StoreEmptyException(String.format("Saving empty violations for freezing rule is disabled (enable by configuration %s.%s=true)",
ViolationStoreFactory.FREEZE_STORE_PROPERTY_NAME, WARN_EMPTY_RULE_VIOLATION_PROPERTY_NAME));
}
if (violations.isEmpty() && deleteEmptyRule && !contains(rule)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another way to write this check would be

Suggested change
if (violations.isEmpty() && deleteEmptyRule && !contains(rule)) {
if (violations.isEmpty() && (deleteEmptyRule || skipEmptyRule) && !contains(rule)) {

where skipEmptyRule condition is only used for skipping creation of empty rule file. To keep the configuration simple, I decided to use deleteEmptyRule for both skipping file creation and deleting the empty file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature suggestion: Freeze files and stored.rules validation / sanity check
1 participant