From d0d37803c45ece910e3ca60585ab8da299cd6674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garc=C3=ADa?= Date: Wed, 19 Apr 2017 18:10:16 +0200 Subject: [PATCH] fix duplicated issues and upgrade to linter v2 --- lib/index.js | 41 +++++++++++++++++++++++++++++---- package.json | 12 ++++++---- spec/linter-codeclimate-spec.js | 20 +++++++++------- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/lib/index.js b/lib/index.js index 188987e..dd1e240 100644 --- a/lib/index.js +++ b/lib/index.js @@ -32,13 +32,18 @@ const endMeasure = (baseName) => { performance.mark(`${baseName}-end`); performance.measure(baseName, `${baseName}-start`, `${baseName}-end`); // eslint-disable-next-line no-console - console.log(`${baseName} took: `, performance.getEntriesByName(baseName)[0].duration); + console.log(`${baseName} took: ${performance.getEntriesByName(baseName)[0].duration}`); performance.clearMarks(`${baseName}-end`); performance.clearMeasures(baseName); } performance.clearMarks(`${baseName}-start`); }; +const mapSeverity = { + major: 'error', + minor: 'warning', +}; + /** * Show a clearer error in Atom when the exact problem is known. * @@ -91,6 +96,18 @@ const notifyError = (err, cmd, description = '', extraDetails = '', buttons = [] export default { activate() { + // Idle callback to check version + this.idleCallbacks = new Set(); + let depsCallbackID; + const installLinterCodeclimateDeps = () => { + this.idleCallbacks.delete(depsCallbackID); + if (!atom.inSpecMode()) { + require('atom-package-deps').install('linter-codeclimate'); + } + }; + depsCallbackID = window.requestIdleCallback(installLinterCodeclimateDeps); + this.idleCallbacks.add(depsCallbackID); + this.subscriptions = new CompositeDisposable(); this.subscriptions.add(atom.config.observe( 'linter-codeclimate.executablePath', (value) => { @@ -110,6 +127,8 @@ export default { }, deactivate() { + this.idleCallbacks.forEach(callbackID => window.cancelIdleCallback(callbackID)); + this.idleCallbacks.clear(); this.subscriptions.dispose(); }, @@ -133,6 +152,7 @@ export default { name: 'Code Climate', grammarScopes: ['*'], scope: 'file', + lintsOnChange: false, lint: async (textEditor) => { const filePath = textEditor.getPath(); const fileDir = dirname(filePath); @@ -237,6 +257,7 @@ export default { return []; } const linterResults = []; + const fingerprints = new Set(); let range; Object.keys(messages).forEach((issueKey) => { const issue = messages[issueKey]; @@ -267,11 +288,21 @@ export default { range = Helpers.generateRange(textEditor, line); } + // Avoid duplicated issues + // TODO Remove when https://github.com/phpmd/phpmd/issues/467 fixed + if (fingerprints.has(issue.fingerprint)) { + return; + } + fingerprints.add(issue.fingerprint); + linterResults.push({ - type: 'Warning', - text: issue.description, - filePath, - range, + severity: mapSeverity[issue.severity] || 'warning', + excerpt: `${issue.engine_name.toUpperCase()}: ${issue.description} [${issue.check_name}]`, + description: (issue.content && issue.content.body) ? issue.content.body : undefined, + location: { + file: filePath, + position: range, + }, }); }); diff --git a/package.json b/package.json index aefe440..22a0552 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "repository": "https://github.com/AtomLinter/linter-codeclimate", "license": "MIT", "engines": { - "atom": ">=1.4.0 <2.0.0" + "atom": ">=1.7.0 <2.0.0" }, "configSchema": { "executablePath": { @@ -30,16 +30,20 @@ }, "dependencies": { "atom-linter": "^10.0.0", - "js-yaml": "^3.5.3", - "fs-plus": "^3.0.0" + "atom-package-deps": "^4.6.0", + "fs-plus": "^3.0.0", + "js-yaml": "^3.5.3" }, "providedServices": { "linter": { "versions": { - "1.0.0": "provideLinter" + "2.0.0": "provideLinter" } } }, + "package-deps": [ + "linter:2.0.0" + ], "devDependencies": { "eslint": "^3.16.1", "eslint-config-airbnb-base": "^11.1.1", diff --git a/spec/linter-codeclimate-spec.js b/spec/linter-codeclimate-spec.js index 54e1c16..9f8a177 100644 --- a/spec/linter-codeclimate-spec.js +++ b/spec/linter-codeclimate-spec.js @@ -23,14 +23,18 @@ describe('The codeclimate provider for Linter', () => { waitsForPromise(() => atom.workspace.open(coolCodePath).then(editor => lint(editor)).then( (messages) => { - expect(messages[0].type).toBe('Warning'); - expect(messages[0].text).toBe('Unused method argument - `bar`. If ' + - "it's necessary, use `_` or `_bar` as an argument name to indicate " + - "that it won't be used. You can also write as `foo(*)` if you want " + - "the method to accept any arguments but don't care about them."); - expect(messages[0].html).not.toBeDefined(); - expect(messages[0].filePath).toBe(coolCodePath); - expect(messages[0].range).toEqual([[1, 11], [1, 14]]); + expect(messages[0].severity).toBe('warning'); + expect(messages[0].excerpt).toBe('RUBOCOP: Unused method argument - ' + + "`bar`. If it's necessary, use `_` or `_bar` as an argument name to " + + "indicate that it won't be used. You can also write as `foo(*)` if " + + "you want the method to accept any arguments but don't care about " + + 'them. [Rubocop/Lint/UnusedMethodArgument]'); + expect(messages[0].description).toBeDefined(); + expect(messages[0].reference).not.toBeDefined(); + expect(messages[0].icon).not.toBeDefined(); + expect(messages[0].solutions).not.toBeDefined(); + expect(messages[0].location.file).toBe(coolCodePath); + expect(messages[0].location.position).toEqual([[1, 11], [1, 14]]); }, ), ),