Skip to content

Commit 6aa4d80

Browse files
committed
🌅
0 parents  commit 6aa4d80

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed

.codeclimate.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
engines:
2+
fixme:
3+
enabled: true
4+
exclude_paths:
5+
- "**/*.md"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM mhart/alpine-node
2+
3+
WORKDIR /usr/src/app
4+
5+
RUN npm install glob
6+
7+
COPY . /usr/src/app
8+
9+
CMD ["/usr/src/app/bin/fixme"]

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Code Climate, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Code Climate FIXME Engine
2+
3+
`codeclimate-fixme` is a Code Climate engine that finds comments in your code which match the following strings:
4+
5+
* `TODO`
6+
* `FIXME`
7+
* `XXX`
8+
* `HACK`
9+
* `BUG`
10+
11+
These strings are things you should fix now, not later.
12+
13+
`codecilmate-fixme` is also very simple, and is intended to provide a `Hello World` like template for Code Climate Platform engine authors. It is implemented in JavaScript as an NPM package.
14+
15+
### Installation & Usage
16+
17+
1. If you haven't already, [install the Code Climate CLI](https://github.com/codeclimate/codeclimate).
18+
2. Run `codeclimate engines:enable fixme`. This command both installs the engine and enables it in your `.codeclimate.yml` file.
19+
3. You're ready to analyze! Browse into your project's folder and run `codeclimate analyze`.
20+
21+
### Need help?
22+
23+
For help with `codeclimate-fixme`, please open an issue on this repository.
24+
25+
If you're running into a Code Climate issue, first look over this project's [GitHub Issues](https://github.com/codeclimate/codeclimate-watson/issues), as your question may have already been covered. If not, [go ahead and open a support ticket with us](https://codeclimate.com/help).

bin/fixme

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env node
2+
3+
// Dependencies
4+
var glob = require("glob");
5+
var exec = require('child_process').exec;
6+
7+
// Strings to scan for in source
8+
var fixmeStrings = "'FIXME|TODO|HACK|BUG'";
9+
10+
// Prints properly structured Issue data to STDOUT according to
11+
// Code Climate Engine specification.
12+
var printIssue = function(fileName, lineNum){
13+
var issue = {
14+
"type": "issue",
15+
"check_name": "FIXME found",
16+
"description": "Code comment found that needs your attention.",
17+
"categories": ["Bug Risk"],
18+
"location":{
19+
"path": fileName,
20+
"lines": {
21+
"begin": lineNum,
22+
"end": lineNum
23+
}
24+
}
25+
};
26+
27+
// Issues must be followed by a null byte
28+
var issueString = JSON.stringify(issue)+"\0";
29+
console.log(issueString);
30+
}
31+
32+
var findFixmes = function(file){
33+
var grepString = "grep -inH -E " + fixmeStrings + " " + file;
34+
35+
exec(grepString, function(error, stdout, stderr) {
36+
var lines = stdout.split("\n");
37+
lines.forEach(function(line, index, array){
38+
if(index < (array.length-1)){
39+
40+
var cols = line.split(":");
41+
var fileName = cols[0].split("/code/")[1];
42+
var lineNum = cols[1];
43+
44+
printIssue(fileName, lineNum);
45+
}
46+
})
47+
})
48+
}
49+
50+
var fileWalk = function(excludePaths){
51+
var analysisFiles = [];
52+
var allFiles = glob.sync("/code/**/**", {});
53+
54+
allFiles.forEach(function(file, i, a){
55+
if(excludePaths.indexOf(file.split("/code/")[1]) < 0) {
56+
analysisFiles.push(file);
57+
}
58+
});
59+
60+
return analysisFiles;
61+
}
62+
63+
64+
var runEngine = function(){
65+
var config = JSON.parse(process.env.ENGINE_CONFIG);
66+
67+
var analysisFiles = fileWalk(config.exclude_paths);
68+
69+
analysisFiles.forEach(function(f, i, a){
70+
findFixmes(f);
71+
});
72+
}
73+
74+
runEngine();

test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// FIXME make this do something
2+
function(){
3+
console.log("!");
4+
}
5+
6+
// TODO make this do something too

0 commit comments

Comments
 (0)