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

Commit

Permalink
Merge pull request #103 from AtomLinter/arcanemagus/update-ci
Browse files Browse the repository at this point in the history
General fixes:
* Update to ESLint v4.5.0
* Update to `eslint-config-airbnb-base` v11.3.2
* Update to `eslint-plugin-import` v2.7.0
* Asyncify the specs with `jasmine-fix`
* Defer dependency loading and package dependency checking to speed up activation time

Update the Travis CI configuration:
* Update to Ruby 2.4.1
* Use Trusty based images
* Update APT package dependencies
  • Loading branch information
Arcanemagus authored Aug 28, 2017
2 parents 36c2c85 + 8b57e40 commit a4d8ff1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 93 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ language: ruby
matrix:
include:
- os: linux
rvm: 2.2.0
rvm: 2.4.1
env: ATOM_CHANNEL=stable

- os: linux
rvm: 2.2.0
rvm: 2.4.1
env: ATOM_CHANNEL=beta

install:
Expand Down Expand Up @@ -39,10 +39,12 @@ git:

sudo: false

dist: trusty

addons:
apt:
packages:
- build-essential
- git
- libgnome-keyring-dev
- fakeroot
- git
- libsecret-1-dev
99 changes: 65 additions & 34 deletions lib/linter-reek.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
'use babel';

/* eslint-disable import/no-extraneous-dependencies, import/extensions */
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';
/* eslint-enable import/no-extraneous-dependencies, import/extensions */

import * as helpers from 'atom-linter';
import path from 'path';
let helpers;
let path;

// Local variables
const parseRegex = /\[(\d+)(?:, \d+)*\]:(.*) \[.+\/(.+).md\]/g;
// Options
let executablePath;

const loadDeps = () => {
if (!helpers) {
helpers = require('atom-linter');
}
if (!path) {
path = require('path');
}
};

export default {
activate() {
require('atom-package-deps').install('linter-reek').then(() => {
this.idleCallbacks = new Set();
let depsCallbackID;
const installLinterReekDeps = () => {
this.idleCallbacks.delete(depsCallbackID);
if (!atom.inSpecMode()) {
require('atom-package-deps').install('linter-reek');
}
loadDeps();
if (atom.inDevMode()) {
// eslint-disable-next-line no-console
console.log('linter-reek: All dependencies installed.');
}
});
};
depsCallbackID = window.requestIdleCallback(installLinterReekDeps);
this.idleCallbacks.add(depsCallbackID);

this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.config.observe('linter-reek.executablePath', (value) => {
executablePath = value;
this.executablePath = value;
}),
);

if (atom.inDevMode()) {
/* eslint-disable no-console */
console.log('linter-reek: Reek linter is now activated.');
console.log(`linter-reek: Command path: ${executablePath}`);
console.log(`linter-reek: Command path: ${this.executablePath}`);
/* eslint-enable no-console */
}
},

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

Expand All @@ -43,34 +63,45 @@ export default {
grammarScopes: ['source.ruby', 'source.ruby.rails', 'source.ruby.rspec'],
scope: 'file',
lintOnFly: false,
lint: (TextEditor) => {
lint: async (TextEditor) => {
const filePath = TextEditor.getPath();
if (!filePath) {
// Somehow a TextEditor without a path was passed in
return null;
}

const fileText = TextEditor.getText();
const execOpts = { cwd: path.dirname(filePath), ignoreExitCode: true };
return helpers.exec(executablePath, [filePath], execOpts).then((output) => {
if (TextEditor.getText() !== fileText) {
// Editor contents have changed, tell Linter not to update
return null;
}
loadDeps();

const execOpts = {
cwd: path.dirname(filePath),
ignoreExitCode: true,
};

const output = await helpers.exec(this.executablePath, [filePath], execOpts);

if (TextEditor.getText() !== fileText) {
// Editor contents have changed, tell Linter not to update
return null;
}

const messages = [];
const messages = [];

let match = parseRegex.exec(output);
while (match !== null) {
const line = Number.parseInt(match[1], 10) - 1;
const urlBase = 'https://github.com/troessner/reek/blob/master/docs/';
const ruleLink = `[<a href="${urlBase}${match[3]}.md">${match[3]}</a>]`;
messages.push({
filePath,
type: 'Warning',
severity: 'warning',
html: `${match[2]} ${ruleLink}`,
range: helpers.generateRange(TextEditor, line),
});
match = parseRegex.exec(output);
}
return messages;
});
let match = parseRegex.exec(output);
while (match !== null) {
const line = Number.parseInt(match[1], 10) - 1;
const urlBase = 'https://github.com/troessner/reek/blob/master/docs/';
const ruleLink = `[<a href="${urlBase}${match[3]}.md">${match[3]}</a>]`;
messages.push({
filePath,
type: 'Warning',
severity: 'warning',
html: `${match[2]} ${ruleLink}`,
range: helpers.generateRange(TextEditor, line),
});
match = parseRegex.exec(output);
}
return messages;
},
};
},
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"engines": {
"atom": ">=1.0.0 <2.0.0"
"atom": ">=1.7.0 <2.0.0"
},
"scripts": {
"lint": "eslint .",
Expand All @@ -24,9 +24,10 @@
"atom-package-deps": "^4.0.1"
},
"devDependencies": {
"eslint-config-airbnb-base": "^11.1.1",
"eslint": "^3.16.1",
"eslint-plugin-import": "^2.2.0"
"eslint": "^4.5.0",
"eslint-config-airbnb-base": "^11.3.2",
"eslint-plugin-import": "^2.7.0",
"jasmine-fix": "^1.3.0"
},
"package-deps": [
"linter"
Expand All @@ -39,9 +40,9 @@
}
},
"eslintConfig": {
"extends": "airbnb-base",
"rules": {
"global-require": "off",
"no-console": "off",
"import/no-unresolved": [
"error",
{
Expand All @@ -51,12 +52,12 @@
}
]
},
"extends": "airbnb-base",
"globals": {
"atom": true
},
"env": {
"node": true
"node": true,
"browser": true
}
}
}
10 changes: 9 additions & 1 deletion spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module.exports = {
env: {
jasmine: true,
atomtest: true,
jasmine: true
},
rules: {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
};
69 changes: 22 additions & 47 deletions spec/linter-reek-spec.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,39 @@
'use babel';

import * as path from 'path';
// eslint-disable-next-line no-unused-vars
import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix';

const lint = require('../lib/linter-reek.js').provideLinter().lint;

const goodFile = path.join(__dirname, 'fixtures', 'good.rb');
const badFile = path.join(__dirname, 'fixtures', 'bad.rb');

describe('The reek provider for Linter', () => {
beforeEach(() => {
beforeEach(async () => {
atom.workspace.destroyActivePaneItem();
waitsForPromise(() =>
Promise.all([
atom.packages.activatePackage('linter-reek'),
atom.packages.activatePackage('language-ruby'),
]).then(() =>
atom.workspace.open(goodFile),
),
);
await atom.packages.activatePackage('language-ruby');
await atom.packages.activatePackage('linter-reek');
});

describe('checks a file with issues and', () => {
let editor = null;
beforeEach(() => {
waitsForPromise(() =>
atom.workspace.open(badFile).then(openEditor => (editor = openEditor)),
);
});

it('finds at least one message', () => {
waitsForPromise(() =>
lint(editor).then(messages =>
expect(messages.length).toBeGreaterThan(0),
),
);
});

it('verifies the first message', () => {
const messageHtml = 'IrresponsibleModule: Dirty has no descriptive comment ' +
'[<a href="https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md">Irresponsible-Module</a>]';
waitsForPromise(() =>
lint(editor).then((messages) => {
expect(messages[0].type).toEqual('Warning');
expect(messages[0].severity).toEqual('warning');
expect(messages[0].text).not.toBeDefined();
expect(messages[0].html).toEqual(messageHtml);
expect(messages[0].filePath).toBe(badFile);
expect(messages[0].range).toEqual([[0, 0], [0, 11]]);
}),
);
});
it('checks a file with issues and reports the correct message', async () => {
const messageHtml = 'IrresponsibleModule: Dirty has no descriptive comment ' +
'[<a href="https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md">Irresponsible-Module</a>]';
const editor = await atom.workspace.open(badFile);
const messages = await lint(editor);

expect(messages.length).toBe(1);
expect(messages[0].type).toEqual('Warning');
expect(messages[0].severity).toEqual('warning');
expect(messages[0].text).not.toBeDefined();
expect(messages[0].html).toEqual(messageHtml);
expect(messages[0].filePath).toBe(badFile);
expect(messages[0].range).toEqual([[0, 0], [0, 11]]);
});

it('finds nothing wrong with a valid file', () => {
waitsForPromise(() =>
atom.workspace.open(goodFile).then(editor =>
lint(editor).then(messages =>
expect(messages.length).toBe(0),
),
),
);
it('finds nothing wrong with a valid file', async () => {
const editor = await atom.workspace.open(goodFile);
const messages = await lint(editor);
expect(messages.length).toBe(0);
});
});

0 comments on commit a4d8ff1

Please sign in to comment.