lib/devmind-beautifier.js   A
last analyzed

Complexity

Total Complexity 14
Complexity/F 1.4

Size

Lines of Code 93
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 0
c 5
b 0
f 0
nc 1
dl 0
loc 93
rs 10
wmc 14
mnd 1
bc 13
fnc 10
bpm 1.3
cpm 1.4
noi 14

8 Functions

Rating   Name   Duplication   Size   Complexity  
A devmind-beautifier.js ➔ request 0 8 1
A ???.deactivate 0 5 1
A ???.activate 0 19 1
A ???.serialize 0 5 1
A devmind-beautifier.js ➔ changeState 0 10 1
A devmind-beautifier.js ➔ success 0 9 2
A devmind-beautifier.js ➔ fail 0 6 1
A ???.toggle 0 12 1
1
"use babel";
2
3
import DevmindBeautifierView from "./devmind-beautifier-view";
4
import { CompositeDisposable } from "atom";
5
var qs = require("qs");
6
7
function request(ext, text, url) {
8
  data = { extension: ext, content: text };
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
9
  var http = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ 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...
10
  http.open("POST", url, true);
11
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
12
  http.send(qs.stringify(data));
13
  changeState(http);
14
}
15
16
function changeState(http) {
17
  http.onreadystatechange = function() {
18
    if (http.readyState == 4 && http.status == 200) {
19
      success(http);
20
    }
21
    if (http.status !== 200) {
22
      fail();
23
    }
24
  };
25
}
26
27
function success(http) {
28
  if (typeof http.responseText.status === "undefined") {
29
    editor.setText(http.responseText);
0 ignored issues
show
Bug introduced by
The variable editor seems to be never declared. If this is a global, consider adding a /** global: editor */ 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...
30
    atom.notifications.addSuccess("Now your code looks fancy");
0 ignored issues
show
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ 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
    panel.modalPanel.hide();
0 ignored issues
show
Bug introduced by
The variable panel seems to be never declared. If this is a global, consider adding a /** global: panel */ 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...
32
  } else {
33
    atom.notifications.addInfo("File extension not supported. Yet.");
34
  }
35
}
36
37
function fail() {
38
  panel.modalPanel.hide();
0 ignored issues
show
Bug introduced by
The variable panel seems to be never declared. If this is a global, consider adding a /** global: panel */ 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...
39
  atom.notifications.addError(
0 ignored issues
show
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ 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...
40
    "Something went wrong, please check your internet connection"
41
  );
42
}
43
44
export default {
45
  devmindBeautifierView: null,
46
  modalPanel: null,
47
  subscriptions: null,
48
49
  activate(state) {
50
    this.devmindBeautifierView = new DevmindBeautifierView(
51
      state.devmindBeautifierViewState
52
    );
53
    this.modalPanel = atom.workspace.addModalPanel({
0 ignored issues
show
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ 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...
54
      item: this.devmindBeautifierView.getElement(),
55
      visible: false
56
    });
57
58
    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
59
    this.subscriptions = new CompositeDisposable();
60
61
    // Register command that toggles this view
62
    this.subscriptions.add(
63
      atom.commands.add("atom-workspace", {
64
        "devmind-beautifier:toggle": () => this.toggle()
65
      })
66
    );
67
  },
68
69
  deactivate() {
70
    this.modalPanel.destroy();
71
    this.subscriptions.dispose();
72
    this.devmindBeautifierView.destroy();
73
  },
74
75
  serialize() {
76
    return {
77
      devmindBeautifierViewState: this.devmindBeautifierView.serialize()
78
    };
79
  },
80
81
  toggle() {
82
    panel = this;
0 ignored issues
show
Bug introduced by
The variable panel seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.panel.
Loading history...
83
84
    editor = atom.workspace.getActiveTextEditor();
0 ignored issues
show
Bug introduced by
The variable editor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.editor.
Loading history...
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ 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...
85
    text = editor.getText().trim();
0 ignored issues
show
Bug introduced by
The variable text seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.text.
Loading history...
86
    fileName = editor.getTitle();
0 ignored issues
show
Bug introduced by
The variable fileName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fileName.
Loading history...
87
    ext = fileName
0 ignored issues
show
Bug introduced by
The variable ext seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ext.
Loading history...
88
      .split(".")
89
      .pop()
90
      .trim();
91
    request(ext, text, "https://beautifier.devmind.io/format");
92
  }
93
};
94