File sugar.js
has 4177 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*
* Sugar Library edge
*
* Freely distributable and licensed under the MIT-style license.
* Copyright (c) 2015 Andrew Plummer
Function getExtendedDate
has 192 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getExtendedDate(contextDate, f, localeCode, prefer, forceUTC) {
// TODO can we split this up into smaller methods?
var d, relative, baseLocalization, afterCallbacks, loc, set, unit, unitIndex, weekday, num, tmp, weekdayForward;
afterCallbacks = [];
Function setLocalization
has 109 lines of code (exceeds 25 allowed). Consider refactoring. Open
function setLocalization(localeCode, set) {
var loc;
function initializeField(name) {
var val = loc[name];
Function buildBase64
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildBase64(key) {
var encodeAscii, decodeAscii;
function catchEncodingError(fn) {
return function(str) {
Function buildDateMethods
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildDateMethods() {
extendSimilar(date, DateUnits, function(methods, u, i) {
var name = u.name, caps = simpleCapitalize(name), since, until;
u.addMethod = 'add' + caps + 's';
Function updateDate
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
function updateDate(d, params, reset, advance, prefer, weekdayForward) {
var specificityIndex;
function getParam(key) {
return isDefined(params[key]) ? params[key] : params[key + 's'];
Function runTagReplacements
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
function runTagReplacements(str, reg, strip, replacementFn, fullString) {
var match;
var result = '';
var currentIndex = 0;
Function addFormat
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
addFormat: function(src, allowsTime, match, variant, iso) {
var to = match || [], loc = this, time, timeMarkers, lastIsNumeral;
src = src.replace(/\s+/g, '[,. ]*');
src = src.replace(/\{([^,]+?)\}/g, function(all, k) {
Function every
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
'every': function(amount, fn) {
var increment,
precision,
dio,
unit,
Function buildStartEndsWith
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildStartEndsWith() {
var override = true;
try {
// If String#startsWith does not exist or alternately if it exists but
// correctly throws an error here, then there is no need to flag the
Function buildFormatTokens
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildFormatTokens() {
createPaddedToken('f', function(d) {
return callDateGet(d, 'Milliseconds');
}, true);
Function createLazyFunction
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createLazyFunction(fn, ms, immediate, limit) {
var queue = [], locked = false, execute, rounded, perExecution, result;
ms = ms || 1;
limit = limit || Infinity;
rounded = ceil(ms);
Function collateStrings
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function collateStrings(a, b) {
var aValue, bValue, aChar, bChar, aEquiv, bEquiv, index = 0, tiebreaker = 0;
var sortIgnore = sugarArray[AlphanumericSortIgnore];
var sortIgnoreCase = sugarArray[AlphanumericSortIgnoreCase];
Function stringify
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function stringify(thing, stack) {
var type = typeof thing, isObject, isArrayLike, klass, value, arr, key, i, len;
// Return quickly if string to save cycles
if (type === 'string') return thing;
Function mergeObject
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function mergeObject(target, source, deep, resolve) {
// Will not merge a primitive type.
if (!isObjectType(source)) return target;
Function compareDate
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function compareDate(d, find, localeCode, buffer, forceUTC) {
var p, t, min, max, override, accuracy = 0, loBuffer = 0, hiBuffer = 0;
p = getExtendedDate(null, find, localeCode, null, forceUTC);
if (buffer > 0) {
loBuffer = hiBuffer = buffer;
Function defineOnGlobal
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function defineOnGlobal(klass, name, instance, original, prop, existed, polyfill) {
Avoid deeply nested control flow statements. Open
if (set.sign && (tmp = loc.modifiersByName[set.sign])) {
// Unit and sign, ie "months ago", "weeks from now", etc.
num *= tmp.value;
}
Function arrayFind
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function arrayFind(arr, f, startIndex, loop, returnIndex, context) {
Function abbreviateNumber
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function abbreviateNumber(num, roundTo, str, mid, limit, bytes) {
Avoid deeply nested control flow statements. Open
if (set.shift && !set.unit) {
set.unit = loc.units[5];
}
Avoid deeply nested control flow statements. Open
if (set.shift && !set.unit) set.unit = loc.units[7];
Avoid deeply nested control flow statements. Open
if (set.shift) {
// Shift and unit, ie "next month", "last week", etc.
num *= (tmp = loc.modifiersByName[set.shift]) ? tmp.value : 0;
}
Avoid deeply nested control flow statements. Open
if (set.num && set.month) {
// If we have "the 2nd Tuesday of June", then pass the "weekdayForward" flag
// along to updateDate so that the date does not accidentally traverse into
// the previous month. This needs to be independent of the "prefer" flag because
// we are only ensuring that the weekday is in the future, not the entire date.
Function updateDate
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function updateDate(d, params, reset, advance, prefer, weekdayForward) {
Avoid deeply nested control flow statements. Open
if (isDefined(set.weekday)) {
// Units can be with non-relative dates, set here. ie "the day after monday"
setDate(d, [{ weekday: set.weekday }, true]);
delete set.weekday;
}
Function extendSimilar
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function extendSimilar(klass, set, fn, instance, polyfill, override) {
Avoid deeply nested control flow statements. Open
if (set.offsetSign === '-') {
set.offsetMinutes *= -1;
}
Consider simplifying this complex logical expression. Open
if (obj.start && obj.end) {
return obj.start >= this.start && obj.start <= this.end &&
obj.end >= this.start && obj.end <= this.end;
} else {
return obj >= this.start && obj <= this.end;
Function createDate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function createDate(contextDate, f, localeCode, prefer, forceUTC) {
Function entryAtIndex
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function entryAtIndex(obj, length, index, overshoot, isString) {
Function truncateString
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function truncateString(str, length, from, ellipsis, split) {
Function getExtendedDate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function getExtendedDate(contextDate, f, localeCode, prefer, forceUTC) {
Function setDelay
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function setDelay(fn, ms, after, scope, args) {
Function runTagReplacements
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function runTagReplacements(str, reg, strip, replacementFn, fullString) {
Function addFormat
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
addFormat: function(src, allowsTime, match, variant, iso) {
Function extend
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function extend(klass, methods, instance, polyfill, override) {
Function compareDate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function compareDate(d, find, localeCode, buffer, forceUTC) {
Avoid too many return
statements within this function. Open
return defaultMatcher(f);
Avoid too many return
statements within this function. Open
return -1;
Avoid too many return
statements within this function. Open
return 0;
Avoid too many return
statements within this function. Open
return 0;
Avoid too many return
statements within this function. Open
return fuzzyMatcher(f, isObject);
Avoid too many return
statements within this function. Open
return el[map];
Avoid too many return
statements within this function. Open
return 1;
Similar blocks of code found in 2 locations. Consider refactoring. Open
return new Range(
this.start > range.start ? this.start : range.start,
this.end < range.end ? this.end : range.end
);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 60.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
return new Range(
this.start < range.start ? this.start : range.start,
this.end > range.end ? this.end : range.end
);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 60.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76