Skip to content

Commit 89aec22

Browse files
authored
Cleanup SPEC.md.
- 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'.
1 parent 18e192e commit 89aec22

File tree

1 file changed

+67
-36
lines changed

1 file changed

+67
-36
lines changed

SPEC.md

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
# Code Climate Engine Specification
22

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)
21+
- [Output](#output)
22+
- [Data types](#data-types)
23+
- [Issues](#issues)
24+
- [Descriptions](#descriptions)
25+
- [Categories](#categories)
26+
- [Remediation points](#remediation-points)
27+
- [Locations](#locations)
28+
- [Positions](#positions)
29+
- [Contents](#contents)
30+
- [Source code traces](#source-code-traces)
31+
- [Resource restrictions](#resource-restrictions)
32+
- [Security restrictions](#security-restrictions)
33+
- [Engine specification file](#engine-specification-file)
34+
- [Packaging](#packaging)
35+
- [Naming convention](#naming-convention)
436

537
## Overview
638

739
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.
840

9-
## Input
41+
## Engine execution
42+
43+
### Input
1044

1145
The Engine Docker container is provided the source code to analyze at `/code`, which is mounted as a read-only volume.
1246

@@ -20,7 +54,7 @@ for all engines in a single `.codeclimate.yml` file. The Code Climate CLI (and o
2054

2155
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.
2256

23-
### Which files to analyze
57+
#### Which files to analyze
2458

2559
`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:
2660

@@ -36,7 +70,7 @@ The `include_paths` key will always be present in `config.json`, and must be use
3670

3771
`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.
3872

39-
## Output
73+
### Output
4074

4175
* Engines must stream Issues to `STDOUT` in JSON format.
4276
* 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
4781
* *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.*
4882
* *Note that all results will be discard and the analysis failed if an engine exits with a non-zero exit code.*
4983

50-
## Data Types
84+
### Data Types
5185

52-
### Issues
86+
#### Issues
5387

5488
An `issue` represents a single instance of a real or potential code problem, detected by a static analysis Engine.
5589

@@ -79,13 +113,13 @@ An `issue` represents a single instance of a real or potential code problem, det
79113
* `severity` -- **Optional**. A `Severity` string (`info`, `normal`, or `critical`) describing the potential impact of the issue found.
80114
* `fingerprint` -- **Optional**. A unique, deterministic identifier for the specific issue being reported to allow a user to exclude it from future analyses.
81115

82-
#### Descriptions
116+
##### Descriptions
83117

84118
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.
85119

86120
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.
87121

88-
#### Categories
122+
##### Categories
89123

90124
Issues must be associated with one or more categories. Valid issue `categories` are:
91125

@@ -98,7 +132,7 @@ Issues must be associated with one or more categories. Valid issue `categories`
98132
- `Security` -- TODO describe me
99133
- `Style` -- TODO describe me
100134

101-
#### Remediation Points
135+
##### Remediation points
102136

103137
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).
104138

@@ -109,7 +143,7 @@ Here are some guidelines to compute appropriate remediation points values for an
109143

110144
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.
111145

112-
### Locations
146+
#### Locations
113147

114148
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:
115149

@@ -146,7 +180,7 @@ Locations of the first form (_line-based_ locations) emit a beginning and end li
146180

147181
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.
148182

149-
#### Positions
183+
##### Positions
150184

151185
Positions refer to specific characters within a source file, and can be expressed in two ways:
152186

@@ -176,16 +210,16 @@ line of the file.
176210

177211
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.
178212

179-
### Contents
213+
#### Contents
180214

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:
182216

183217
```json
184218
{
185219
"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."
186220
}
187221
```
188-
### Source Code Traces
222+
#### Source code traces
189223

190224
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:
191225

@@ -215,11 +249,26 @@ An example trace:
215249

216250
```
217251

218-
## Versioning
252+
### Resource restrictions
219253

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:
221256

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
223272

224273
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:
225274

@@ -290,27 +339,9 @@ VOLUME /code
290339
CMD ["/usr/src/app/bin/fixme"]
291340
```
292341

293-
## Naming Convention
342+
## Naming convention
294343

295344
Your `Docker` image must be built with the name `codeclimate/codeclimate-YOURENGINENAME`.
296345

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`.
315346

316347
[null]: http://en.wikipedia.org/wiki/Null_character

0 commit comments

Comments
 (0)