File util.js
has 538 lines of code (exceeds 250 allowed). Consider refactoring. Open
'use strict';
var config = require( './config.json' );
var portletLinkOptions = require( './portletLinkOptions.json' );
var infinityValues = require( './infinityValues.json' );
util
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
var util = {
/**
* Encode the string like PHP's rawurlencode.
*
Function addPortletLink
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
addPortletLink: function ( portletId, href, text, id, tooltip, accesskey, nextnode ) {
if ( !portletId ) {
// Avoid confusing id="undefined" lookup
return null;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function addPortletLink
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
addPortletLink: function ( portletId, href, text, id, tooltip, accesskey, nextnode ) {
if ( !portletId ) {
// Avoid confusing id="undefined" lookup
return null;
}
Function parseImageUrl
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
parseImageUrl: function ( url ) {
var name, decodedName, width, urlTemplate;
// thumb.php-generated thumbnails
// thumb.php?f=<name>&w[idth]=<width>[px]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function prettifyIP
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
prettifyIP: function ( ip ) {
ip = this.sanitizeIP( ip );
if ( ip === null ) {
return null;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseImageUrl
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseImageUrl: function ( url ) {
var name, decodedName, width, urlTemplate;
// thumb.php-generated thumbnails
// thumb.php?f=<name>&w[idth]=<width>[px]
Function sanitizeIP
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
sanitizeIP: function ( ip ) {
if ( typeof ip !== 'string' ) {
return null;
}
ip = ip.trim();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function sanitizeIP
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
sanitizeIP: function ( ip ) {
if ( typeof ip !== 'string' ) {
return null;
}
ip = ip.trim();
Function isIPv6Address
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
isIPv6Address: function ( address, allowBlock ) {
var block, RE_IPV6_ADD;
if ( typeof address !== 'string' ) {
return false;
Function isTemporaryUser
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
isTemporaryUser: function ( username ) {
// Just return early if temporary accounts are disabled.
if ( !config.AutoCreateTempUser.enabled ) {
return false;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function prettifyIP
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
prettifyIP: function ( ip ) {
ip = this.sanitizeIP( ip );
if ( ip === null ) {
return null;
}
Function addPortlet
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
addPortlet: function ( id, label, before ) {
const portlet = document.createElement( 'div' );
// These classes should be kept in sync with includes/skins/components/SkinComponentMenu.php.
// eslint-disable-next-line mediawiki/class-doc
portlet.classList.add( 'mw-portlet', 'mw-portlet-' + id, 'emptyPortlet',
Function isTemporaryUser
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
isTemporaryUser: function ( username ) {
// Just return early if temporary accounts are disabled.
if ( !config.AutoCreateTempUser.enabled ) {
return false;
}
Function getUrl
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
getUrl: function ( pageName, params ) {
var fragmentIdx, url, query, fragment,
title = typeof pageName === 'string' ? pageName : mw.config.get( 'wgPageName' );
// Find any fragment
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function addPortletLink
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
addPortletLink: function ( portletId, href, text, id, tooltip, accesskey, nextnode ) {
Function addPortlet
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
addPortlet: function ( id, label, before ) {
const portlet = document.createElement( 'div' );
// These classes should be kept in sync with includes/skins/components/SkinComponentMenu.php.
// eslint-disable-next-line mediawiki/class-doc
portlet.classList.add( 'mw-portlet', 'mw-portlet-' + id, 'emptyPortlet',
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return ip.replace( /(^|:)0+(([0-9A-Fa-f]{1,4}))/g, '$1$2' );
Similar blocks of code found in 2 locations. Consider refactoring. Open
return function () {
var context = this,
args = arguments,
later = function () {
timeout = null;
- 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 115.
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 function () {
// Check how long it's been since the last time the function was
// called, and whether it's more or less than the requested throttle
// period. If it's less, run the function immediately. If it's more,
// set a timeout for the remaining time -- but don't replace an
- 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 83.
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 encodeURIComponent( String( str ) )
.replace( /!/g, '%21' )
.replace( /'/g, '%27' )
.replace( /\(/g, '%28' )
.replace( /\)/g, '%29' )
- 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 63.
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
showPortlet: function ( portletId ) {
var portlet = document.getElementById( portletId );
if ( portlet ) {
portlet.classList.remove( 'emptyPortlet' );
}
- 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 50.
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
hidePortlet: function ( portletId ) {
var portlet = document.getElementById( portletId );
if ( portlet ) {
portlet.classList.add( 'emptyPortlet' );
}
- 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 50.
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