Skip to content

Commit

Permalink
Modify rule S6579: apply LaYC format (#3124)
Browse files Browse the repository at this point in the history
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)

---------

Co-authored-by: Marcin Stachniuk <[email protected]>
  • Loading branch information
rudy-regazzoni-sonarsource and mstachniuk authored Sep 25, 2023
1 parent c101d61 commit c8a38c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions rules/S6579/docker/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ It will be evaluated to an empty value.
== Why is this an issue?

The variables defined by `ARG` instruction have a scope from the definition to the end of the build stage where it was defined.
The variables will be unresolved (it will be empty) which may lead to unintended behaviour.
If it was defined in the beginning of the Dockerfile (outside of any build stage), then its scope is restricted to only `FROM` instructions.
Outside of their scope, variables will be resolved to empty string which may lead to unintended behaviour.

== How to fix it

Expand All @@ -19,7 +20,7 @@ FROM busybox
RUN ./run/setup $SETTINGS
----

In this case the `$SETTINGS` variable will be not evaluated.
In this case the `$SETTINGS` variable will be evaluated to empty string.

==== Compliant solution

Expand All @@ -41,7 +42,7 @@ FROM busybox
RUN ./run/setup $SETTINGS
----

In this case the `$SETTINGS` variable will be not evaluated, just the text `$SETTINGS` will be passed to `RUN` instruction.
In this case the `$SETTINGS` variable will be evaluated to empty string.

==== Compliant solution

Expand All @@ -53,7 +54,7 @@ ARG SETTINGS
RUN ./run/setup $SETTINGS
----

In this case the flag `--default-settings` will be passed to `RUN` instruction.
In this case the flag `--default-settings` will be passed to `RUN` instruction (unless another value is provided during build time).

=== How does this work?

Expand Down

0 comments on commit c8a38c9

Please sign in to comment.