File bootstrap-datepicker.js
has 1832 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* =========================================================
* bootstrap-datepicker.js
* Repo: https://github.com/eternicode/bootstrap-datepicker/
* Demo: http://eternicode.github.io/bootstrap-datepicker/
* Docs: http://bootstrap-datepicker.readthedocs.org/
Function fill
has 149 lines of code (exceeds 25 allowed). Consider refactoring. Open
fill: function(){
var d = new Date(this.viewDate),
year = d.getUTCFullYear(),
month = d.getUTCMonth(),
startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
Function parseDate
has 129 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseDate: function(date, format, language, assumeNearby){
if (!date)
return undefined;
if (date instanceof Date)
return date;
Function click
has 112 lines of code (exceeds 25 allowed). Consider refactoring. Open
click: function(e){
e.preventDefault();
e.stopPropagation();
var target, dir, day, year, month, monthChanged, yearChanged;
Function _process_options
has 102 lines of code (exceeds 25 allowed). Consider refactoring. Open
_process_options: function(opts){
// Store raw options for reference
this._o = $.extend({}, this._o, opts);
// Processed options
var o = this.o = $.extend({}, this._o);
Function keydown
has 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
keydown: function(e){
if (!this.picker.is(':visible')){
if (e.keyCode === 40 || e.keyCode === 27) { // allow down to re-show picker
this.show();
e.stopPropagation();
Function _buildEvents
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
_buildEvents: function(){
var events = {
keyup: $.proxy(function(e){
if ($.inArray(e.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1)
this.update();
Function place
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
place: function(){
if (this.isInline)
return this;
var calendarWidth = this.picker.outerWidth(),
calendarHeight = this.picker.outerHeight(),
Function update
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
update: function(){
if (!this._allow_update)
return this;
var oldDates = this.dates.copy(),
Function _fill_yearsView
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
_fill_yearsView: function(selector, cssClass, factor, step, currentYear, startYear, endYear, callback){
var html, view, year, steps, startStep, endStep, thisYear, i, classes, tooltip, before;
html = '';
view = this.picker.find(selector);
Function Datepicker
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
var Datepicker = function(element, options){
$(element).data('datepicker', this);
this._process_options(options);
this.dates = new DateArray();
Function getClassNames
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
getClassNames: function(date){
var cls = [],
year = this.viewDate.getUTCFullYear(),
month = this.viewDate.getUTCMonth(),
today = new Date();
Function updateNavArrows
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
updateNavArrows: function(){
if (!this._allow_update)
return;
var d = new Date(this.viewDate),
Function DateArray
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
var DateArray = (function(){
var extras = {
get: function(i){
return this.slice(i)[0];
},
Function datepickerPlugin
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
var datepickerPlugin = function(option){
var args = Array.apply(null, arguments);
args.shift();
var internal_return;
this.each(function(){
Function moveMonth
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
moveMonth: function(date, dir){
if (!isValidDate(date))
return this.o.defaultViewDate;
if (!dir)
return date;
Function dateUpdated
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
dateUpdated: function(e){
// `this.updating` is a workaround for preventing infinite recursion
// between `changeDate` triggering and `setUTCDate` calling. Until
// there is a better mechanism.
if (this.updating)
Function formatDate
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
formatDate: function(date, format, language){
if (!date)
return '';
if (typeof format === 'string')
format = DPGlobal.parseFormat(format);
Function _fill_yearsView
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
_fill_yearsView: function(selector, cssClass, factor, step, currentYear, startYear, endYear, callback){
Avoid deeply nested control flow statements. Open
else if (e.keyCode === 37 || e.keyCode === 39){
newViewDate = this.moveAvailableDate(focusDate, dir, 'moveDay');
}
else if (!this.weekOfDateIsDisabled(focusDate)){
newViewDate = this.moveAvailableDate(focusDate, dir, 'moveWeek');
Avoid deeply nested control flow statements. Open
if (e.keyCode === 38 || e.keyCode === 40) {
dir = dir * 4;
}
Avoid deeply nested control flow statements. Open
if (newViewDate)
this._trigger('changeMonth', this.viewDate);
Avoid too many return
statements within this function. Open
return default_value === undefined ? false : default_value;
Avoid too many return
statements within this function. Open
return 4;
Avoid too many return
statements within this function. Open
return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
Avoid too many return
statements within this function. Open
return date;
Similar blocks of code found in 2 locations. Consider refactoring. Open
(function(factory){
if (typeof define === "function" && define.amd) {
define(["jquery"], factory);
} else if (typeof exports === 'object') {
factory(require('jquery'));
- 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 20577.
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