You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/query-metadata-style-guide.md
+24-16Lines changed: 24 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Query file metadata and alert message style-guide
1
+
# Query file metadata and alert message styleguide
2
2
3
3
4
4
## Introduction
@@ -11,12 +11,13 @@ Query files have the extension `.ql`. Each file has two distinct areas:
11
11
12
12
* Metadata area–displayed at the top of the file, contains the metadata that defines how results for the query are interpreted and gives a brief description of the purpose of the query.
13
13
* Query definition–defined using QL. The query includes a select statement, which defines the content and format of the results. For further information about writing QL, see the following topics:
@@ -27,7 +28,7 @@ For examples of query files for the languages supported by Semmle, see the follo
27
28
28
29
## Metadata area
29
30
30
-
Query file metadata contains important information which defines the name and purpose of the query. The metadata is included as the content of a valid QLDoc comment, on lines with leading whitespace followed by `*`, between an initial `/**` and a trailing `*/`. For example:
31
+
Query file metadata contains important information which defines the identifier and purpose of the query. The metadata is included as the content of a valid [QLDoc](https://help.semmle.com/QL/ql-spec/qldoc.html) comment, on lines with leading whitespace followed by `*`, between an initial `/**` and a trailing `*/`. For example:
31
32
32
33
```
33
34
/**
@@ -43,11 +44,11 @@ Query file metadata contains important information which defines the name and pu
43
44
*/
44
45
```
45
46
46
-
In order to help others use your query, and to ensure that the query works correctly on LGTM.com, you should include all of the required information outlined below in the metadata, and as much of the optional information as possible. For further information on query metadata see [Query file requirements](https://help.semmle.com/wiki/display/SD/Query+file+requirements).
47
+
In order to help others use your query, and to ensure that the query works correctly on LGTM, you should include all of the required information outlined below in the metadata, and as much of the optional information as possible. For further information on query metadata see [Query file requirements](https://help.semmle.com/wiki/display/SD/Query+file+requirements).
47
48
48
49
### Query name `@name`
49
50
50
-
You must specify an `@name` property for your query. This property defines the display name for the query. Query names should use sentence capitalization, but not include a full stop. Filter queries should specify the results that are excluded when you run the query. See the following examples for more detail:
51
+
You must specify an `@name` property for your query. This property defines the display name for the query. Query names should use sentence capitalization, but not include a full stop. For example:
51
52
52
53
*`@name Access to variable in enclosing class`
53
54
*`@name Array argument size mismatch`
@@ -103,7 +104,7 @@ Note, `@id` properties should be consistent for queries that highlight the same
103
104
* alerts (`@kind problem`)
104
105
* alerts containing path information (`@kind path-problem`)
105
106
106
-
These `@kind` properties support two further mandatory properties which are added by Semmle after the query has been tested, prior to deployment to LGTM. The following information is for reference:
107
+
These `@kind` properties support two further properties which are added by Semmle after the query has been tested, prior to deployment to LGTM. The following information is for reference:
107
108
108
109
109
110
@@ -128,7 +129,7 @@ The `@tags` property is used to define categories that the query relates to. Eac
128
129
*`@tags readability`–for queries that detect confusing patterns that make it harder for developers to read the code.
129
130
*`@tags security`–for queries that detect security weaknesses. See below for further information.
130
131
131
-
There are also more specific `@tags` that can be specified. See, the following pages for more information on the low-level tags:
132
+
There are also more specific `@tags` that can be specified. See, the the following pages for examples of the low-level tags:
@@ -153,21 +154,28 @@ If your query is a security query, use one or more `@tags` to associate it with
153
154
||`external/cwe/cwe-036`|
154
155
||`external/cwe/cwe-073`|
155
156
156
-
When you tag a query like this, the associated CWE pages from [MITRE.org](http://cwe.mitre.org/index.html) will automatically appear in the reference section of its associated qhelp file. For more information on qhelp files, see [Query help style guide](https://docs.google.com/document/d/14E-bne3sO3boo0jbmD68XMdTZknN5dXSTXBGQeAfj6A/edit#).
157
+
When you tag a query like this, the associated CWE pages from [MITRE.org](http://cwe.mitre.org/index.html) will automatically appear in the reference section of its associated qhelp file.
157
158
158
159
## QL area
159
160
160
161
### Alert messages
161
162
162
-
You must define a message in the select clause of an alert query to display with your results. Alert messages are strings that concisely describe the problem that the alert is highlighting and, if possible, also provide some context. For consistency, alert messages should adhere to the following guidelines:
163
+
The select clause of each alert query defines the alert message that is displayed for each result found by the query. Alert messages are strings that concisely describe the problem that the alert is highlighting and, if possible, also provide some context. For consistency, alert messages should adhere to the following guidelines:
163
164
164
165
* Each message should be a complete, standalone sentence. That is, it should be capitalized and have proper punctuation, including a full stop.
165
166
* The message should factually describe the problem that is being highlighted–it should not contain recommendations about how to fix the problem or value judgements.
166
167
* Program element references should be in 'single quotes' to distinguish them from ordinary words. Quotes are not needed around substitutions ($@).
167
168
* Avoid constant alert message strings and include some context, if possible. For example, `The class 'Foo' is duplicated as 'Bar'.` is preferable to `This class is duplicated here.`
168
-
* Where you reference another program element, link to it if possible using a substitution (`$@`). Links should be used inline in the sentence, rather than as parenthesised lists or appositions.
169
-
* When a message contains multiple links, construct a sentence that has the most variable link (that is, the link with most targets) last.
169
+
* Where you reference another program element, link to it if possible using a substitution (`$@`). Links should be used inline in the sentence, rather than as parenthesised lists or appositions.
170
+
* When a message contains multiple links, construct a sentence that has the most variable link (that is, the link with most targets) last. For further information, see [Defining select statements](https://help.semmle.com/QL/learn-ql/ql/writing-queries/select-statement.html)
171
+
172
+
See the following pages for examples of alert messages:
170
173
171
-
See the query homepages for examples of alert messages.
For further information on query writing, see [Writing QL queries](https://lgtm.com/help/ql/writing-queries/writing-queries). For more information on learning QL, see [Learning QL](https://lgtm.com/help/lgtm/ql/learning-ql).
181
+
For further information on query writing, see [Writing QL queries](https://help.semmle.com/QL/learn-ql/ql/writing-queries/writing-queries.html). For more information on learning QL, see [Learning QL](https://help.semmle.com/QL/learn-ql/index.html).
0 commit comments