-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
91 lines (81 loc) · 2.04 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* author: Adam Hollett and Jeremy Hanson-Finger
* copyright: 2016 Shopify
* license: MIT
* module: atom:linter:rorybot
* fileoverview: Linter.
*/
'use strict';
// Initialize contants
const config = atom.config;
const deps = require('atom-package-deps');
const minimatch = require('minimatch');
const rorybot = require('rorybot');
const CODE_EXPRESSION = /`([^`]+)`/g;
function activate() {
deps.install('linter-rory');
}
function linter() {
// Return word range for highlighting
function toRange(location) {
return [[
Number(location.start.line) - 1,
Number(location.start.column) - 1
], [
Number(location.end.line) - 1,
Number(location.end.column) - 1
]];
}
// Transform VFile messages into linter messages
function transform(message, editorPath) {
return {
severity: 'error',
excerpt: message.reason,
description: message.reason,
location: {
file: editorPath,
position: toRange(message.location)
}
};
}
return {
grammarScopes: config.get('linter-rorybot').grammars,
name: 'rorybot',
scope: 'file',
lintsOnChange: true,
lint(textEditor) {
const editorPath = textEditor.getPath();
let settings = config.get('linter-rorybot');
if (minimatch(editorPath, settings.ignoreFiles)) {
return [];
}
return new Promise(function (resolve) {
resolve(rorybot(textEditor.getText()).messages.map((message) => transform(message, editorPath)));
});
}
};
}
// Export module
module.exports = {
config: {
ignoreFiles: {
description: 'Disable files matching (minimatch) glob',
type: 'string',
default: ''
},
grammars: {
description: 'List of scopes for languages which will be ' +
'checked. Note: setting new sources overwrites the ' +
'defaults.',
type: 'array',
default: [
'source.gfm',
'text.html.basic',
'text.html.ruby',
'text.plain'
]
}
},
provideLinter: linter,
activate: activate
};