Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 148a2be

Browse files
authored
Merge pull request #99 from AtomLinter/arcanemagus/cleanup
Cleanup and bugfixes
2 parents b226bfd + 174de4d commit 148a2be

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If you would like to contribute enhancements or fixes, please do the following:
1111
Please note that modifications should follow these coding guidelines:
1212

1313
- Indent is 2 spaces.
14-
- Code should pass coffeelint linter.
14+
- Code should pass ESLint linter (`npm run lint`).
1515
- Vertical whitespace helps readability, don’t be afraid to use it.
1616

1717
Thank you for helping out!

lib/main.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,65 @@
11
'use babel';
22

3+
import * as helpers from 'atom-linter';
4+
import { extname } from 'path';
5+
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
6+
import { CompositeDisposable } from 'atom';
7+
38
export default {
4-
config: {
5-
rubyExecutablePath: {
6-
type: 'string',
7-
default: 'ruby',
8-
},
9-
ignoredExtensions: {
10-
type: 'array',
11-
default: ['erb', 'md'],
12-
items: {
13-
type: 'string',
14-
},
15-
},
9+
activate() {
10+
require('atom-package-deps').install('linter-ruby');
11+
12+
this.subscriptions = new CompositeDisposable();
13+
this.subscriptions.add(atom.config.observe('linter-ruby.rubyExecutablePath',
14+
(value) => { this.executablePath = value; }));
15+
this.subscriptions.add(atom.config.observe('linter-ruby.ignoredExtensions',
16+
(value) => { this.ignoredExtensions = value; }));
1617
},
1718

18-
activate: () => {
19-
// We are now using steelbrain's package dependency package to install our
20-
// dependencies.
21-
require('atom-package-deps').install();
19+
deactivate() {
20+
this.subscriptions.dispose();
2221
},
2322

24-
provideLinter: () => {
25-
const helpers = require('atom-linter');
26-
const Path = require('path');
27-
const regex = /.+:(\d+):\s*(.+?)[,:]\s(.+)/;
23+
provideLinter() {
24+
const regex = /.+:(\d+):\s*(.+?)[,:]\s(.+)/g;
2825
return {
2926
name: 'Ruby',
3027
grammarScopes: ['source.ruby', 'source.ruby.rails', 'source.ruby.rspec'],
3128
scope: 'file',
3229
lintOnFly: true,
33-
lint: (activeEditor) => {
34-
const command = atom.config.get('linter-ruby.rubyExecutablePath');
35-
const ignored = atom.config.get('linter-ruby.ignoredExtensions');
36-
const filePath = activeEditor.getPath();
37-
const fileExtension = Path.extname(filePath).substr(1);
30+
lint: async (textEditor) => {
31+
const filePath = textEditor.getPath();
32+
const fileText = textEditor.getText();
33+
const fileExtension = extname(filePath).substr(1);
3834

39-
if (ignored.includes(fileExtension)) {
35+
if (this.ignoredExtensions.includes(fileExtension)) {
4036
return [];
4137
}
4238

43-
return helpers.exec(command, ['-wc', '-E utf-8'], { stdin: activeEditor.getText(), stream: 'stderr' }).then((output) => {
44-
const toReturn = [];
45-
output.split(/\r?\n/).forEach((line) => {
46-
const matches = regex.exec(line);
47-
if (matches === null) {
48-
return;
49-
}
50-
const msgLine = Number.parseInt(matches[1] - 1, 10);
51-
toReturn.push({
52-
range: helpers.rangeFromLineNumber(activeEditor, msgLine),
53-
type: matches[2],
54-
text: matches[3],
55-
filePath,
56-
});
39+
const execArgs = ['-wc', '-Eutf-8'];
40+
const execOpts = {
41+
stdin: fileText,
42+
stream: 'stderr',
43+
allowEmptyStderr: true,
44+
};
45+
const output = await helpers.exec(this.executablePath, execArgs, execOpts);
46+
if (textEditor.getText() !== fileText) {
47+
// File contents have changed, just tell Linter not to update messages
48+
return null;
49+
}
50+
const toReturn = [];
51+
let match = regex.exec(output);
52+
while (match !== null) {
53+
const msgLine = Number.parseInt(match[1] - 1, 10);
54+
toReturn.push({
55+
range: helpers.rangeFromLineNumber(textEditor, msgLine),
56+
type: match[2],
57+
text: match[3],
58+
filePath,
5759
});
58-
return toReturn;
59-
});
60+
match = regex.exec(output);
61+
}
62+
return toReturn;
6063
},
6164
};
6265
},

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@
66
"repository": "https://github.com/AtomLinter/linter-ruby",
77
"license": "MIT",
88
"engines": {
9-
"atom": ">0.180.0"
9+
"atom": ">=1.4.0 <2.0.0"
1010
},
1111
"activationHooks": [
1212
"language-ruby:grammar-used",
1313
"language-ruby-on-rails:grammar-used"
1414
],
15+
"configSchema": {
16+
"rubyExecutablePath": {
17+
"type": "string",
18+
"default": "ruby"
19+
},
20+
"ignoredExtensions": {
21+
"type": "array",
22+
"default": ["erb", "md"],
23+
"items": {
24+
"type": "string"
25+
}
26+
}
27+
},
1528
"providedServices": {
1629
"linter": {
1730
"versions": {

0 commit comments

Comments
 (0)