Skip to content
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

fix: prevent splitting on an undefined value #247

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions widgets/images/imageList.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class myWidget extends ListWidget {

if (images) {
images.forEach((image) => {
const getTag = (tag, part) => tag ? tag[0].split(':')[part] : 'none'
const getTag = (tag, part) => (tag && tag.length) ? tag[0].split(':')[part] : 'none'

imageList.push([
image.Id.substring(7, 12),
image.RepoDigests ? image.RepoDigests[0].split('@')[0] : getTag(image[2], 0),
(image.RepoDigests && image.RepoDigests.length) ? image.RepoDigests[0].split('@')[0] : getTag(image[2], 0),
Copy link
Contributor Author

@saemik94 saemik94 Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use the chaining operator to check the values, but the linter prevents the use of this operator.

image.RepoDigests && image.RepoDigests.length vs. image.RepoDigests?.length

The dependency "default": "^12.0.1" would need to be updated, the latest version is 17.1.0 and the operator is supported from version 15. But this leads to a whole list of adjustments that would then have to be made. I am not sure how to handle this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to use as-is and skip the optional chaining due to support of older Node.js versions.

getTag(image.RepoTags, 1),
this.timeDifference(image.Created),
this.formatBytes(image.Size)
Expand Down