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

Commit

Permalink
Fixing bug where the worker thread would hang if there wasn't a tslin…
Browse files Browse the repository at this point in the history
…t.json file (#160)
  • Loading branch information
Xapphire13 authored Apr 25, 2017
1 parent 65ff796 commit 01a482b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 88 deletions.
16 changes: 11 additions & 5 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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 @@ -150,8 +150,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 @@ -164,8 +164,14 @@ async function lint(content, filePath, options) {
rulesDirectory,
}, options), program);

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 = {};
}

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 @@ -73,7 +73,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;
151 changes: 69 additions & 82 deletions spec/linter-tslint-spec.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,82 @@
'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
import linterTslint from '../lib/main';

const validPath = path.join(__dirname, 'fixtures', 'valid', 'valid.ts');
// Fixture paths
const invalidPath = path.join(__dirname, 'fixtures', 'invalid', 'invalid.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);
}),
);
});

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]]);
}),
);
});

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

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

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

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

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

atom.config.set('linter-tslint.enableSemanticRules', true);
});

afterEach(() => {
atom.config.set('linter-tslint.enableSemanticRules', false);
});
describe('The TSLint provider for Linter', () => {
const lint = linterTslint.provideLinter().lint;

it('finds nothing wrong with a valid file', () => {
waitsForPromise(() =>
atom.workspace.open(validTypecheckedPath).then(editor => lint(editor)).then((messages) => {
expect(messages.length).toBe(0);
}),
);
beforeEach(async () => {
await atom.packages.activatePackage('linter-tslint');
});

it('handles messages from TSLint', () => {
const expectedMsg = 'no-boolean-literal-compare - This expression is unnecessarily compared to a boolean. Just use it directly.';
waitsForPromise(() =>
atom.workspace.open(invalidTypecheckedPath).then(editor => lint(editor)).then((messages) => {
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('error');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe(expectedMsg);
expect(messages[0].filePath).toBe(invalidTypecheckedPath);
expect(messages[0].range).toEqual([[1, 0], [1, 1]]);
}),
);
describe('When the package is activated', () => {
describe('When dealing with typechecking off (no semantic rules)', () => {
it('finds nothing wrong with a valid file', async () => {
const editor = await atom.workspace.open(validPath);
const result = await lint(editor);
expect(result.length).toBe(0);
});

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

describe('When dealing with typechecking on (with semantic rules)', () => {
beforeEach(() => {
atom.config.set('linter-tslint.enableSemanticRules', true);
});

afterEach(() => {
atom.config.set('linter-tslint.enableSemanticRules', false);
});

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

it('handles messages from TSLint', async () => {
const expectedMsg = 'no-boolean-literal-compare - This expression is unnecessarily compared to a boolean. Just use it directly.';
const editor = await atom.workspace.open(invalidTypecheckedPath);
const result = await lint(editor);
expect(result.length).toBe(1);
expect(result[0].type).toBe('error');
expect(result[0].html).not.toBeDefined();
expect(result[0].text).toBe(expectedMsg);
expect(result[0].filePath).toBe(invalidTypecheckedPath);
expect(result[0].range).toEqual([[1, 0], [1, 1]]);
});
});
});
});

0 comments on commit 01a482b

Please sign in to comment.