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

Commit 4857d9b

Browse files
Merge pull request #4 from AtomLinter/tests-added
Get some more tests working
2 parents 3175271 + b74aa3f commit 4857d9b

File tree

7 files changed

+225
-145
lines changed

7 files changed

+225
-145
lines changed

lib/config.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use babel';
22
import { CompositeDisposable, Disposable } from 'atom';
3+
import get from 'lodash.get';
34

45
import console from './console';
56

@@ -56,24 +57,23 @@ const Config = {
5657
try {
5758
this.overrides = JSON.parse(this.configFile.readSync());
5859
} catch (err) {
59-
console.error('Linter ESLint v8: Error parsing .linter-eslint file', err);
60+
console.error('Error parsing .linter-eslint file', err);
6061
this.overrides = {};
6162
}
6263
this.triggerConfigChange();
6364
},
6465

6566
get (keyName = null) {
66-
if (!keyName) {
67-
return Object.assign(
68-
{},
69-
atom.config.get('linter-eslint-node'),
70-
this.overrides
71-
);
72-
}
73-
if (keyName in this.overrides) {
74-
return this.overrides[keyName];
75-
}
76-
return atom.config.get(`linter-eslint-node.${keyName}`);
67+
// TODO: Once we're certain that no config changes will go unnoticed by us,
68+
// we could just reuse this._currentConfig instead of building a new object
69+
// every time.
70+
let config = Object.assign(
71+
{},
72+
atom.config.get('linter-eslint-node'),
73+
this.overrides
74+
);
75+
if (!keyName) { return config; }
76+
return get(config, keyName);
7777
},
7878

7979
triggerConfigChange () {

lib/job-manager.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ class JobManager {
8585
this.createWorker();
8686
}
8787
});
88-
89-
console.log('Created worker:', this.worker);
9088
}
9189

9290
killWorker () {
@@ -102,7 +100,10 @@ class JobManager {
102100
}
103101

104102
receiveMessage (data) {
105-
console.debug('receiveMessage:', data);
103+
if (data.log) {
104+
console.log('WORKER LOG:', data.log);
105+
return;
106+
}
106107
let key = data.key;
107108
if (!key) {
108109
throw new Error(`Received message from worker without key`);
@@ -122,6 +123,10 @@ class JobManager {
122123
// just throw an error and let it get handled elsewhere.
123124
receiveError (data) {
124125
if (typeof data === 'object' && data.key) {
126+
if (!this.handlersForJobs.has(data.key)) {
127+
// Assume this has already been handled and silently fail.
128+
return;
129+
}
125130
let [, reject] = this.handlersForJobs.get(data.key);
126131
this.handlersForJobs.delete(data.key);
127132
reject(data);

lib/main.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default {
4343
async activate () {
4444
Config.initialize();
4545
this.workerPath = Path.join(__dirname, 'worker.js');
46-
NodePathTester.test(Config.get('nodeBin'));
4746
this.jobManager = new JobManager();
4847

4948
// Keep track of whether the user has seen certain notifications. Absent
@@ -159,6 +158,29 @@ export default {
159158
this.clearESLintCache();
160159
}
161160
}
161+
}),
162+
163+
// Add item to editor context menu.
164+
atom.contextMenu.add({
165+
'atom-text-editor:not(.mini), .overlayer': [{
166+
label: 'ESLint Fix',
167+
command: 'linter-eslint-node:fix-file',
168+
shouldDisplay: (evt) => {
169+
const activeEditor = atom.workspace.getActiveTextEditor();
170+
if (!activeEditor) {
171+
return false;
172+
}
173+
// Black magic!
174+
// Compares the private component property of the active TextEditor
175+
// against the components of the elements
176+
const evtIsActiveEditor = evt.path.some((elem) => (
177+
// Atom v1.19.0+
178+
elem.component && activeEditor.component
179+
&& elem.component === activeEditor.component));
180+
// Only show if it was the active editor and it is a valid scope
181+
return evtIsActiveEditor && helpers.hasValidScope(activeEditor, Config.get('scopes'));
182+
}
183+
}]
162184
})
163185
);
164186

@@ -377,6 +399,19 @@ export default {
377399
return;
378400
}
379401

402+
if (err.type && err.type === 'config-not-found') {
403+
if (Config.get('disabling.disableWhenNoEslintConfig')) {
404+
return;
405+
}
406+
atom.notifications.addError(
407+
`linter-eslint-node: No .eslintrc found`,
408+
{
409+
description: err.error,
410+
dismissable: false
411+
}
412+
);
413+
}
414+
380415
if (err.type && err.type === 'no-project') {
381416
// No project means nowhere to look for an `.eslintrc`.
382417
return;
@@ -519,7 +554,7 @@ export default {
519554
return filteredResults;
520555
} catch (err) {
521556
this.handleError(err);
522-
return null;
557+
return [];
523558
}
524559
}
525560
};

0 commit comments

Comments
 (0)