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

checks: add redundant target platform check #5091

Merged
merged 1 commit into from
Jun 29, 2024

Conversation

jsternberg
Copy link
Collaborator

Adds a linter check that checks if --platform=$TARGETPLATFORM is used and sends a linter message marking this as redundant. This is because $TARGETPLATFORM is the default.

@jsternberg jsternberg force-pushed the lint-redundant-target-platform branch 2 times, most recently from 72cf668 to 5b906e9 Compare June 26, 2024 20:52
@@ -316,6 +316,10 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
}

if v := st.Platform; v != "" {
// Mark whether the specified platform is redudant for the linter
Copy link
Member

Choose a reason for hiding this comment

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

"redundant"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing this line due to another section of the code review.

@@ -316,6 +316,10 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
}

if v := st.Platform; v != "" {
// Mark whether the specified platform is redudant for the linter
// to pick up later.
ds.platformRedundant = v == "$TARGETPLATFORM"
Copy link
Member

Choose a reason for hiding this comment

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

This can also be "${}". Probably better to check the platMatch, so that the return value equals the targetplatform value and platMatch.Matched equals TARGETPLATFORM.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've modified this to use the platform match and integrated it more closely with the existing report unused args so I've removed this variable and this check.

// Mark whether the specified platform is redudant for the linter
// to pick up later.
ds.platformRedundant = v == "$TARGETPLATFORM"

Copy link
Member

Choose a reason for hiding this comment

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

If we are going to defer returning the warning to dispatch() (to only return warnings for reachable stages) then it should be done for this reportUnusedFromArgs condition as well. In that case the key in the dispatchState can be something like stageWarnings or warnings and contain the slice of warnings that will all be reported if stage is found to be reachable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've integrated this with the existing report unused args using the same shell match and reported the error there. If we decide that warnings should only be reported if reachable, we can change that for all of them at once. I'd like to avoid modifying how the other variables are reported within this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Opened #5099 for tracking.

@thompson-shaun thompson-shaun added this to the v0.15.0 milestone Jun 27, 2024
@jsternberg jsternberg force-pushed the lint-redundant-target-platform branch 6 times, most recently from 086fc9e to 8582d58 Compare June 27, 2024 16:36
@thompson-shaun thompson-shaun changed the title linter: add redundant target platform check checks: add redundant target platform check Jun 27, 2024
@jsternberg jsternberg force-pushed the lint-redundant-target-platform branch 3 times, most recently from 14b3151 to eb1e97d Compare June 27, 2024 17:03
// Only match this rule if there was only one matched name.
// It's psosible there were multiple args and that one of them expanded to an empty
// string and we don't want to report a warning when that happens.
if len(nameMatch.Matched) == 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Also check len(Unmatched)==0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

RUN apk add --no-cache git
```

✅ Good: an alternative `--platform` can be set to compile for the host platform.
Copy link
Member

Choose a reason for hiding this comment

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

The main good example should be just skipping the flag.

// Mark whether the specified platform is redudant for the linter
// to pick up later.
ds.platformRedundant = v == "$TARGETPLATFORM"

Copy link
Member

Choose a reason for hiding this comment

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

Opened #5099 for tracking.

@jsternberg jsternberg force-pushed the lint-redundant-target-platform branch from eb1e97d to e45eeda Compare June 27, 2024 17:35
Adds a linter check that checks if `--platform=$TARGETPLATFORM` is used
and sends a linter message marking this as redundant. This is because
`$TARGETPLATFORM` is the default.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
@jsternberg jsternberg force-pushed the lint-redundant-target-platform branch from e45eeda to fe6a7dc Compare June 27, 2024 17:57
@tonistiigi tonistiigi merged commit 2ec1338 into moby:master Jun 29, 2024
77 checks passed
@jsternberg jsternberg deleted the lint-redundant-target-platform branch July 10, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants