File Sortable.js
has 779 lines of code (exceeds 250 allowed). Consider refactoring. Open
/**!
* Sortable
* @author RubaXa <trash@rubaxa.org>
* @license MIT
*/
Function _onDragOver
has 93 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onDragOver: function (/**Event*/evt) {
var el = this.el,
target,
dragRect,
revert,
Function _autoScroll
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
_autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
// Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
if (rootEl && options.scroll) {
var el,
rect,
Function _onDrop
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onDrop: function (/**Event*/evt) {
var el = this.el,
options = this.options;
clearInterval(this._loopId);
Consider simplifying this complex logical expression. Open
if (activeGroup && !options.disabled &&
(isOwner
? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
: activeGroup.pull && groupPut && (
(activeGroup.name === group.name) || // by Name
Function Sortable
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
function Sortable(el, options) {
this.el = el; // root element
this.options = options = _extend({}, options);
Function _onDragStart
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
var dataTransfer = evt.dataTransfer,
options = this.options;
this._offUpEvents();
Function _onTapStart
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onTapStart: function (/** Event|TouchEvent */evt) {
var _this = this,
el = this.el,
options = this.options,
type = evt.type,
Function _prepareDragStart
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
_prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
var _this = this,
el = _this.el,
options = _this.options,
ownerDocument = el.ownerDocument,
Consider simplifying this complex logical expression. Open
if (
(tag === '>*' && el.parentNode === ctx) || (
(tag === '' || el.nodeName.toUpperCase() == tag) &&
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
)
Consider simplifying this complex logical expression. Open
else if (floating) {
after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
} else {
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
}
Function _dispatchEvent
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
Avoid deeply nested control flow statements. Open
while (i--) {
touchDragOverListeners[i]({
clientX: touchEvt.clientX,
clientY: touchEvt.clientY,
target: target,
Avoid deeply nested control flow statements. Open
if ((scrollEl.offsetWidth < scrollEl.scrollWidth) ||
(scrollEl.offsetHeight < scrollEl.scrollHeight)
) {
break;
}
Avoid deeply nested control flow statements. Open
if (moveVector === 1 || moveVector === -1) {
after = (moveVector === 1);
}
else if (floating) {
after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
Avoid deeply nested control flow statements. Open
if (after && !nextSibling) {
el.appendChild(dragEl);
} else {
target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
}
Function _onMove
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) {
Avoid too many return
statements within this function. Open
return;
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (dst && src) {
for (var key in src) {
if (src.hasOwnProperty(key)) {
dst[key] = src[key];
}
- 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 46.
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