forked from sindresorhus/atom-linter-xo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (57 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/** @babel */
import {CompositeDisposable} from 'atom';
import {install} from 'atom-package-deps';
import fix from './lib/fix';
import format from './lib/format';
import lint from './lib/lint';
const SUPPORTED_SCOPES = [
'source.js',
'source.jsx',
'source.js.jsx',
'source.js.embedded.html'
];
export function activate() {
install('linter-xo');
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(atom.commands.add('atom-text-editor', {
'XO:Fix': () => {
const editor = atom.workspace.getActiveTextEditor();
if (!editor) {
return;
}
fix(editor)(editor.getText());
}
}));
this.subscriptions.add(
atom.workspace.observeTextEditors(editor => {
editor.getBuffer().onWillSave(() => {
if (!atom.config.get('linter-xo.fixOnSave')) {
return;
}
const {scopeName} = editor.getGrammar();
if (!SUPPORTED_SCOPES.includes(scopeName)) {
return;
}
return fix(editor)(editor.getText());
});
})
);
}
export const config = {
fixOnSave: {
type: 'boolean',
default: false
}
};
export function deactivate() {
this.subscriptions.dispose();
}
export function provideLinter() {
return {
name: 'XO',
grammarScopes: SUPPORTED_SCOPES,
scope: 'file',
lintsOnChange: true,
lint: editor => lint(editor)(editor.getText()).then(format(editor))
};
}