Passed
Pull Request — master (#17)
by
unknown
57s
created

source/js/events.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 36
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

4 Functions

Rating   Name   Duplication   Size   Complexity  
A actions.createTask 0 8 1
A senders.app 0 3 1
A senders.maildrop 0 3 1
A events.js ➔ ??? 0 9 2
1
/* eslint-env webextensions */
2
3
function encodeTaskProperties(omnifocusTask) {
4
  return {
5
    name: encodeURIComponent(omnifocusTask.name),
6
    note: encodeURIComponent(omnifocusTask.note),
7
  };
8
}
9
10
const senders = {
11
  app(config, encodedTask) {
12
    return `omnifocus:///add?name=${encodedTask.name}&note=${encodedTask.note}`;
13
  },
14
  maildrop(config, encodedTask) {
15
    return `mailto:${config.address}@sync.omnigroup.com?subject=${encodedTask.name}&body=${encodedTask.note}`;
16
  },
17
};
18
19
const actions = {
20
  createTask(taskInfo) {
21
    const sender = localStorage.sender || 'app';
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
22
    const encodedTask = encodeTaskProperties(taskInfo);
23
24
    return {
25
      url: senders[sender](localStorage, encodedTask),
26
    };
27
  },
28
};
29
30
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
0 ignored issues
show
Bug introduced by
The variable chrome seems to be never declared. If this is a global, consider adding a /** global: chrome */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
31
  let responseData = false;
32
33
  if (actions[request.method]) {
34
    responseData = actions[request.method](request.params);
35
  }
36
37
  sendResponse(responseData);
38
});
39