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

Fixing bug where the worker thread would hang if there wasn't a tslint.json file #160

Merged
merged 5 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function lint(content, filePath, options) {
const configuration = Linter.loadConfigurationFromPath(configurationPath);

let { rulesDirectory } = configuration;
if (rulesDirectory) {
if (rulesDirectory && configurationPath) {
const configurationDir = path.dirname(configurationPath);
if (!Array.isArray(rulesDirectory)) {
rulesDirectory = [rulesDirectory];
Expand All @@ -123,8 +123,8 @@ async function lint(content, filePath, options) {
return path.join(configurationDir, dir);
});

if (rulesDirectory) {
rulesDirectory.push(rulesDirectory);
if (config.rulesDirectory) {
rulesDirectory.push(config.rulesDirectory);
}
}

Expand All @@ -133,8 +133,14 @@ async function lint(content, filePath, options) {
rulesDirectory,
}, options));

linter.lint(filePath, content, configuration);
const lintResult = linter.getResult();
let lintResult;
try {
linter.lint(filePath, content, configuration);
lintResult = linter.getResult();
} catch (err) {
console.error(err); // eslint-disable-line no-console
lintResult = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't something be done with this crash? (Logging to the console?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will add =]

}

if (
// tslint@<5
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"devDependencies": {
"eslint": "^3.16.1",
"eslint-config-airbnb-base": "^11.1.1",
"eslint-plugin-import": "^2.2.0"
"eslint-plugin-import": "^2.2.0",
"jasmine-fix": "^1.0.1"
},
"eslintConfig": {
"extends": "airbnb-base",
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/no-config/noConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const foo = 42;
export default foo;
75 changes: 37 additions & 38 deletions spec/linter-tslint-spec.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
'use babel';

import * as path from 'path';
// NOTE: If using 'fit' you must add it to the list below!
import { beforeEach, it } from 'jasmine-fix'; // eslint-disable-line import/no-extraneous-dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a note here about fit, with async specs if you try to use fit without importing it the spec will "pass" but do nothing.

import linterTslint from '../lib/main';

const validPath = path.join(__dirname, 'fixtures', 'valid', 'valid.ts');
const invalidPath = path.join(__dirname, 'fixtures', 'invalid', 'invalid.ts');
const noConfigPath = path.join(__dirname, 'fixtures', 'no-config', 'noConfig.ts');
const validPath = path.join(__dirname, 'fixtures', 'valid', 'valid.ts');

describe('The TSLint provider for Linter', () => {
const lint = require('../lib/main.js').provideLinter().lint;

beforeEach(() => {
atom.workspace.destroyActivePaneItem();

waitsForPromise(() =>
Promise.all([
atom.packages.activatePackage('linter-tslint'),
]),
);
});

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

it('handles messages from TSLint', () => {
const expectedMsg = 'semicolon - Missing semicolon';
waitsForPromise(() =>
atom.workspace.open(invalidPath).then(editor => lint(editor)).then((messages) => {
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('warning');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe(expectedMsg);
expect(messages[0].filePath).toBe(invalidPath);
expect(messages[0].range).toEqual([[0, 14], [0, 14]]);
}),
);
beforeEach(async () => {
await atom.packages.activatePackage('linter-tslint');
});

it('handles undefined filepath', () => {
waitsForPromise(() =>
atom.workspace.open().then(editor => lint(editor)).then((result) => {
expect(result).toBeNull();
}),
);
describe('When the package is activated', () => {
it('finds nothing wrong with a valid file', async () => {
const editor = await atom.workspace.open(validPath);
const messages = await lint(editor);
expect(messages.length).toBe(0);
});

it('handles messages from TSLint', async () => {
const expectedMsg = 'semicolon - Missing semicolon';
const editor = await atom.workspace.open(invalidPath);
const messages = await lint(editor);
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('warning');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe(expectedMsg);
expect(messages[0].filePath).toBe(invalidPath);
expect(messages[0].range).toEqual([[0, 14], [0, 14]]);
});

it('handles undefined filepath', async () => {
const editor = await atom.workspace.open();
const result = await lint(editor);
expect(result).toBeNull();
});

it('finishes validatation even when there is no tslint.json', async () => {
const editor = await atom.workspace.open(noConfigPath);
await lint(editor);
});
});
});