Commit b954a62
authored
Fix MetricsPixelNumericValueDetector for compiled Kotlin classes (duckduckgo#7953)
Task/Issue URL:
https://app.asana.com/1/137249556945/project/1202552961248957/task/1213634576464400
### Description
The `MetricsPixelNumericValueDetector` lint rule was silently missing
violations when `MetricsPixel` was used in modules where the class is
loaded from a compiled dependency JAR — the constructor `PsiMethod`
can't be resolved in that case, so `visitConstructor` never fired.
This PR adds a fallback detection path via
`getApplicableUastTypes`/`createUastHandler` that triggers on all
`UCallExpression` nodes and uses source text matching + return type
filtering to identify `MetricsPixel` calls. Named-argument lookup was
also reworked to use `UNamedExpression` with a Kotlin PSI fallback,
making it robust regardless of argument order. All tests now skip
`TestMode.REORDER_ARGUMENTS` to suppress a known lint test
infrastructure warning caused by overlapping edits when positional args
are nested inside outer named args.
### Steps to test this PR
_MetricsPixelNumericValueDetector_
- [x] Change `SearchMetricPixelsPlugin` so one of them has a value
that's not a number, i.e. "test"
- [x] Run `./gradlew :feature-toggles-impl:lint`
- [x] Lint should throw an error
### UI changes
| Before | After |
| ------ | ----- |
!(Upload before screenshot)|(Upload after screenshot)|
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Medium risk because it changes lint detection logic to rely on
UAST/PSI fallbacks and source-text matching, which could introduce false
positives/negatives across Kotlin call shapes.
>
> **Overview**
> Fixes `MetricsPixelNumericValueDetector` missing violations when
`MetricsPixel` comes from a compiled dependency by adding a fallback
scan over all `UCallExpression`s and filtering to `MetricsPixel` calls
when the constructor can’t be resolved.
>
> Reworks argument extraction to be robust to named/out-of-order
arguments by using `UNamedExpression` with a Kotlin PSI fallback, and
improves error location selection by reporting on the `value` expression
when possible.
>
> Updates tests to reflect the real `MetricsPixel` signature (default
`type`), adds coverage for out-of-order named arguments, and skips
`TestMode.REORDER_ARGUMENTS` to avoid test infra issues.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
693bca6. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 557b40a commit b954a62
2 files changed
Lines changed: 121 additions & 15 deletions
File tree
- lint-rules/src
- main/java/com/duckduckgo/lint
- test/java/com/duckduckgo/lint
Lines changed: 77 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
35 | | - | |
36 | | - | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | | - | |
40 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
41 | 68 | | |
42 | 69 | | |
43 | | - | |
44 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
45 | 73 | | |
46 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
47 | 78 | | |
48 | 79 | | |
49 | | - | |
50 | | - | |
| 80 | + | |
| 81 | + | |
51 | 82 | | |
52 | 83 | | |
53 | 84 | | |
54 | 85 | | |
55 | 86 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 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 | + | |
60 | 122 | | |
61 | 123 | | |
62 | 124 | | |
| 125 | + | |
| 126 | + | |
63 | 127 | | |
64 | 128 | | |
65 | 129 | | |
| |||
74 | 138 | | |
75 | 139 | | |
76 | 140 | | |
77 | | - | |
| 141 | + | |
Lines changed: 44 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
| 119 | + | |
116 | 120 | | |
117 | 121 | | |
118 | 122 | | |
| |||
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
| 151 | + | |
147 | 152 | | |
148 | 153 | | |
149 | 154 | | |
| |||
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
| 183 | + | |
178 | 184 | | |
179 | 185 | | |
180 | 186 | | |
181 | 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 | + | |
182 | 224 | | |
183 | 225 | | |
184 | 226 | | |
| |||
188 | 230 | | |
189 | 231 | | |
190 | 232 | | |
191 | | - | |
192 | 233 | | |
193 | | - | |
| 234 | + | |
| 235 | + | |
194 | 236 | | |
195 | 237 | | |
196 | 238 | | |
0 commit comments