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

Commit 9ffcfab

Browse files
committed
Observe the settings
Instead of making Atom lookup the settings on each lint call, observe them in the activation so this work isn't needlessly repeated.
1 parent c9415b5 commit 9ffcfab

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,36 @@
22

33
import * as helpers from 'atom-linter';
44
import { extname } from 'path';
5+
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
6+
import { CompositeDisposable } from 'atom';
57

68
export default {
7-
activate: () => {
9+
activate() {
810
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; }));
17+
},
18+
19+
deactivate() {
20+
this.subscriptions.dispose();
921
},
1022

11-
provideLinter: () => {
23+
provideLinter() {
1224
const regex = /.+:(\d+):\s*(.+?)[,:]\s(.+)/;
1325
return {
1426
name: 'Ruby',
1527
grammarScopes: ['source.ruby', 'source.ruby.rails', 'source.ruby.rspec'],
1628
scope: 'file',
1729
lintOnFly: true,
1830
lint: async (activeEditor) => {
19-
const command = atom.config.get('linter-ruby.rubyExecutablePath');
20-
const ignored = atom.config.get('linter-ruby.ignoredExtensions');
2131
const filePath = activeEditor.getPath();
2232
const fileExtension = extname(filePath).substr(1);
2333

24-
if (ignored.includes(fileExtension)) {
34+
if (this.ignoredExtensions.includes(fileExtension)) {
2535
return [];
2636
}
2737

@@ -30,7 +40,7 @@ export default {
3040
stdin: activeEditor.getText(),
3141
stream: 'stderr',
3242
};
33-
const output = await helpers.exec(command, execArgs, execOpts);
43+
const output = await helpers.exec(this.executablePath, execArgs, execOpts);
3444
const toReturn = [];
3545
output.split(/\r?\n/).forEach((line) => {
3646
const matches = regex.exec(line);

0 commit comments

Comments
 (0)