From 07f6e5e60884e745993622eb9ee3ed8714800800 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Wed, 13 Jan 2016 16:17:30 -0500 Subject: [PATCH 1/2] Drop exclude_paths support, default configuration Defaulting to `include_paths: [./]` means it's possible to run docker run -v $PWD:/code $image to see raw output from running this engine, which is useful while developing. --- lib/file-builder.js | 9 --------- lib/fix-me.js | 12 +++++++----- test/file-builder.js | 5 ----- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/file-builder.js b/lib/file-builder.js index e0c05a4..bdf84bd 100644 --- a/lib/file-builder.js +++ b/lib/file-builder.js @@ -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 = []; @@ -35,7 +27,6 @@ function filterFiles(paths) { module.exports = { withIncludes: withIncludes, - withExcludes: withExcludes, filterFiles: filterFiles }; diff --git a/lib/fix-me.js b/lib/fix-me.js index cea3d96..6f86197 100644 --- a/lib/fix-me.js +++ b/lib/fix-me.js @@ -11,18 +11,20 @@ function FixMe() { } FixMe.prototype.runEngine = function(){ var analysisFiles = [], + config = { + include_paths: ["./"] + }, 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){ diff --git a/test/file-builder.js b/test/file-builder.js index e766b64..224069d 100644 --- a/test/file-builder.js +++ b/test/file-builder.js @@ -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(); From 1d46c204085b9d2e055952d0ce43e87a4631a1cb Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Wed, 13 Jan 2016 16:24:14 -0500 Subject: [PATCH 2/2] Allow configurability of the FIXME strings --- README.md | 17 +++++++++++++++++ lib/fix-me.js | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7516d87..e1ee050 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/fix-me.js b/lib/fix-me.js index 6f86197..e8cd911 100644 --- a/lib/fix-me.js +++ b/lib/fix-me.js @@ -12,7 +12,8 @@ function FixMe() { } FixMe.prototype.runEngine = function(){ var analysisFiles = [], config = { - include_paths: ["./"] + include_paths: ["./"], + strings: ["FIXME", "TODO", "HACK", "XXX", "BUG"] }, self = this; @@ -28,12 +29,12 @@ FixMe.prototype.runEngine = function(){ 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)