-
Notifications
You must be signed in to change notification settings - Fork 243
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
Add amp-img srcset linter check #926
Conversation
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.
Looks great. Could be worth also adding warn cases for layout = fill
, flex-item
, and intrinsic
.
Are there any additional considerations for nested amp-img
in the case where the inner element is provided as a fallback?
@caroqliu I did not think about nested amp-img before. |
}); | ||
if (incorrectImages.length > 0) { | ||
return this.warn( | ||
"Not all <amp-img> with non-fixed layout define a srcset. Using AMP Optimizer might help." |
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.
@caroqliu I have changed the check so that it will emit a warning for each image. |
I'm not seeing a new commit since the last review, am I missing something? |
@caroqliu oops, the push hook failed. |
incorrectImages.map((_, e) => { | ||
const s = $(e).toString(); | ||
return this.warn( | ||
`[${s}] should define a srcset. Using AMP Optimizer might help.` |
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.
Sorry, I should have clarified -- this looks like it is emitting a warning for every image that is missing a srcset. It may be more manageable to send a single warning that lists all the images that are missing a srcset, similar to the images missing alt text:
amp-toolbox/packages/linter/src/rules/ImagesHaveAltText.ts
Lines 24 to 32 in 25a4df3
for (let key in imgsWithoutAlt) { | |
imgsWithoutAlt[key] > 1 | |
? (output += key + color(" [used " + imgsWithoutAlt[key] + " times]\n")) | |
: (output += key + "\n"); | |
} | |
return Object.keys(imgsWithoutAlt).length > 0 | |
? this.warn("Missing alt text from images: \n" + output) | |
: this.pass(); |
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'm open to emitting multiple warnings if that sounds like a better approach to you, what do you think?
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 are all possible approaches in the different linter tests, so there is no "right" way to do this.
Some checks emit one warning without details to the findings, some emit one warning with details to the findings like you suggested and some emit a warning for each finding.
If we ever want to show the results in the frontend I think a list of warnings is a better approach.
We might be able to add other metadata to each entry that can be used to display a nice list like in your screenshot.
With only one warning entry this will never be possible.
No description provided.