Skip to content
Permalink
Browse files

Breaking: Refactor `engine.report` to take a `Problem` object

Fix #2276
Close #2387
  • Loading branch information...
antross authored and molant committed May 6, 2019
1 parent 90ccaa0 commit a0a6b54a949300d9a1f03892d8c8858c1547129f
Showing with 20 additions and 26 deletions.
  1. +1 −15 packages/hint/src/lib/engine.ts
  2. +8 −8 packages/hint/src/lib/hint-context.ts
  3. +11 −3 packages/hint/tests/lib/engine.ts
@@ -25,7 +25,6 @@ import {
Events,
HintConfig,
HintResources,

IConnector,
IConnectorConstructor,
IFetchOptions,
@@ -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);

@@ -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);
}

@@ -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. */
@@ -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);
}

0 comments on commit a0a6b54

Please sign in to comment.
You can’t perform that action at this time.