Completed
Push — develop ( d320a2...2c5883 )
by William
35s
created

app/lib/utils.js   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 13
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
c 1
b 0
f 1
nc 1
dl 0
loc 13
rs 10
wmc 4
mnd 2
bc 2
fnc 2
bpm 1
cpm 2
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ getMenuItem 0 6 3
1
/**
2
 * @file Utils
3
 */
4
/**
5
 * @module Utils
6
 */
7
8
import {menu} from '../main/index';
9
10
/**
11
 * Get menu item by label.
12
 * @param label {string} The label of the menu item to search for.
13
 * @returns {Electron.MenuItem} - The full menu item. Can change things like checked etc.
14
 */
15
export function getMenuItem (label) {
16
	for (let i = 0; i < menu.items.length; i++) {
17
		const menuItem = menu.items[i].submenu.items.find(item => item.label === label);
18
		if (menuItem) return menuItem
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
19
	}
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
20
}
21