Skip to content

Commit

Permalink
Merge pull request #21 from codeclimate/pb-config
Browse files Browse the repository at this point in the history
Allow configurability of the FIXME strings
  • Loading branch information
pbrisbin committed Jan 13, 2016
2 parents 47e17e4 + 1d46c20 commit 41b7a09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ These strings are things you should fix now, not later.
2. Run `codeclimate engines:enable fixme`. This command both installs the engine and enables it in your `.codeclimate.yml` file.
3. You're ready to analyze! Browse into your project's folder and run `codeclimate analyze`.

### Configuration

You can specify what strings to match by adding a `strings` key in your
`.codeclimate.yml`:

```yaml
engines:
fixme:
enabled: true
strings:
- FIXME
- CUSTOM
```
**NOTE**: values specified here *override* the defaults, they are not
*additional* strings to match.
### Need help?
For help with `codeclimate-fixme`, please open an issue on this repository.
Expand Down
9 changes: 0 additions & 9 deletions lib/file-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ function withIncludes(include_paths) {
return buildFiles(include_paths);
}

// Returns file paths based on the exclude_paths values in config file
function withExcludes(exclude_paths) {
var allFiles = glob.sync("/code/**/**", {});
var excludedFiles = buildFiles(exclude_paths);

return diff(allFiles, excludedFiles);
}

// Returns all the file paths in the main directory that match the given pattern
function buildFiles(paths) {
var files = [];
Expand All @@ -35,7 +27,6 @@ function filterFiles(paths) {

module.exports = {
withIncludes: withIncludes,
withExcludes: withExcludes,
filterFiles: filterFiles
};

19 changes: 11 additions & 8 deletions lib/fix-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ function FixMe() { }

FixMe.prototype.runEngine = function(){
var analysisFiles = [],
config = {
include_paths: ["./"],
strings: ["FIXME", "TODO", "HACK", "XXX", "BUG"]
},
self = this;

if (fs.existsSync('/config.json')) {
var engineConfig = JSON.parse(fs.readFileSync('/config.json'));
var overrides = JSON.parse(fs.readFileSync('/config.json'));

if (engineConfig.hasOwnProperty('include_paths')) {
analysisFiles = fileBuilder.withIncludes(engineConfig.include_paths);
} else if (engineConfig.hasOwnProperty('exclude_paths')) {
analysisFiles = fileBuilder.withExcludes(engineConfig.exclude_paths);
for (var prop in overrides) {
config[prop] = overrides[prop];
}
}

analysisFiles = fileBuilder.withIncludes(config.include_paths);
analysisFiles = fileBuilder.filterFiles(analysisFiles);

analysisFiles.forEach(function(f, i, a){
self.find(f);
self.find(f, config.strings);
});
}

FixMe.prototype.find = function(file){
var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)'",
FixMe.prototype.find = function(file, strings){
var fixmeStrings = "'(" + strings.join("|") + ")'",
self = this;

// Prepare the grep string for execution (uses BusyBox grep)
Expand Down
5 changes: 0 additions & 5 deletions test/file-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ describe("fileBuilder", function(){
// expect();
});
});
describe("#withExcludes(paths)", function(){
xit("returns correct files", function(){
// expect();
});
});
describe("#filterFiles(paths)", function(){
xit("returns filters out directory paths", function(){
// expect();
Expand Down

0 comments on commit 41b7a09

Please sign in to comment.