Codacy issue fixes

This commit is contained in:
Angelos Chalaris
2018-06-18 21:18:53 +03:00
parent ba3fcbb95a
commit 17fb304f04
32 changed files with 45 additions and 45 deletions

View File

@ -5,7 +5,7 @@
// Load modules // Load modules
const fs = require('fs-extra'), path = require('path'); const fs = require('fs-extra'), path = require('path');
const child_process = require('child_process'); const childProcess = require('child_process');
const chalk = require('chalk'); const chalk = require('chalk');
const util = require('./util'); const util = require('./util');
if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') { if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') {
@ -84,7 +84,7 @@ snippetFiles
}); });
try { try {
fs.writeFileSync(path.join(TEST_PATH,'testlog'),`Test log for: ${new Date().toString()}\n`); fs.writeFileSync(path.join(TEST_PATH,'testlog'),`Test log for: ${new Date().toString()}\n`);
child_process.execSync(`npm test`); childProcess.execSync(`npm test`);
} }
catch (e) { catch (e) {
fs.appendFileSync(path.join(TEST_PATH,'testlog')); fs.appendFileSync(path.join(TEST_PATH,'testlog'));

View File

@ -11,7 +11,7 @@ test('Returns -1 when not found', () => {
expect(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21)).toBe(-1); expect(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21)).toBe(-1);
}); });
test('Works with empty arrays', () => { test('Works with empty arrays', () => {
expect(binarySearch([], 21)).toBe(-1) expect(binarySearch([], 21)).toBe(-1);
}); });
test('Works for one element arrays', () => { test('Works for one element arrays', () => {
expect(binarySearch([1], 1)).toBe(0); expect(binarySearch([1], 1)).toBe(0);

View File

@ -12,5 +12,5 @@ var view = {
}; };
bindAll(view, 'click'); bindAll(view, 'click');
test('Binds to an object context', () => { test('Binds to an object context', () => {
expect(view.click()).toBe('clicked docs') expect(view.click()).toBe('clicked docs');
}); });

View File

@ -12,5 +12,5 @@ const freddy = {
}; };
const freddyBound = bindKey(freddy, 'greet'); const freddyBound = bindKey(freddy, 'greet');
test('Binds function to an object context', () => { test('Binds function to an object context', () => {
expect(freddyBound('hi', '!')).toBe('hi fred!') expect(freddyBound('hi', '!')).toBe('hi fred!');
}); });

View File

@ -14,8 +14,8 @@ test('Works for arrays with multiple value', () => {
expect(castArray([1,2,3])).toEqual( [1,2,3]); expect(castArray([1,2,3])).toEqual( [1,2,3]);
}); });
test('Works for strings', () => { test('Works for strings', () => {
expect(castArray('test')).toEqual(['test']) expect(castArray('test')).toEqual(['test']);
}); });
test('Works for objects', () => { test('Works for objects', () => {
expect(castArray({})).toEqual([{}]) expect(castArray({})).toEqual([{}]);
}); });

View File

@ -8,16 +8,16 @@ test('chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] ', () => {
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1,2],[3,4],[5]]); expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1,2],[3,4],[5]]);
}); });
test('chunk([]) returns []', () => { test('chunk([]) returns []', () => {
expect(chunk([])).toEqual([]) expect(chunk([])).toEqual([]);
}); });
test('chunk(123) returns []', () => { test('chunk(123) returns []', () => {
expect(chunk(123)).toEqual([]) expect(chunk(123)).toEqual([]);
}); });
test('chunk({ a: 123}) returns []', () => { test('chunk({ a: 123}) returns []', () => {
expect(chunk({ a: 123})).toEqual([]) expect(chunk({ a: 123})).toEqual([]);
}); });
test('chunk(string, 2) returns [ st, ri, ng ]', () => { test('chunk(string, 2) returns [ st, ri, ng ]', () => {
expect(chunk('string', 2)).toEqual( [ 'st', 'ri', 'ng' ]) expect(chunk('string', 2)).toEqual( [ 'st', 'ri', 'ng' ]);
}); });
test('chunk() throws an error', () => { test('chunk() throws an error', () => {
expect(() => {chunk();}).toThrow(); expect(() => {chunk();}).toThrow();

View File

@ -5,5 +5,5 @@ test('clampNumber is a Function', () => {
expect(clampNumber).toBeInstanceOf(Function); expect(clampNumber).toBeInstanceOf(Function);
}); });
test('Clamps num within the inclusive range specified by the boundary values a and b', () => { test('Clamps num within the inclusive range specified by the boundary values a and b', () => {
expect(clampNumber(2, 3, 5)).toBe(3) expect(clampNumber(2, 3, 5)).toBe(3);
}); });

View File

@ -5,5 +5,5 @@ test('coalesce is a Function', () => {
expect(coalesce).toBeInstanceOf(Function); expect(coalesce).toBeInstanceOf(Function);
}); });
test('Returns the first non-null/undefined argument', () => { test('Returns the first non-null/undefined argument', () => {
expect(coalesce(null, undefined, '', NaN, 'Waldo')).toEqual('') expect(coalesce(null, undefined, '', NaN, 'Waldo')).toEqual('');
}); });

View File

@ -6,5 +6,5 @@ test('coalesceFactory is a Function', () => {
}); });
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
test('Returns a customized coalesce function', () => { test('Returns a customized coalesce function', () => {
expect(customCoalesce(undefined, null, NaN, '', 'Waldo')).toEqual('Waldo') expect(customCoalesce(undefined, null, NaN, '', 'Waldo')).toEqual('Waldo');
}); });

View File

@ -8,5 +8,5 @@ test('Works with default parameter', () => {
expect(decapitalize('FooBar')).toBe('fooBar'); expect(decapitalize('FooBar')).toBe('fooBar');
}); });
test('Works with second parameter set to true', () => { test('Works with second parameter set to true', () => {
expect(decapitalize('FooBar', true)).toBe('fOOBAR') expect(decapitalize('FooBar', true)).toBe('fOOBAR');
}); });

View File

@ -5,5 +5,5 @@ test('difference is a Function', () => {
expect(difference).toBeInstanceOf(Function); expect(difference).toBeInstanceOf(Function);
}); });
test('Returns the difference between two arrays', () => { test('Returns the difference between two arrays', () => {
expect(difference([1, 2, 3], [1, 2, 4])).toEqual([3]) expect(difference([1, 2, 3], [1, 2, 4])).toEqual([3]);
}); });

View File

@ -5,5 +5,5 @@ test('digitize is a Function', () => {
expect(digitize).toBeInstanceOf(Function); expect(digitize).toBeInstanceOf(Function);
}); });
test('Converts a number to an array of digits', () => { test('Converts a number to an array of digits', () => {
expect(digitize(123)).toEqual([1, 2,3]) expect(digitize(123)).toEqual([1, 2,3]);
}); });

View File

@ -5,7 +5,7 @@ test('dropRight is a Function', () => {
expect(dropRight).toBeInstanceOf(Function); expect(dropRight).toBeInstanceOf(Function);
}); });
test('Returns a new array with n elements removed from the right', () => { test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3])).toEqual([1, 2]) expect(dropRight([1, 2, 3])).toEqual([1, 2]);
}); });
test('Returns a new array with n elements removed from the right', () => { test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3], 2)).toEqual([1]); expect(dropRight([1, 2, 3], 2)).toEqual([1]);

View File

@ -5,5 +5,5 @@ test('dropRightWhile is a Function', () => {
expect(dropRightWhile).toBeInstanceOf(Function); expect(dropRightWhile).toBeInstanceOf(Function);
}); });
test('Removes elements from the end of an array until the passed function returns true.', () => { test('Removes elements from the end of an array until the passed function returns true.', () => {
expect(dropRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([1, 2]) expect(dropRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([1, 2]);
}); });

View File

@ -5,5 +5,5 @@ test('dropWhile is a Function', () => {
expect(dropWhile).toBeInstanceOf(Function); expect(dropWhile).toBeInstanceOf(Function);
}); });
test('Removes elements in an array until the passed function returns true.', () => { test('Removes elements in an array until the passed function returns true.', () => {
expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3,4]) expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3,4]);
}); });

View File

@ -5,5 +5,5 @@ test('escapeHTML is a Function', () => {
expect(escapeHTML).toBeInstanceOf(Function); expect(escapeHTML).toBeInstanceOf(Function);
}); });
test('Escapes a string for use in HTML', () => { test('Escapes a string for use in HTML', () => {
expect(escapeHTML('<a href="#">Me & you</a>')).toBe('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;') expect(escapeHTML('<a href="#">Me & you</a>')).toBe('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;');
}); });

View File

@ -5,5 +5,5 @@ test('escapeRegExp is a Function', () => {
expect(escapeRegExp).toBeInstanceOf(Function); expect(escapeRegExp).toBeInstanceOf(Function);
}); });
test('Escapes a string to use in a regular expression', () => { test('Escapes a string to use in a regular expression', () => {
expect(escapeRegExp('(test)')).toBe('\\(test\\)') expect(escapeRegExp('(test)')).toBe('\\(test\\)');
}); });

View File

@ -7,5 +7,5 @@ test('forEachRight is a Function', () => {
let output = ''; let output = '';
forEachRight([1, 2, 3, 4], val => output+=val); forEachRight([1, 2, 3, 4], val => output+=val);
test('Iterates over the array in reverse', () => { test('Iterates over the array in reverse', () => {
expect(output).toBe('4321') expect(output).toBe('4321');
}); });

View File

@ -5,11 +5,11 @@ test('geometricProgression is a Function', () => {
expect(geometricProgression).toBeInstanceOf(Function); expect(geometricProgression).toBeInstanceOf(Function);
}); });
test('Initializes an array containing the numbers in the specified range', () => { test('Initializes an array containing the numbers in the specified range', () => {
expect(geometricProgression(256)).toEqual([1, 2, 4, 8, 16, 32, 64, 128, 256]) expect(geometricProgression(256)).toEqual([1, 2, 4, 8, 16, 32, 64, 128, 256]);
}); });
test('Initializes an array containing the numbers in the specified range', () => { test('Initializes an array containing the numbers in the specified range', () => {
expect(geometricProgression(256, 3)).toEqual([3, 6, 12, 24, 48, 96, 192]) expect(geometricProgression(256, 3)).toEqual([3, 6, 12, 24, 48, 96, 192]);
}); });
test('Initializes an array containing the numbers in the specified range', () => { test('Initializes an array containing the numbers in the specified range', () => {
expect(geometricProgression(256, 1, 4)).toEqual([1, 4, 16, 64, 256]) expect(geometricProgression(256, 1, 4)).toEqual([1, 4, 16, 64, 256]);
}); });

View File

@ -6,5 +6,5 @@ test('get is a Function', () => {
}); });
const obj = { selector: { to: { val: 'val to get' } } }; const obj = { selector: { to: { val: 'val to get' } } };
test('Retrieve a property indicated by the selector from an object.', () => { test('Retrieve a property indicated by the selector from an object.', () => {
expect(get(obj, 'selector.to.val')).toEqual(['val to get']) expect(get(obj, 'selector.to.val')).toEqual(['val to get']);
}); });

View File

@ -5,5 +5,5 @@ test('initializeArrayWithValues is a Function', () => {
expect(initializeArrayWithValues).toBeInstanceOf(Function); expect(initializeArrayWithValues).toBeInstanceOf(Function);
}); });
test('Initializes and fills an array with the specified values', () => { test('Initializes and fills an array with the specified values', () => {
expect(initializeArrayWithValues(5, 2)).toEqual([2, 2, 2, 2, 2]) expect(initializeArrayWithValues(5, 2)).toEqual([2, 2, 2, 2, 2]);
}); });

View File

@ -8,7 +8,7 @@ test('Works for arrays with data', () => {
expect(is(Array, [1])).toBeTruthy(); expect(is(Array, [1])).toBeTruthy();
}); });
test('Works for empty arrays', () => { test('Works for empty arrays', () => {
expect(is(Array, [])).toBeTruthy() expect(is(Array, [])).toBeTruthy();
}); });
test('Works for arrays, not objects', () => { test('Works for arrays, not objects', () => {
expect(is(Array, {})).toBeFalsy(); expect(is(Array, {})).toBeFalsy();
@ -41,10 +41,10 @@ test('Works for numbers - returns true for primitive', () => {
expect(is(Number, 1)).toBeTruthy(); expect(is(Number, 1)).toBeTruthy();
}); });
test('Works for numbers - returns true when using constructor', () => { test('Works for numbers - returns true when using constructor', () => {
expect(is(Number, new Number('10'))).toBeTruthy() expect(is(Number, new Number('10'))).toBeTruthy();
}); });
test('Works for booleans - returns true for primitive', () => { test('Works for booleans - returns true for primitive', () => {
expect(is(Boolean, false)).toBeTruthy() expect(is(Boolean, false)).toBeTruthy();
}); });
test('Works for booleans - returns true when using constructor', () => { test('Works for booleans - returns true when using constructor', () => {
expect(is(Boolean, new Boolean(false))).toBeTruthy(); expect(is(Boolean, new Boolean(false))).toBeTruthy();

View File

@ -5,7 +5,7 @@ test('isArray is a Function', () => {
expect(isArray).toBeInstanceOf(Function); expect(isArray).toBeInstanceOf(Function);
}); });
test('passed value is an array', () => { test('passed value is an array', () => {
expect(isArray([1])).toBeTruthy() expect(isArray([1])).toBeTruthy();
}); });
test('passed value is not an array', () => { test('passed value is not an array', () => {
expect(isArray('array')).toBeFalsy(); expect(isArray('array')).toBeFalsy();

View File

@ -5,7 +5,7 @@ test('isArrayLike is a Function', () => {
expect(isArrayLike).toBeInstanceOf(Function); expect(isArrayLike).toBeInstanceOf(Function);
}); });
test('Returns true for a string', () => { test('Returns true for a string', () => {
expect(isArrayLike('abc')).toBeTruthy() expect(isArrayLike('abc')).toBeTruthy();
}); });
test('Returns true for an array', () => { test('Returns true for an array', () => {
expect(isArrayLike([1,2,3])).toBeTruthy(); expect(isArrayLike([1,2,3])).toBeTruthy();

View File

@ -5,8 +5,8 @@ test('median is a Function', () => {
expect(median).toBeInstanceOf(Function); expect(median).toBeInstanceOf(Function);
}); });
test('Returns the median of an array of numbers', () => { test('Returns the median of an array of numbers', () => {
expect(median([5, 6, 50, 1, -5])).toBe(5) expect(median([5, 6, 50, 1, -5])).toBe(5);
}); });
test('Returns the median of an array of numbers', () => { test('Returns the median of an array of numbers', () => {
expect(median([1, 2, 3])).toBe(2) expect(median([1, 2, 3])).toBe(2);
}); });

View File

@ -7,5 +7,5 @@ test('pull is a Function', () => {
let myArray = ['a', 'b', 'c', 'a', 'b', 'c']; let myArray = ['a', 'b', 'c', 'a', 'b', 'c'];
pull(myArray, 'a', 'c'); pull(myArray, 'a', 'c');
test('Pulls the specified values', () => { test('Pulls the specified values', () => {
expect(myArray).toEqual(['b','b']) expect(myArray).toEqual(['b','b']);
}); });

View File

@ -6,7 +6,7 @@ test('randomHexColorCode is a Function', () => {
}); });
test('randomHexColorCode has to proper length', () => { test('randomHexColorCode has to proper length', () => {
expect(randomHexColorCode().length).toBe(7); expect(randomHexColorCode().length).toBe(7);
}) });
test('The color code starts with "#"', () => { test('The color code starts with "#"', () => {
expect(randomHexColorCode().startsWith('#')).toBeTruthy(); expect(randomHexColorCode().startsWith('#')).toBeTruthy();
}); });

View File

@ -17,5 +17,5 @@ const data = [
} }
]; ];
test('Filter an array of objects based on a condition while also filtering out unspecified keys.', () => { test('Filter an array of objects based on a condition while also filtering out unspecified keys.', () => {
expect(reducedFilter(data, ['id', 'name'], item => item.age > 24)).toEqual([{ id: 2, name: 'mike'}]) expect(reducedFilter(data, ['id', 'name'], item => item.age > 24)).toEqual([{ id: 2, name: 'mike'}]);
}); });

View File

@ -12,7 +12,7 @@ test('Returns a random sample of specified size from an array', () => {
expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy(); expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy();
}); });
test('Returns all elements in an array if n >= length', () => { test('Returns all elements in an array if n >= length', () => {
expect(sampleSize(arr, 5).length).toBe(4) expect(sampleSize(arr, 5).length).toBe(4);
}); });
test('Returns an empty array if original array is empty', () => { test('Returns an empty array if original array is empty', () => {
expect(sampleSize([], 2)).toEqual([]); expect(sampleSize([], 2)).toEqual([]);

View File

@ -8,5 +8,5 @@ test('Returns an array with n elements removed from the end', () => {
expect(takeRight([1, 2, 3], 2)).toEqual([2, 3]); expect(takeRight([1, 2, 3], 2)).toEqual([2, 3]);
}); });
test('Returns an array with n elements removed from the end', () => { test('Returns an array with n elements removed from the end', () => {
expect(takeRight([1, 2, 3])).toEqual([3]) expect(takeRight([1, 2, 3])).toEqual([3]);
}); });

View File

@ -14,10 +14,10 @@ test('toKebabCase(\'some-mixed-string With spaces-underscores-and-hyphens\') ret
expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe('some-mixed-string-with-spaces-underscores-and-hyphens'); expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe('some-mixed-string-with-spaces-underscores-and-hyphens');
}); });
test('toKebabCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', () => { test('toKebabCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', () => {
expect(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html') expect(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html');
}); });
test('toKebabCase() returns undefined', () => { test('toKebabCase() returns undefined', () => {
expect(toKebabCase()).toBe(undefined) expect(toKebabCase()).toBe(undefined);
}); });
test('toKebabCase([]) throws an erro', () => { test('toKebabCase([]) throws an erro', () => {
expect(() => { toKebabCase([]); }).toThrow(); expect(() => { toKebabCase([]); }).toThrow();

View File

@ -14,7 +14,7 @@ test('toSnakeCase(\'some-mixed_string With spaces_underscores-and-hyphens\') ret
expect(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens')).toBe('some_mixed_string_with_spaces_underscores_and_hyphens'); expect(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens')).toBe('some_mixed_string_with_spaces_underscores_and_hyphens');
}); });
test('toSnakeCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', () => { test('toSnakeCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', () => {
expect(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html') expect(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html');
}); });
test('toSnakeCase() returns undefined', () => { test('toSnakeCase() returns undefined', () => {
expect(toSnakeCase()).toBe(undefined); expect(toSnakeCase()).toBe(undefined);