Passed
Push — master ( fbaf18...732058 )
by Lucas
43s
created

devmind-beautifier.js ➔ request   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 9.4285
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
      if (typeof http.responseText.status === "undefined") {
20
        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...
21
        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...
22
        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...
23
      } else {
24
        atom.notifications.addInfo("File extension not supported. Yet.");
25
      }
26
    }
27
    if (http.status !== 200) {
28
      panel.modalPanel.hide();
29
      atom.notifications.addError(
30
        "Something went wrong, please check your internet connection"
31
      );
32
    }
33
  };
34
}
35
36
export default {
37
  devmindBeautifierView: null,
38
  modalPanel: null,
39
  subscriptions: null,
40
41
  activate(state) {
42
    this.devmindBeautifierView = new DevmindBeautifierView(
43
      state.devmindBeautifierViewState
44
    );
45
    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...
46
      item: this.devmindBeautifierView.getElement(),
47
      visible: false
48
    });
49
50
    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
51
    this.subscriptions = new CompositeDisposable();
52
53
    // Register command that toggles this view
54
    this.subscriptions.add(
55
      atom.commands.add("atom-workspace", {
56
        "devmind-beautifier:toggle": () => this.toggle()
57
      })
58
    );
59
  },
60
61
  deactivate() {
62
    this.modalPanel.destroy();
63
    this.subscriptions.dispose();
64
    this.devmindBeautifierView.destroy();
65
  },
66
67
  serialize() {
68
    return {
69
      devmindBeautifierViewState: this.devmindBeautifierView.serialize()
70
    };
71
  },
72
73
  toggle() {
74
    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...
75
76
    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...
77
    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...
78
    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...
79
    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...
80
      .split(".")
81
      .pop()
82
      .trim();
83
    request(ext, text, "https://beautifier.devmind.io/format");
84
  }
85
};
86