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

Commit c9415b5

Browse files
committed
Utilize async/await
Use the much cleaner async/await syntax to clean up the code around the execution of `ruby`.
1 parent 98e5289 commit c9415b5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lib/main.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
grammarScopes: ['source.ruby', 'source.ruby.rails', 'source.ruby.rspec'],
1616
scope: 'file',
1717
lintOnFly: true,
18-
lint: (activeEditor) => {
18+
lint: async (activeEditor) => {
1919
const command = atom.config.get('linter-ruby.rubyExecutablePath');
2020
const ignored = atom.config.get('linter-ruby.ignoredExtensions');
2121
const filePath = activeEditor.getPath();
@@ -25,23 +25,27 @@ export default {
2525
return [];
2626
}
2727

28-
return helpers.exec(command, ['-wc', '-E utf-8'], { stdin: activeEditor.getText(), stream: 'stderr' }).then((output) => {
29-
const toReturn = [];
30-
output.split(/\r?\n/).forEach((line) => {
31-
const matches = regex.exec(line);
32-
if (matches === null) {
33-
return;
34-
}
35-
const msgLine = Number.parseInt(matches[1] - 1, 10);
36-
toReturn.push({
37-
range: helpers.rangeFromLineNumber(activeEditor, msgLine),
38-
type: matches[2],
39-
text: matches[3],
40-
filePath,
41-
});
28+
const execArgs = ['-wc', '-E utf-8'];
29+
const execOpts = {
30+
stdin: activeEditor.getText(),
31+
stream: 'stderr',
32+
};
33+
const output = await helpers.exec(command, execArgs, execOpts);
34+
const toReturn = [];
35+
output.split(/\r?\n/).forEach((line) => {
36+
const matches = regex.exec(line);
37+
if (matches === null) {
38+
return;
39+
}
40+
const msgLine = Number.parseInt(matches[1] - 1, 10);
41+
toReturn.push({
42+
range: helpers.rangeFromLineNumber(activeEditor, msgLine),
43+
type: matches[2],
44+
text: matches[3],
45+
filePath,
4246
});
43-
return toReturn;
4447
});
48+
return toReturn;
4549
},
4650
};
4751
},

0 commit comments

Comments
 (0)