Skip to content

Commit

Permalink
Breaking: Refactor engine.report to take a Problem object
Browse files Browse the repository at this point in the history
  • Loading branch information
antross committed May 6, 2019
1 parent 9a9863b commit ac650aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
16 changes: 1 addition & 15 deletions packages/hint/src/lib/engine.ts
Expand Up @@ -25,7 +25,6 @@ import {
Events,
HintConfig,
HintResources,

IConnector,
IConnectorConstructor,
IFetchOptions,
Expand All @@ -35,14 +34,12 @@ import {
NetworkData,
Parser,
Problem,
ProblemLocation,
Severity,
StringKeyOf
} from './types';
import { HintContext } from './hint-context';
import { HintScope } from './enums/hint-scope';
import { Configuration } from './config';
import { Category } from './enums/category';

const debug: debug.IDebugger = d(__filename);

Expand Down Expand Up @@ -282,18 +279,7 @@ export class Engine<E extends Events = Events> extends EventEmitter {
}

/** Reports a message from one of the hints. */
public report(hintId: string, category: Category, severity: Severity, sourceCode: string, location: ProblemLocation | null, message: string, resource: string, codeLanguage: string | undefined) {
const problem: Problem = {
category,
codeLanguage,
hintId,
location: location || { column: -1, line: -1 },
message,
resource,
severity,
sourceCode
};

public report(problem: Problem) {
this.messages.push(problem);
}

Expand Down
16 changes: 8 additions & 8 deletions packages/hint/src/lib/hint-context.ts
Expand Up @@ -133,16 +133,16 @@ export class HintContext<E extends Events = Events> {
* So pass the `location` on as it is.
*/

this.engine.report(
this.id,
(this.meta && this.meta.docs && this.meta.docs.category) ? this.meta.docs.category : Category.other,
severity || this.severity,
codeSnippet || sourceCode || '',
position,
this.engine.report({
category: (this.meta && this.meta.docs && this.meta.docs.category) ? this.meta.docs.category : Category.other,
codeLanguage: options.codeLanguage,
hintId: this.id,
location: position || { column: -1, line: -1 },
message,
resource,
options.codeLanguage
);
severity: severity || this.severity,
sourceCode: codeSnippet || sourceCode || ''
});
}

/** Subscribe an event in hint. */
Expand Down
14 changes: 11 additions & 3 deletions packages/hint/tests/lib/engine.ts
Expand Up @@ -921,13 +921,21 @@ test('executeOn should forward content if provided', async (t) => {
const Engine = loadScript(t.context);

class FakeConnectorCollect implements IConnector {
private server: typeof Engine;
public constructor(server: typeof Engine) {
private server: import('../../src/lib/engine').Engine;
public constructor(server: import('../../src/lib/engine').Engine) {
this.server = server;
}

public collect(target: url.URL, options?: IFetchOptions) {
this.server.report('1', Category.other, 1, 'node', { column: 1, line: 1 }, options && options.content || '', target.href);
this.server.report({
category: Category.other,
hintId: '1',
location: { column: 1, line: 1 },
message: options && options.content || '',
resource: target.href,
severity: 1,
sourceCode: 'node'
});

return Promise.resolve(target);
}
Expand Down

0 comments on commit ac650aa

Please sign in to comment.