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

Commit

Permalink
Fix duplicated issues and upgrade to linter v2 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgalvarez authored and Arcanemagus committed Jun 12, 2017
1 parent f677548 commit ea0adbc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
41 changes: 36 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,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.
*
Expand Down Expand Up @@ -79,6 +84,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) => {
Expand All @@ -98,6 +115,8 @@ export default {
},

deactivate() {
this.idleCallbacks.forEach(callbackID => window.cancelIdleCallback(callbackID));
this.idleCallbacks.clear();
this.subscriptions.dispose();
},

Expand All @@ -108,6 +127,7 @@ export default {
name: 'Code Climate',
grammarScopes: ['*'],
scope: 'file',
lintsOnChange: false,
lint: async (textEditor) => {
const filePath = textEditor.getPath();
const fileDir = dirname(filePath);
Expand Down Expand Up @@ -201,6 +221,7 @@ export default {
return [];
}
const linterResults = [];
const fingerprints = new Set();
let range;
Object.keys(messages).forEach((issueKey) => {
const issue = messages[issueKey];
Expand Down Expand Up @@ -231,11 +252,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,
},
});
});

Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -29,15 +29,19 @@
}
},
"dependencies": {
"atom-linter": "^10.0.0"
"atom-linter": "^10.0.0",
"atom-package-deps": "^4.6.0"
},
"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",
Expand Down
20 changes: 12 additions & 8 deletions spec/linter-codeclimate-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ describe('The codeclimate provider for Linter', () => {
() =>
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]]);
},
),
),
Expand Down

0 comments on commit ea0adbc

Please sign in to comment.