From c6733212bb8cb8201414967a9182c593a72135f8 Mon Sep 17 00:00:00 2001 From: Amin Mirzaee Date: Sat, 27 Jan 2018 22:36:16 -0500 Subject: [PATCH] Fix the tests and add prepare script --- package.json | 1 + src/configfinder.coffee | 9 +++++---- test/fixtures/.DS_Store | Bin 0 -> 6148 bytes .../find_extended_test/package/.coffeelintrc | 6 ++++++ .../find_extended_test/package/package.json | 6 ++++++ .../find_extended_test/package/sixspaces.coffee | 2 ++ test/test_commandline.coffee | 14 ++++++++++++-- 7 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/.DS_Store create mode 100644 test/fixtures/find_extended_test/package/.coffeelintrc create mode 100644 test/fixtures/find_extended_test/package/package.json create mode 100644 test/fixtures/find_extended_test/package/sixspaces.coffee diff --git a/package.json b/package.json index 7e703a4f..7957c2c4 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "test": "./vowsrunner.js --spec test/*.coffee test/*.litcoffee", "testrule": "npm run compile && ./vowsrunner.js --spec", "posttest": "npm run lint", + "prepare": "npm run prepublish", "prepublish": "cake prepublish", "postpublish": "cake postpublish", "publish": "cake publish", diff --git a/src/configfinder.coffee b/src/configfinder.coffee index f569b19e..3f3cbc04 100644 --- a/src/configfinder.coffee +++ b/src/configfinder.coffee @@ -35,7 +35,7 @@ loadJSON = (filename, attr = null) -> try config = JSON.parse(stripComments(fs.readFileSync(filename).toString())) config = config[attr] if attr - config.__location__ = filename + config?.__location__ = filename return config catch e process.stderr.write "Could not load JSON file '#{filename}': #{e}" @@ -92,8 +92,10 @@ expandModuleNames = (dir, config) -> extendConfig = (dir, config) -> unless config.extends return config - - parentConfig = require resolve config.extends, basedir: dir + try + parentConfig = require config.extends + catch + parentConfig = require resolve config.extends, basedir: dir extendedConfig = {} for ruleName, rule of config @@ -111,7 +113,6 @@ exports.getConfig = (filename = null) -> dir = process.cwd() config = getConfig(dir) - dir = path.dirname(config.__location__) if config config = extendConfig(dir, config) diff --git a/test/fixtures/.DS_Store b/test/fixtures/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..102ac6266ccd3c6e7f3b182ba6e3e5cdd90a9770 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TrifTXu*Y1y^^jInJP4uIgEt|f2bDG<)dp%(n$)T_lGo5T@(Fw$ zXLh&6QUx!Hl^K}*W@l%1v)_jO0RT}S_*H-s02ru*xgr*y2(^>WNKShQh3umVZMcI3 z%Wx)|9e{hmY&$<0_JeRx^gg8^%4a8+jQ2>h-!ooLJVI$mI(Qi%SN{ zigD?5qM?(x$sn$~{d1}vyGh5>_DK|VC${UI2JK<9w0;nUi5rCNzDy4MHilfB1)(1e z>(LIho@Z0&5nE__tXBnXV!9*pr zHD(Is)`10GAE~`SNP;%KB?wK8w#G~$wx9@=il|bBeqsofj($_e*%~v2DjkFz8T-*A z3;jY7a&+{YG8}}hkV|HO8JK1uuc{?F{|~=@|4%1zjTvAD{uKkF&~O@coRU6UXC_By ut%=$~C84-X;UonOc@$$T9mQo-Dd;!JK(sYx3ekhY7Xe8F7tFw~GVl)70$Qg4 literal 0 HcmV?d00001 diff --git a/test/fixtures/find_extended_test/package/.coffeelintrc b/test/fixtures/find_extended_test/package/.coffeelintrc new file mode 100644 index 00000000..cc75a445 --- /dev/null +++ b/test/fixtures/find_extended_test/package/.coffeelintrc @@ -0,0 +1,6 @@ +module.exports = { + "indentation": { + "level" : "error", + "value" : 6 + } +} diff --git a/test/fixtures/find_extended_test/package/package.json b/test/fixtures/find_extended_test/package/package.json new file mode 100644 index 00000000..b0fe79d6 --- /dev/null +++ b/test/fixtures/find_extended_test/package/package.json @@ -0,0 +1,6 @@ +{ + "name": "test", + "coffeelintConfig": { + "extends" : "./.coffeelintrc" + } +} diff --git a/test/fixtures/find_extended_test/package/sixspaces.coffee b/test/fixtures/find_extended_test/package/sixspaces.coffee new file mode 100644 index 00000000..5a9e59d8 --- /dev/null +++ b/test/fixtures/find_extended_test/package/sixspaces.coffee @@ -0,0 +1,2 @@ +f = -> + null diff --git a/test/test_commandline.coffee b/test/test_commandline.coffee index bf101d71..a891bc1c 100644 --- a/test/test_commandline.coffee +++ b/test/test_commandline.coffee @@ -105,7 +105,7 @@ vows.describe('commandline').addBatch({ 'works': (error, stdout, stderr) -> assert.isNull(error) - 'with findconfig and local coffeelint.json and extended config': + 'with findconfig and local coffeelint.json and extended config (module)': topic: () -> args = [ 'fixtures/find_extended_test/invalid.coffee' @@ -116,6 +116,17 @@ vows.describe('commandline').addBatch({ 'works': (error, stdout, stderr) -> assert.isNull(error) + 'with findconfig and local package.json and extended config (relative)': + topic: () -> + args = [ + 'fixtures/find_extended_test/package/sixspaces.coffee' + ] + commandline args, this.callback + return undefined + + 'works': (error, stdout, stderr) -> + assert.isNull(error) + 'with custom configuration': topic: () -> args = [ @@ -200,7 +211,6 @@ vows.describe('commandline').addBatch({ return undefined 'works': (config, error, stdout, stderr) -> - assert.isNotNull(config) # This will throw an exception if it doesn't parse. JSON.parse config assert.isNotNull(stdout)