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

linter: lint rule for using the legacy key/value format with whitespace #4923

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsternberg
Copy link
Collaborator

The ENV and LABEL commands both support using either a whitespace delimited token or one delimited with the equals token. The equals token is preferred because it is more explicit and less ambiguous than using whitespace. The linter rule emits a warning when it sees the whitespace separator used.

To facilitate this, the parser was modified to include the separator as a node in the tree. The associated parsing code has also been changed for 3 arguments instead of only 2 per key/value pair.

@jsternberg jsternberg force-pushed the lint-legacy-key-value-env branch 4 times, most recently from 18a8384 to 6be16d1 Compare May 14, 2024 18:02
@tonistiigi tonistiigi requested a review from thaJeztah May 14, 2024 18:46
Comment on lines +634 to +636
FROM scratch
ENV key value
LABEL key value
Copy link
Member

Choose a reason for hiding this comment

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

I know there were some concerns about warning about these being potentially too strict.

Wondering if we should have a "more permissive" and "more strict" rule. The most problematic ones are when multiple whitespaces are present;

ARG key one two
ENV key one two

Those look very much alike, but ARG means 3 args are defined, but the ENV one defines a single key env with value one two

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, but left a suggestion (wondering if this one may be too noisy for some if it's by default 🤔)

@tonistiigi tonistiigi added this to the v0.14.0 milestone May 28, 2024
@@ -105,4 +105,11 @@ var (
return fmt.Sprintf("Multiple %s instructions should not be used in the same stage because only the last one will be used", instructionName)
},
}
RuleLegacyKeyValueFormat = LinterRule[func(cmdName string) string]{
Copy link
Member

Choose a reason for hiding this comment

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

We should provide some hint that key=value should be used instead in the message. Most users will not know what is "legacy format"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this message to read differently so now it explicitly mentions the solution in the detailed description.

The `ENV` and `LABEL` commands both support using either a whitespace
delimited token or one delimited with the equals token. The equals token
is preferred because it is more explicit and less ambiguous than using
whitespace. The linter rule emits a warning when it sees the whitespace
separator used.

To facilitate this, the parser was modified to include the separator as
a node in the tree. The associated parsing code has also been changed
for 3 arguments instead of only 2 per key/value pair.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants