Showing 551 of 551 total issues
Function accessPointsFn
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const accessPointsFn = (cmd, args, cb) => {
if (common.os_release >= '12.0') {
sudo(cmd, args, (err, stdout, stderr) => {
if (stderr) logger.error(stderr);
return cb(err, stdout);
- 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 get_battery_status
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
exports.get_battery_status = function(callback){
exec('pmset -g batt', function(err, stdout){
if (err) return callback(err);
- 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 notify_action
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
exports.notify_action = function (status, id, name, opts, err, out) {
Function send
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
const send = function (attempt, method, path, data, options, cb) {
Function getLocation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const getLocation = (cb) => {
// eslint-disable-next-line consistent-return
system.get_os_version((_err, version) => {
if (version && greaterOrEqual(version, '10.6.0')) {
socket.writeMessage(nameArray[0], (err, data) => {
- 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 validate_new_user_fields
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def validate_new_user_fields(self, name, email, terms, age, passwd, passwd2 = None):
Function start
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
exports.start = (id, opts, cb) => {
const done = (err = null) => {
if (err) return cb(err);
if (!emitter) emitter = new Emitter();
cb(err, emitter);
- 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 reactToCheckLocationPerms
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const reactToCheckLocationPerms = (data) => {
permissionFile.setData('nativeLocation', data[1].result, () => {
network.isWifiPermissionActive((output) => {
permissionFile.setData('wifiLocation', stringBooleanOrEmpty(output), () => {
// eslint-disable-next-line max-len
- 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 deeply nested control flow statements. Open
if (reqPreyConf[count].possiblevalues) {
if (reqPreyConf[count].value && !reqPreyConf[count].value.test(line)) {
somethingWrong = true;
dataToFix[reqPreyConf[count].name] = false;
}
Function sync
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
exports.sync = (success, id, err, triggersSync, storedSync, cb) => {
let triggers = [...triggersSync];
const stored = [...storedSync];
const watching = [];
- 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 requestNativePermission
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const requestNativePermission = (cb) => {
if (osName.localeCompare('mac') !== 0) return cb(new Error('Action only allowed on MacOS'));
// eslint-disable-next-line consistent-return
socket.writeMessage(nameArray[1], () => {
const permissionNative = permissionFile.getData('nativeLocation');
- 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 linkDevice
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const linkDevice = (cb) => {
getDeviceData((err, deviceData) => {
const data = deviceData;
if (err) return cb(err);
- 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 deeply nested control flow statements. Open
if (preyConfDataToWrite) {
dataToInsert = preyConfDataToWrite[reqPreyConf[count].name] ? preyConfDataToWrite[reqPreyConf[count].name] : '';
} else {
dataToInsert = reqPreyConf[count].default
|| ((typeof reqPreyConf[count].default === 'boolean') && reqPreyConf[count].default === false) ? reqPreyConf[count].default : '';
Avoid deeply nested control flow statements. Open
if (line.match(reqPreyConf[count].value)) {
if (reqPreyConf[count].word === 'api_key') {
apiKeyValue = true;
} else if (reqPreyConf[count].word === 'device_key') {
deviceKeyValue = true;
Avoid deeply nested control flow statements. Open
if (match) {
const value = match[1];
const matchValue = reqPreyConf[count].possiblevalues.exec(value);
if (matchValue) {
preyConfData[reqPreyConf[count].name] = value;
Function start
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
exports.start = function (opts, cb) {
hooks.on('connected', () => {
network.get_active_access_point((err, ap) => {
if (was_disconnected) {
logger.info(`Connection achieved! ${ap ? ap.ssid || '' : ''}`);
- 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 drawImage
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def drawImage(self, file, width, height, x, y, view):
Function start
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
exports.start = (opts, cb) => {
hooks.on('mac_address_changed', () => {
fetchLocation('mac-address');
});
- 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 __init__
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def __init__(self):
button_text = "Close"
title = args.title
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
var cpu_info = {
model: cpus[0].model.trim(),
speed: cpus[0].speed,
cores: cpus.length
};
- 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