From 312bbe038706098954edae7615fcf46082780d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szalai=20Mih=C3=A1ly?= Date: Mon, 20 Aug 2018 23:04:34 +0200 Subject: [PATCH 1/2] Lint -> Atom IDE Diagnostics --- .npmignore | 3 +++ lib/linter-integration.js | 53 +++++++++++++++++++++++++-------------- package.json | 2 +- 3 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..5f23cc6a --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +/node_modules diff --git a/lib/linter-integration.js b/lib/linter-integration.js index 924dd14b..fb389635 100644 --- a/lib/linter-integration.js +++ b/lib/linter-integration.js @@ -1,14 +1,32 @@ 'use babel'; +import { CompositeDisposable } from 'atom' + class Linter { constructor(registry) { - this.linter = registry.register({ name: 'Build' }); + let _this = this; + this.linter = registry({ name: 'Build' }); + this.subscriptions = new CompositeDisposable(); + + // Setting and clearing messages per filePath + this.subscriptions.add(atom.workspace.observeTextEditors(function(textEditor) { + _this.editorPath = textEditor.getPath() + if (!_this.editorPath) { + return + } + const subscription = textEditor.onDidDestroy(function() { + _this.subscriptions.remove(subscription); + _this.linter.setMessages(_this.editorPath, []); + }) + _this.subscriptions.add(subscription); + })); } destroy() { - this.linter.dispose(); + //this.linter.dispose(); + this.subscriptions.dispose(); } clear() { - this.linter.deleteMessages(); + this.linter.clearMessages(); } processMessages(messages, cwd) { function extractRange(json) { @@ -29,22 +47,19 @@ class Linter { default: return null; } } - this.linter.setMessages(messages.map(match => ({ - type: match.type || 'Error', - text: !match.message && !match.html_message ? 'Error from build' : match.message, - html: match.message ? undefined : match.html_message, - filePath: normalizePath(match.file), - severity: typeToSeverity(match.type), - range: extractRange(match), - trace: match.trace && match.trace.map(trace => ({ - type: trace.type || 'Trace', - text: !trace.message && !trace.html_message ? 'Trace in build' : trace.message, - html: trace.message ? undefined : trace.html_message, - filePath: trace.file && normalizePath(trace.file), - severity: typeToSeverity(trace.type) || 'info', - range: extractRange(trace) - })) - }))); + this.linter.setMessages(this.editorPath, (messages.map(match => ({ + severity: typeToSeverity(match.type) || 'info', + location: { + file: normalizePath(match.file), + position: extractRange(match) + }, + excerpt: !match.message && !match.html_message + ? 'Error from build' + : match.message, + description: match.message + ? undefined + : match.html_message + })))); } } diff --git a/package.json b/package.json index 8a6b52be..7855e25a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "linter-indie": { "versions": { - "1.0.0": "consumeLinterRegistry" + "2.0.0": "consumeLinterRegistry" } } }, From 5604e1eab8ec9915a11bc736fc92984f311a4f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szalai=20Mih=C3=A1ly?= Date: Tue, 21 Aug 2018 22:19:13 +0200 Subject: [PATCH 2/2] eslinter --- lib/linter-integration.js | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/linter-integration.js b/lib/linter-integration.js index fb389635..7d8e4205 100644 --- a/lib/linter-integration.js +++ b/lib/linter-integration.js @@ -1,28 +1,28 @@ 'use babel'; -import { CompositeDisposable } from 'atom' +import { CompositeDisposable } from 'atom'; class Linter { constructor(registry) { - let _this = this; + const _this = this; this.linter = registry({ name: 'Build' }); this.subscriptions = new CompositeDisposable(); // Setting and clearing messages per filePath - this.subscriptions.add(atom.workspace.observeTextEditors(function(textEditor) { - _this.editorPath = textEditor.getPath() - if (!_this.editorPath) { - return - } - const subscription = textEditor.onDidDestroy(function() { - _this.subscriptions.remove(subscription); - _this.linter.setMessages(_this.editorPath, []); - }) - _this.subscriptions.add(subscription); + this.subscriptions.add(atom.workspace.observeTextEditors(function (textEditor) { + _this.editorPath = textEditor.getPath(); + if (!_this.editorPath) { + return; + } + const subscription = textEditor.onDidDestroy(function () { + _this.subscriptions.remove(subscription); + _this.linter.setMessages(_this.editorPath, []); + }); + _this.subscriptions.add(subscription); })); } destroy() { - //this.linter.dispose(); + // this.linter.dispose(); this.subscriptions.dispose(); } clear() { @@ -48,17 +48,17 @@ class Linter { } } this.linter.setMessages(this.editorPath, (messages.map(match => ({ - severity: typeToSeverity(match.type) || 'info', - location: { - file: normalizePath(match.file), - position: extractRange(match) - }, - excerpt: !match.message && !match.html_message - ? 'Error from build' - : match.message, - description: match.message - ? undefined - : match.html_message + severity: typeToSeverity(match.type) || 'info', + location: { + file: normalizePath(match.file), + position: extractRange(match) + }, + excerpt: !match.message && !match.html_message + ? 'Error from build' + : match.message, + description: match.message + ? undefined + : match.html_message })))); } }