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
- Add a linked table of contents to the top.
- Distinguish between information necessary for writing an executable
(now under "Engine execution") and higher-level requirements that
aren't directly related to the executable ("Engine specification
file", "Packaging", "Naming convention").
- Make the title capitalization consistent because I'm OCD like that.
- Correct description of which directories are mounted by default.
- Fix outdated reference to 'manifest'.
Copy file name to clipboardExpand all lines: SPEC.md
+67-36Lines changed: 67 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,46 @@
1
1
# Code Climate Engine Specification
2
2
3
-
**Note: This specification is a living, versioned document. We welcome your participation and appreciate your patience as we finalize the platform.**
3
+
## Abstract
4
+
5
+
This specification describes the contract that must be followed by an engine to ensure compatability with the rest of the tools in the Code Climate static analysis ecosystem. It defines several aspects of Engine operation including input, outputs, packaging, as well as performance and security restrictions.
6
+
7
+
## Status of this document
8
+
9
+
The current version of this specification is [in the repository](https://github.com/codeclimate/spec/blob/master/VERSION). This specification is versioned using [Semantic Versioning](http://semver.org/).
10
+
11
+
Engines declare the version of the specification they are compatible with in the engine specification file, described below.
12
+
13
+
We welcome your participation and appreciate your patience as we finalize the platform.
14
+
15
+
## Table of contents
16
+
17
+
-[Overview](#overview)
18
+
-[Engine execution](#engine-execution)
19
+
-[Input](#input)
20
+
- [Which files to analyze](#which-files-to-analyze)
A Code Climate engine is a standalone program which accepts a configuration and source code, and returns static analysis results. It can be implemented in any programming language, and is distributed as a Docker image.
8
40
9
-
## Input
41
+
## Engine execution
42
+
43
+
### Input
10
44
11
45
The Engine Docker container is provided the source code to analyze at `/code`, which is mounted as a read-only volume.
12
46
@@ -20,7 +54,7 @@ for all engines in a single `.codeclimate.yml` file. The Code Climate CLI (and o
20
54
21
55
The `include_paths` key will always be present in `config.json`, and must be used by engines to limit which files they will analyze. Details of this key are below.
22
56
23
-
### Which files to analyze
57
+
####Which files to analyze
24
58
25
59
`include_paths` in `/config.json` contains an array of file paths and directory paths (relative to the `/code` directory) that defines the range of files that the engine can analyze. Directories will end with a trailing slash. For example:
26
60
@@ -36,7 +70,7 @@ The `include_paths` key will always be present in `config.json`, and must be use
36
70
37
71
`include_paths` may include paths to files that are irrelevant to the analysis (i.e., `.gitignore` if the engine only analyzes JavaScript). Engines are responsible for filtering out irrelevant files.
38
72
39
-
## Output
73
+
###Output
40
74
41
75
* Engines must stream Issues to `STDOUT` in JSON format.
42
76
* When possible, results should be emitted as soon as they are computed (streamed, not buffered).
@@ -47,9 +81,9 @@ The `include_paths` key will always be present in `config.json`, and must be use
47
81
**Note that an engine finding and emitting issues is expected, and not a fatal error - this means that if your engine finds issues, it should still in all cases exit with code zero.*
48
82
**Note that all results will be discard and the analysis failed if an engine exits with a non-zero exit code.*
49
83
50
-
## Data Types
84
+
###Data Types
51
85
52
-
### Issues
86
+
####Issues
53
87
54
88
An `issue` represents a single instance of a real or potential code problem, detected by a static analysis Engine.
55
89
@@ -79,13 +113,13 @@ An `issue` represents a single instance of a real or potential code problem, det
79
113
*`severity` -- **Optional**. A `Severity` string (`info`, `normal`, or `critical`) describing the potential impact of the issue found.
80
114
*`fingerprint` -- **Optional**. A unique, deterministic identifier for the specific issue being reported to allow a user to exclude it from future analyses.
81
115
82
-
#### Descriptions
116
+
#####Descriptions
83
117
84
118
Descriptions must be a single line of text (no newlines), with no HTML formatting contained within. Ideally, descriptions should be fewer than 70 characters long, but this is not a requirement.
85
119
86
120
Descriptions support one type of basic Markdown formatting, which is the use of backticks to produce inline <code> tags that are rendered in a fixed width font. Identifiers like class, method and variable names should be wrapped within backticks whenever possible for optimal rendering by tools that consume Engines data.
87
121
88
-
#### Categories
122
+
#####Categories
89
123
90
124
Issues must be associated with one or more categories. Valid issue `categories` are:
91
125
@@ -98,7 +132,7 @@ Issues must be associated with one or more categories. Valid issue `categories`
98
132
-`Security` -- TODO describe me
99
133
-`Style` -- TODO describe me
100
134
101
-
#### Remediation Points
135
+
#####Remediation points
102
136
103
137
Remediation points are an abstract, relative scale to express the estimated time it would take for a developer to resolve an issue. They are abstract because they do not map directly to absolute time durations like minutes and hours. Providing remediation points is optional, but they can be useful to certain tools that consume Engines data and generate reports related to the level of effort required to improve a codebase (like CodeClimate.com).
104
138
@@ -109,7 +143,7 @@ Here are some guidelines to compute appropriate remediation points values for an
109
143
110
144
The baseline remediation points value is 50,000, which is the time it takes to fix a trivial code style issue like a missing semicolon on a single line, including the time for the developer to open the code, make the change, and confidently commit the fix. All other remediation points values are expressed in multiples of that Basic Remediation Point Value.
111
145
112
-
### Locations
146
+
####Locations
113
147
114
148
Locations refer to ranges of a source code file. A Location contains a `path`, a source range, (expressed as `lines` or `positions`), and an optional array of `other_locations`. Here's an example location:
115
149
@@ -146,7 +180,7 @@ Locations of the first form (_line-based_ locations) emit a beginning and end li
146
180
147
181
Locations in the second form (_position-based_ locations) allow more precision by including references to the specific characters that form the source code range representing the issue.
148
182
149
-
#### Positions
183
+
#####Positions
150
184
151
185
Positions refer to specific characters within a source file, and can be expressed in two ways:
152
186
@@ -176,16 +210,16 @@ line of the file.
176
210
177
211
Offsets, however are 0-based. A Position of `{ "offset": 4 }` represents the _fifth_ character in the file. Importantly, the `offset` is from the beginning of the file, not the beginning of a line. Newline characters (and all characters) count when computing an offset.
178
212
179
-
### Contents
213
+
####Contents
180
214
181
-
Contents give more information about the issue's check, including a description of the issue, how to fix it, and relevant links. They are expressed as a hash with a `body` key. The value of this key should be a [Markdown](http://daringfireball.net/projects/markdown/) document. For example:
215
+
Content gives more information about the issue's check, including a description of the issue, how to fix it, and relevant links. They are expressed as a hash with a `body` key. The value of this key should be a [Markdown](http://daringfireball.net/projects/markdown/) document. For example:
182
216
183
217
```json
184
218
{
185
219
"body": "This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See [this page](http://c2.com/cgi/wiki?AbcMetric) for more information on ABC size."
186
220
}
187
221
```
188
-
### Source Code Traces
222
+
####Source code traces
189
223
190
224
Some engines require the ability to refer to other source locations in describing an issue. For this reason, an `Issue` object can have an associated `Trace`, a data structure meant to represent ordered or unordered lists of source code locations. A `Trace` has the following fields:
191
225
@@ -215,11 +249,26 @@ An example trace:
215
249
216
250
```
217
251
218
-
##Versioning
252
+
### Resource restrictions
219
253
220
-
This specification is versioned. The current version is [in the repository](https://github.com/codeclimate/spec/blob/master/VERSION). Engines declare the version of the specification they are compatible with in the manifest file, described below. This project follows [Semantic Versioning](http://semver.org/).
254
+
In order to ensure analysis runs reliably across a variety of systems, Engines
255
+
must conform to some basic resource restrictions:
221
256
222
-
## Engine Specification File
257
+
* The Docker image for an Engine must not exceed 512MB, including all layers.
258
+
* The combined total RSS memory usage by all processes within the Docker container must not exceed 1GB at any time.
259
+
* All Engines must complete and exit within 10 minutes.
260
+
261
+
### Security restrictions
262
+
263
+
Engines run in a secured runtime environment, within container-based virtualization
264
+
provided by Docker.
265
+
266
+
* The `/code` directory, containing the files to analyze, & `/config.json`, containing configuration for the engine to use, are mounted read-only.
267
+
* Engines run with no network access (`--net=none` in Docker). They must not rely on making any external network calls.
268
+
* Engines run with the minimal set of Linux capabilities (`--cap-drop all` in Docker)
269
+
* Engines are always run as a user `app` with UID and GID of 9000, and never `root`.
270
+
271
+
## Engine specification file
223
272
224
273
All engines must include an `engine.json` file at `/engine.json`. This file includes information that is necessary for the analysis runtime and metadata about the engine. Here is an example specification:
225
274
@@ -290,27 +339,9 @@ VOLUME /code
290
339
CMD ["/usr/src/app/bin/fixme"]
291
340
```
292
341
293
-
## Naming Convention
342
+
## Naming convention
294
343
295
344
Your `Docker` image must be built with the name `codeclimate/codeclimate-YOURENGINENAME`.
296
345
297
-
## Resource Restrictions
298
-
299
-
In order to ensure analysis runs reliably across a variety of systems, Engines
300
-
must conform to some basic resource restrictions:
301
-
302
-
* The Docker image for an Engine must not exceed 512MB, including all layers.
303
-
* The combined total RSS memory usage by all processes within the Docker container must not exceed 1GB at any time.
304
-
* All Engines must complete and exit within 10 minutes.
305
-
306
-
## Security Restrictions
307
-
308
-
Engines run in a secured runtime environment, within container-based virtualization
309
-
provided by Docker.
310
-
311
-
* The root filesystem (`/`) is mounted read-only. A `/tmp` volume is mounted read-write for temporary file storage during the engine run.
312
-
* Engines run with no network access (`--net=none` in Docker). They must not rely on making any external network calls.
313
-
* Engines run with the minimal set of Linux capabilities (`--cap-drop all` in Docker)
314
-
* Engines are always run as a user `app` with UID and GID of 9000, and never `root`.
0 commit comments