-
Notifications
You must be signed in to change notification settings - Fork 9.6k
core(errors-in-console): add ignoredPatterns option #9480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6304c0b
76f0ae4
fb75724
123283d
e22163f
c3ee28d
eb8a3f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ const UIStrings = { | |
|
|
||
| const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); | ||
|
|
||
| /** @typedef {{ignoredPatterns?: Array<RegExp|string>}} AuditOptions */ | ||
|
|
||
| class ErrorLogs extends Audit { | ||
| /** | ||
| * @return {LH.Audit.Meta} | ||
|
|
@@ -42,11 +44,41 @@ class ErrorLogs extends Audit { | |
| }; | ||
| } | ||
|
|
||
| /** @return {AuditOptions} */ | ||
| static defaultOptions() { | ||
| return {}; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @template {{description: string | undefined}} T | ||
| * @param {Array<T>} items | ||
| * @param {AuditOptions} options | ||
| * @return {Array<T>} | ||
| */ | ||
| static filterAccordingToOptions(items, options) { | ||
| const {ignoredPatterns} = options; | ||
| if (!ignoredPatterns) return items; | ||
|
|
||
| return items.filter(({description}) => { | ||
| if (!description) return true; | ||
| for (const pattern of ignoredPatterns) { | ||
| if (pattern instanceof RegExp && pattern.test(description)) return false; | ||
| if (typeof pattern === 'string' && description.includes(pattern)) return false; | ||
| } | ||
|
|
||
| return true; | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are we going to do with poorly formed
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure how we could ever possibly know that a user has misspelled the error they want to ignore, so you've lost me on that one. users gotta learn to crawl on their own sometime 😆
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, that does read well
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooooh misspell the option name, that makes much more sense. 👍 Honestly, I strongly dislike the pattern we've been starting to apply that unknown properties are fatal errors which breaks backwards/forwards compatibility. Would a warning of unrecognized property names address your concern?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, sounds great 👍 |
||
| } | ||
|
|
||
| /** | ||
| * @param {LH.Artifacts} artifacts | ||
| * @param {LH.Audit.Context} context | ||
| * @return {LH.Audit.Product} | ||
| */ | ||
| static audit(artifacts) { | ||
| static audit(artifacts, context) { | ||
| const auditOptions = /** @type {AuditOptions} */ (context.options); | ||
|
|
||
| const consoleEntries = artifacts.ConsoleMessages; | ||
| const runtimeExceptions = artifacts.RuntimeExceptions; | ||
| /** @type {Array<{source: string, description: string|undefined, url: string|undefined}>} */ | ||
|
|
@@ -73,7 +105,10 @@ class ErrorLogs extends Audit { | |
| }; | ||
| }); | ||
|
|
||
| const tableRows = consoleRows.concat(runtimeExRows); | ||
| const tableRows = ErrorLogs.filterAccordingToOptions( | ||
| consoleRows.concat(runtimeExRows), | ||
| auditOptions | ||
| ).sort((a, b) => (a.description || '').localeCompare(b.description || '')); | ||
|
|
||
| /** @type {LH.Audit.Details.Table['headings']} */ | ||
| const headings = [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only ever called with
/** @type {Array<{source: string, description: string|undefined, url: string|undefined}>} */, which is already declared once. Should just be a typedef instead of parametric? :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why though? this method operates on things that have an optional description, no matter what they look like, and that's exactly how the types are expressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a nit, so can leave it, but it's only generic in the sense that all monomorphic functions are generic (over one type). Adding a parameter implies complexity that isn't there (it's only ever called with one type of thing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, and if typescript had another method of expressing monomorphic functions that operate on a subset of the type while preserving the output type I would happily switch to that method :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean...
operates on a subset of the type just fine :P
(I blame everyone's emojis for the continuation of this conversation 👻📠)