diff --git a/.eslintrc.js b/.eslintrc.js index b89a5f6346d253bde865dd00cf31274bec9e2cff..13663188254b104f3683c15e2fb5de0693d39ecb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,7 +10,6 @@ module.exports = { 'promise', ], 'rules': { - 'max-len': [1, 120], 'no-console': 0, 'no-use-before-define': 0, 'promise/always-return': 'error', diff --git a/src/helpers/packageJson.js b/src/helpers/packageJson.js index 4c3b44faf1fa4a31b60d816bb029a9a24bab9412..aa20aba0d32da2c562badbbc2c9ed89b535d83e0 100644 --- a/src/helpers/packageJson.js +++ b/src/helpers/packageJson.js @@ -17,11 +17,9 @@ module.exports = { // Iterate through the rest of the file for (; searchIndex < currentFileContent.length; searchIndex += 1) { // First check if we have a hit for the old version - if (currentFileContent.substring(searchIndex, searchIndex + searchString.length) === searchString) { + if (matchAt(currentFileContent, searchIndex, searchString)) { // Now test if the result matches - const testContent = currentFileContent.substr(0, searchIndex) + - newString + - currentFileContent.substr(searchIndex + searchString.length); + const testContent = replaceAt(currentFileContent, searchIndex, searchString, newString); // Compare the parsed JSON structure of old and new if (_.isEqual(parsedContents, JSON.parse(testContent))) { newFileContent = testContent; @@ -35,3 +33,13 @@ module.exports = { return newFileContent; }, }; + +// Return true if the match string is found at index in content +function matchAt(content, index, match) { + return content.substring(index, index + match.length) === match; +} + +// Replace oldString with newString at location index of content +function replaceAt(content, index, oldString, newString) { + return content.substr(0, index) + newString + content.substr(index, oldString.length); +}