Skip to content

Commit 4094fa9

Browse files
committed
Docs: Query classification and display
Converted from Semmle wiki
1 parent bb5b161 commit 4094fa9

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Query classification and display
2+
3+
Attributable Queries
4+
5+
The results of some queries are unsuitable for attribution to individual
6+
developers. Most of them have a threshold value on which they trigger,
7+
for example all metric violations and statistics based queries. The
8+
results of such queries would all be attributed to the person pushing
9+
the value over (or under) the threshold. Some queries only trigger
10+
another one doesn't. An example of this is the MaybeNull query which
11+
only triggers if the AlwaysNull query doesn't. A small change in the
12+
data flow could make an alert switch from AlwayNull to MaybeNull (or
13+
vice versa). As a result we attribute both a fix and an introduction to
14+
the developer that changed the data flow. For this particular example
15+
the funny attribution results are more a nuisance than a real problem;
16+
the overall alert count remains unchanged. However, for the duplicate
17+
and similar code queries the effects can be much more severe, as they
18+
come in versions for "duplicate file" and "duplicate function" among
19+
many others, where "duplicate function" only triggers if "duplicate
20+
file" didn't. As a result adding some code to a duplicate file might
21+
result in a "fix" of a "duplicate file" alert and an introduction of
22+
many "duplicate function" alerts. This would be highly unfair.
23+
Currently, on the duplicate and similar code queries exhibit this
24+
"exchanging one for many" alerts when trying to attribute their results.
25+
Therefore we currently exclude all duplicate code related alerts from
26+
attribution.
27+
28+
The following queries are excluded from attribution:
29+
30+
- Metric violations, i.e. the ones with metadata properties like `
31+
@(error|warning|recommendation)-(to|from) `
32+
- Queries with tag ` non-attributable `
33+
34+
` `
35+
36+
<div>
37+
38+
<div>
39+
40+
This check is applied when the results of a single attribution are
41+
loaded into the datastore. This means that any change to this behaviour
42+
will only take effect on newly attributed revisions and the historical
43+
data is unchanged.
44+
45+
</div>
46+
47+
</div>
48+
49+
 
50+
51+
Query severity and precision
52+
53+
We currently classify queries in on two axes, with some additional tags.
54+
Those axes are severity and precision, and are defined using the
55+
query-metadata properties `@problem.severity` and `@precision`.
56+
57+
For severity, we have the following categories:
58+
59+
- Error
60+
- Warning
61+
- Recommendation
62+
63+
These categories may change in the future.
64+
65+
For precision, we have the following categories:
66+
67+
- Very-high
68+
- High
69+
- Medium
70+
- Low
71+
72+
As [usual](https://en.wikipedia.org/wiki/Precision_and_recall),
73+
precision is defined as the percentage of query results that are true
74+
positives, i.e., precision = number of true positives / (number of true
75+
positives + number of false positives). There is no hard-and-fast rule
76+
for which precision ranges correspond to which categories.
77+
78+
We expect these categories to remain unchanged for the forseeable
79+
future.
80+
81+
### A note on precision
82+
83+
Intuitively, precision measures how well the query does at finding the
84+
results it is supposed to find, i.e., how well it implements its
85+
(informal, unwritten) rule. So how precise a query is depends very much
86+
on what we consider that rule to be. We generally try to sharpen our
87+
rules to focus on results that a developer might actually be interested
88+
in.
89+
90+
91+
92+
## Which queries to run and display on LGTM
93+
94+
The following queries are run:
95+
96+
<div class="table-wrap">
97+
98+
| Precision: | V. high | High | Medium | Low |
99+
| -------------- | ----------- | ------- | ------- | --- |
100+
| Error | ****Yes**** | **Yes** | **Yes** | No |
101+
| Warning | ****Yes**** | **Yes** | **Yes** | No |
102+
| Recommendation | ****Yes**** | **Yes** | No | No |
103+
104+
</div>
105+
106+
The following queries have their results displayed by default:
107+
108+
<div class="table-wrap">
109+
110+
| Precision: | V. high | High | Medium | Low |
111+
| -------------- | ----------- | ----------- | ------ | --- |
112+
| Error | Yes | ****Yes**** | No | No |
113+
| Warning | ****Yes**** | ****Yes**** | No | No |
114+
| Recommendation | ****Yes**** | No | No | No |
115+
116+
</div>
117+
118+
119+
Results for queries that are run but not displayed by default can be
120+
made visible by editing the project configuration.
121+
122+
123+
 Queries from custom query packs (in-repo or site-wide) are always run
124+
and displayed by default. The can be hidden by editing the project
125+
config, and "disabled" by removing them from the query pack.

0 commit comments

Comments
 (0)