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

Commit

Permalink
Adding link to rule documentation (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xapphire13 authored Apr 27, 2017
1 parent b645bad commit 197e8bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

/* global emit */

import path from 'path';
import escapeHTML from 'escape-html';
import fs from 'fs';
import path from 'path';
import { getRuleUri } from 'tslint-rule-documentation';

process.title = 'linter-tslint worker';

Expand Down Expand Up @@ -185,11 +187,12 @@ async function lint(content, filePath, options) {
}

return lintResult.failures.map((failure) => {
const ruleUri = getRuleUri(failure.getRuleName());
const startPosition = failure.getStartPosition().getLineAndCharacter();
const endPosition = failure.getEndPosition().getLineAndCharacter();
return {
type: failure.ruleSeverity || 'warning',
text: `${failure.getRuleName()} - ${failure.getFailure()}`,
html: `${escapeHTML(failure.getFailure())} (<a href="${ruleUri.uri}">${failure.getRuleName()}</a>)`,
filePath: path.normalize(failure.getFileName()),
range: [
[startPosition.line, startPosition.character],
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
"dependencies": {
"atom-package-deps": "^4.3.1",
"crypto-random-string": "^1.0.0",
"escape-html": "^1.0.3",
"loophole": "^1.1.0",
"resolve": "^1.2.0",
"tslint": "5.1.0",
"tslint-rule-documentation": "^1.0.1",
"typescript": "2.2.2"
},
"readmeFilename": "README.md",
Expand Down
12 changes: 6 additions & 6 deletions spec/linter-tslint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('The TSLint provider for Linter', () => {
});

it('handles messages from TSLint', async () => {
const expectedMsg = 'semicolon - Missing semicolon';
const expectedMsgRegEx = /Missing semicolon \(<a href=".*">semicolon<\/a>\)/;
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(expectedMsgRegEx.test(result[0].html)).toBeTruthy();
expect(result[0].text).not.toBeDefined();
expect(result[0].filePath).toBe(invalidPath);
expect(result[0].range).toEqual([[0, 14], [0, 14]]);
});
Expand Down Expand Up @@ -67,13 +67,13 @@ describe('The TSLint provider for Linter', () => {
});

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 expectedMsgRegEx = /This expression is unnecessarily compared to a boolean. Just use it directly. \(<a href=".*">no-boolean-literal-compare<\/a>\)/;
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(expectedMsgRegEx.test(result[0].html)).toBeTruthy();
expect(result[0].text).not.toBeDefined();
expect(result[0].filePath).toBe(invalidTypecheckedPath);
expect(result[0].range).toEqual([[1, 0], [1, 1]]);
});
Expand Down

0 comments on commit 197e8bd

Please sign in to comment.