This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinter-flint.js
119 lines (107 loc) · 3.36 KB
/
linter-flint.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use babel';
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';
import { exec } from 'atom-linter';
import { dirname } from 'path';
import escapeHTML from 'escape-html';
// Internal vars
// Example: https://regex101.com/r/OfS9w0/2/
const regex = /\[([A-Z]+)\] (.+)(?:\n\[INFO\] ([^\n.]+.)(?: (http:.+))?\n?)?/gm;
export default {
activate() {
require('atom-package-deps').install('linter-flint');
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.config.observe('linter-flint.executablePath', (value) => {
this.executablePath = value;
}),
atom.config.observe('linter-flint.skipReadme', (value) => {
this.skipReadme = value;
}),
atom.config.observe('linter-flint.skipContributing', (value) => {
this.skipContributing = value;
}),
atom.config.observe('linter-flint.skipLicense', (value) => {
this.skipLicense = value;
}),
atom.config.observe('linter-flint.skipBootstrap', (value) => {
this.skipBootstrap = value;
}),
atom.config.observe('linter-flint.skipTestScript', (value) => {
this.skipTestScript = value;
}),
atom.config.observe('linter-flint.skipScripts', (value) => {
this.skipScripts = value;
}),
);
},
deactivate() {
this.subscriptions.dispose();
},
provideLinter() {
return {
name: 'Flint',
grammarScopes: ['*'],
scope: 'project',
lintOnFly: false,
lint: async (editor) => {
const filePath = editor.getPath();
let projectPath = atom.project.relativizePath(filePath)[0];
if (projectPath === null) {
projectPath = dirname(filePath);
}
const execArgs = ['--no-color'];
if (this.skipReadme) {
execArgs.push('--skip-readme');
}
if (this.skipContributing) {
execArgs.push('--skip-contributing');
}
if (this.skipLicense) {
execArgs.push('--skip-license');
}
if (this.skipBootstrap) {
execArgs.push('--skip-bootstrap');
}
if (this.skipTestScript) {
execArgs.push('--skip-test-script');
}
if (this.skipScripts) {
execArgs.push('--skip-scripts');
}
const execOpts = {
cwd: projectPath,
stream: 'stderr',
};
const output = await exec(this.executablePath, execArgs, execOpts);
const toReturn = [];
let match = regex.exec(output);
while (match !== null) {
const [type, text, info, url] = match.slice(1);
if (type !== 'OK') {
const message = {
type: type === 'WARNING' ? 'Warning' : 'Error',
severity: type === 'WARNING' ? 'warning' : 'error',
text,
};
if (info) {
const trace = {
type: 'Trace',
severity: 'info',
};
if (url) {
trace.html = `${escapeHTML(info)} (<a href="${url}">link</a>)`;
} else {
trace.text = info;
}
message.trace = [trace];
}
toReturn.push(message);
}
match = regex.exec(output);
}
return toReturn;
},
};
},
};