1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//! Generic package filtering based on Cargo.toml properties.
//!
//! This module provides functionality to filter workspace packages based on
//! criteria applied to their Cargo.toml properties.
//!
//! # Examples
//!
//! ## Simple Filtering
//!
//! ```rust,ignore
//! use clippier::package_filter::apply_filters;
//! use std::collections::BTreeMap;
//!
//! // Skip packages where package.publish = false
//! let skip_filters = vec!["package.publish=false".to_string()];
//! let filtered = apply_filters(&packages, &paths, &root, &skip_filters, &[])?;
//! ```
//!
//! ## Complex Expressions with Logical Operators
//!
//! ```rust,ignore
//! // Skip unpublished packages OR examples
//! let skip_filters = vec!["package.publish=false OR package.name$=_example".to_string()];
//!
//! // Include only published moosicbox packages that aren't examples
//! let include_filters = vec!["package.name^=moosicbox_ AND package.publish=true AND NOT package.name$=_example".to_string()];
//!
//! let filtered = apply_filters(&packages, &paths, &root, &skip_filters, &include_filters)?;
//! ```
//!
//! # Filter Syntax
//!
//! Filters use the format: `property[.nested]<operator>value`
//!
//! ## Property Path Resolution
//!
//! Property paths are resolved from the root of Cargo.toml using dot notation.
//! You must specify the full path to any property:
//!
//! * **Package section properties**: Use `package.` prefix
//! - `package.name`, `package.version`, `package.publish`
//! - `package.categories`, `package.keywords`, `package.authors`
//! - `package.metadata.workspaces.independent`
//!
//! * **Other top-level sections**: Reference directly
//! - `dependencies.serde.version`
//! - `features.default`
//! - `workspace.members`
//!
//! **Examples:**
//! * `package.name^=moosicbox_` - Match packages starting with "moosicbox_"
//! * `dependencies.serde?` - Check if serde is a dependency
//! * `package.metadata.ci.skip=true` - Match custom metadata
//! * `features.default?` - Check if default feature exists
//!
//! ## Logical Operators
//!
//! Combine filter conditions using logical operators:
//!
//! * `AND` - Both conditions must be true
//! * `OR` - At least one condition must be true
//! * `NOT` - Inverts the condition
//! * `( )` - Groups conditions for precedence control
//!
//! **Operator Precedence** (highest to lowest):
//! 1. `NOT`
//! 2. `AND`
//! 3. `OR`
//!
//! **Examples:**
//! * `package.publish=false AND package.version^=0.1` - Both must match
//! * `package.publish=false OR package.name$=_example` - Either must match
//! * `NOT package.publish=false` - Inverts the condition
//! * `(package.publish=false OR package.name$=_test) AND package.version^=0.1` - Grouped with precedence
//! * `package.name^=moosicbox_ AND (package.categories@=audio OR package.categories@=video)` - Complex nesting
//!
//! **Case Insensitive:** Keywords can be `AND`, `and`, `And`, etc.
//!
//! ## Quoted Values
//!
//! Use double quotes for values containing spaces or special characters:
//!
//! * `package.name="my package"` - Value with spaces
//! * `package.description="This AND that"` - Prevents "AND" from being treated as operator
//!
//! **Escape Sequences:**
//! * `\"` - Double quote
//! * `\\` - Backslash
//! * `\n` - Newline
//! * `\t` - Tab
//! * `\r` - Carriage return
//!
//! Example: `package.name="Quote: \"test\""`
//!
//! ## Unicode Support
//!
//! Full Unicode support including multibyte characters, emoji, and RTL text:
//!
//! * Property names with Unicode: `package.名前=test`
//! * Unicode values: `package.name=テスト`
//! * Emoji in values: `package.icon=🎵`
//! * Right-to-left text: `package.اسم=قيمة`
//! * Works with all operators and logical expressions
//!
//! ## Scalar Operators
//!
//! Match against string, boolean, or integer values:
//!
//! * `=` - Exact match: `package.publish=false`
//! * `!=` - Not equal: `package.version!=0.1.0`
//! * `^=` - Starts with: `package.version^=0.1`
//! * `$=` - Ends with: `package.name$=_example`
//! * `*=` - Contains: `package.description*=server`
//! * `~=` - Regex: `package.name~=^moosicbox_.*`
//!
//! ## Array Operators
//!
//! Match against array properties (keywords, categories, authors, etc.):
//!
//! * `@=` - Contains element: `package.categories@=audio`
//! * `@*=` - Contains element with substring: `package.keywords@*=music`
//! * `@^=` - Contains element starting with: `package.keywords@^=moosic`
//! * `@~=` - Contains element matching regex: `package.categories@~=^dev.*`
//! * `@!` - Array is empty: `package.keywords@!`
//! * `@#=` - Length equals: `package.keywords@#=3`
//! * `@#>` - Length greater: `package.keywords@#>2`
//! * `@#<` - Length less: `package.keywords@#<5`
//! * `!@=` - Does NOT contain: `package.categories!@=test`
//!
//! ## Existence Operators
//!
//! Check if properties exist:
//!
//! * `?` - Property exists: `package.readme?`
//! * `!?` - Property does NOT exist: `package.homepage!?`
//!
//! ## Nested Properties
//!
//! Access nested metadata using dot notation:
//!
//! * `package.metadata.workspaces.independent=true`
//! * `package.metadata.ci.skip-tests=true`
//! * `package.metadata.custom.field=value`
pub use parse_expression;
pub use ;
pub use parse_filter;
pub use tokenize;
pub use ;
use BTreeMap;
use Path;
use Value;
/// Apply skip and include filters to a list of packages.
///
/// # Arguments
///
/// * `packages` - List of package names to filter
/// * `package_paths` - Map of package names to their workspace paths
/// * `workspace_root` - Root directory of the workspace
/// * `skip_filters` - Filter expressions that cause packages to be excluded (OR logic between filters)
/// * `include_filters` - Filter expressions that must match for inclusion (AND logic between filters)
///
/// Each filter can be:
/// * A simple condition: `"package.publish=false"`
/// * A complex expression: `"(package.publish=false OR package.name$=_example) AND package.categories@=audio"`
///
/// # Returns
///
/// Filtered list of package names that pass all criteria
///
/// # Errors
///
/// Returns error if:
/// * Package path not found
/// * Cargo.toml cannot be read or parsed
/// * Filter syntax is invalid