Skip to content

Commit 4b190c8

Browse files
committed
Rule fileters use AND logic
The filters in a rule are combined using the AND logic. Update the types and documentation accordingly
1 parent d188937 commit 4b190c8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

apps/desktop/src/lib/rules/rule.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export type WorkspaceRuleId = BrandedId<'WorkspaceRule'>;
55
* A workspace rule.
66
* @remarks
77
* A rule is evaluated in the app and determines what happens to files or changes based on triggers, filters, and actions.
8+
*
9+
* Multiple rules can defined and will be evaluated in the order they are defined using an OR logic.
810
*/
911
export interface WorkspaceRule {
1012
/** A UUID unique identifier for the rule. */
@@ -15,7 +17,11 @@ export interface WorkspaceRule {
1517
enabled: boolean;
1618
/** The trigger of the rule is what causes it to be evaluated in the app. */
1719
trigger: Trigger;
18-
/** These filters determine what files or changes the rule applies to. Multiple filters are combined with OR logic. */
20+
/** These filters determine what files or changes the rule applies to
21+
* Multiple filters are combined with AND logic (i.e. all conditions must be met).
22+
* This allows for the expressions of rules like "If a file is modified, its path matches
23+
* the regex 'src/.*', and its content matches the regex 'TODO', then do something.
24+
* */
1925
filters: Filter[];
2026
/** The action determines what happens to the files or changes that matched the filters. */
2127
action: Action;
@@ -33,8 +39,8 @@ export type Trigger =
3339
* Multiple conditions in a filter are combined with AND logic.
3440
*/
3541
export type Filter =
36-
| { type: 'pathMatchesRegex'; subject: string[] } // regex patterns as strings
37-
| { type: 'contentMatchesRegex'; subject: string[] } // regex patterns as strings
42+
| { type: 'pathMatchesRegex'; subject: string } // regex patterns as strings
43+
| { type: 'contentMatchesRegex'; subject: string } // regex patterns as strings
3844
| { type: 'fileChangeType'; subject: TreeStatus }
3945
| { type: 'semanticType'; subject: SemanticType };
4046

crates/but-rules/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ pub struct WorkspaceRule {
1515
/// The trigger of the rule is what causes it to be evaluated in the app.
1616
trigger: Trigger,
1717
/// These filtes determine what files or changes the rule applies to.
18-
/// Within a rule, multiple filters are combined with OR logic (i.e. it's sufficient to match any of the filters)
18+
/// Within a rule, multiple filters are combined with AND logic (i.e. all conditions must be met).
19+
/// This allows for the expressions of rules like "If a file is modified, its path matches
20+
/// the regex 'src/.*', and its content matches the regex 'TODO', then do something."
1921
filters: Vec<Filter>,
2022
/// The action determines what happens to the files or changes that matched the filters.
2123
action: Action,
@@ -34,12 +36,12 @@ pub enum Trigger {
3436
#[derive(Serialize, Deserialize, Debug, Clone)]
3537
#[serde(rename_all = "camelCase", tag = "type", content = "subject")]
3638
pub enum Filter {
37-
/// Matches the file path (relative to the repository root) against all provided regex patterns.
39+
/// Matches the file path (relative to the repository root).
3840
#[serde(with = "serde_regex")]
39-
PathMatchesRegex(Vec<regex::Regex>),
40-
/// Match the file content against all provided regex patterns.
41+
PathMatchesRegex(regex::Regex),
42+
/// Match the file content.
4143
#[serde(with = "serde_regex")]
42-
ContentMatchesRegex(Vec<regex::Regex>),
44+
ContentMatchesRegex(regex::Regex),
4345
/// Matches the file change operation type (e.g. addition, deletion, modification, rename)
4446
FileChangeType(TreeStatus),
4547
/// Matches the semantic type of the change.

0 commit comments

Comments
 (0)