Skip to content
Permalink
Browse files

New: Expose `ignoredUrls` in `HintContext`

  • Loading branch information...
sarvaje authored and molant committed Mar 6, 2019
1 parent d8aa92b commit 8bed0b0ddbdd0ab72e321f2a8f9f55a0231bb982
Showing with 17 additions and 2 deletions.
  1. +8 −1 packages/hint/src/lib/engine.ts
  2. +9 −1 packages/hint/src/lib/hint-context.ts
@@ -191,6 +191,13 @@ export class Engine<E extends Events = Events> extends EventEmitter {
ignoredConnectors.includes(connectorId || '');
};

const getIgnoredUrls = () => {
const urlsIgnoredForAll = this.ignoredUrls.get('all') || [];
const urlsIgnoredForHint = this.ignoredUrls.get(id) || [];

return urlsIgnoredForAll.concat(urlsIgnoredForHint);
};

const hintOptions: HintConfig | HintConfig[] = getHintConfig(id);
const severity: Severity | null = getSeverity(hintOptions);

@@ -199,7 +206,7 @@ export class Engine<E extends Events = Events> extends EventEmitter {
// TODO: I don't think we should have a dependency on logger here. Maybe send a warning event?
logger.log(chalk.yellow(`Warning: The hint "${id}" will be ignored for the connector "${connectorId}"`));
} else if (severity) {
const context: HintContext = new HintContext(id, this, severity, hintOptions, Hint.meta);
const context: HintContext = new HintContext(id, this, severity, hintOptions, Hint.meta, getIgnoredUrls());
const hint: IHint = new Hint(context);

this.hints.set(id, hint);
@@ -39,14 +39,16 @@ export class HintContext<E extends Events = Events> {
private meta: HintMetadata
private severity: Severity
private engine: Engine<E>
private ignoredUrls: RegExp[]

public constructor(hintId: string, engine: Engine<E>, severity: Severity, options: any, meta: HintMetadata) {
public constructor(hintId: string, engine: Engine<E>, severity: Severity, options: any, meta: HintMetadata, ignoredUrls: RegExp[]) {

this.id = hintId;
this.options = options;
this.meta = meta;
this.engine = engine;
this.severity = severity;
this.ignoredUrls = ignoredUrls;

Object.freeze(this);
}
@@ -141,4 +143,10 @@ export class HintContext<E extends Events = Events> {
public on<K extends StringKeyOf<E>>(event: K, listener: (data: E[K], event: string) => void) {
this.engine.onHintEvent(this.id, event, listener);
}

public isUrlIgnored(resource: string) {
return this.ignoredUrls.some((urlIgnored: RegExp) => {
return urlIgnored.test(resource);
});
}
}

0 comments on commit 8bed0b0

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