From d4dc4e262bb11aaa19b6a0cf94175262d35943b4 Mon Sep 17 00:00:00 2001 From: Tyler Reitz Date: Sun, 3 Jun 2018 17:38:07 -0700 Subject: [PATCH 1/2] adds helpful error message when files is overridden or empty --- src/util/__tests__/config-file.js | 17 +++++++++++++++++ src/util/config-file.js | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/util/__tests__/config-file.js b/src/util/__tests__/config-file.js index 4314059c..6af8ff2c 100644 --- a/src/util/__tests__/config-file.js +++ b/src/util/__tests__/config-file.js @@ -19,6 +19,15 @@ const NoNameConfigFile = { contributorsPerLine: 6, contributors: [], } +const NoFilesConfigFile = { + projectOwner: 'jfmengels', + projectName: 'all-contributors-cli', + imageSize: 100, + commit: false, + contributorsPerLine: 6, + contributors: [], + files: [], +} test('Reading an absent configuration file throws a helpful error', () => { expect(() => configFile.readConfig(absentFile)).toThrowError( @@ -41,3 +50,11 @@ test('Should throw error and not allow editing config file if project name or ow configFile.writeConfig(incompleteConfigFilePath, NoNameConfigFile), ).toThrow(`Error! Project name is not set in ${incompleteConfigFilePath}`) }) + +test(`throws if 'files' was overridden in .all-contributorsrc and is empty`, () => { + expect(() => + configFile.writeConfig(incompleteConfigFilePath, NoFilesConfigFile), + ).toThrow( + `Error! Project files was overridden and is empty in ${incompleteConfigFilePath}`, + ) +}) diff --git a/src/util/config-file.js b/src/util/config-file.js index 28b03f55..3fd4853c 100644 --- a/src/util/config-file.js +++ b/src/util/config-file.js @@ -24,6 +24,11 @@ function writeConfig(configPath, content) { if (!content.projectName) { throw new Error(`Error! Project name is not set in ${configPath}`) } + if (!content.files.length) { + throw new Error( + `Error! Project files was overridden and is empty in ${configPath}`, + ) + } return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`) } From 94422bdc9e1a77838a5238f50ce9d8f6199cea1e Mon Sep 17 00:00:00 2001 From: Tyler Reitz Date: Tue, 19 Jun 2018 19:59:47 -0700 Subject: [PATCH 2/2] fix: d4dc4e2-introduced error The prior commit to this branch d4dc4e2 introduced an error in the util/config.js file where it checks for the length of the content.files property, whether that property exists in the config or not. --- src/util/config-file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/config-file.js b/src/util/config-file.js index 3fd4853c..ac9515ae 100644 --- a/src/util/config-file.js +++ b/src/util/config-file.js @@ -24,7 +24,7 @@ function writeConfig(configPath, content) { if (!content.projectName) { throw new Error(`Error! Project name is not set in ${configPath}`) } - if (!content.files.length) { + if (content.files && !content.files.length) { throw new Error( `Error! Project files was overridden and is empty in ${configPath}`, )