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

fetch-configlet: make some variables local #691

Merged
merged 5 commits into from
Oct 31, 2022

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Oct 27, 2022

Reduce the number of globals.

From e.g. the Google Shell Style Guide:

Ensure that local variables are only seen inside a function and its children by using local when declaring them. This avoids polluting the global name space and inadvertently setting variables that may have significance outside the function.

Declaration and assignment must be separate statements when the assignment value is provided by a command substitution; as the local builtin does not propagate the exit code from the command substitution.

my_func2() {
 local name="$1"

 # Separate lines for declaration and assignment:
 local my_var
 my_var="$(my_func)"
 (( $? == 0 )) || return

 …
}
my_func2() {
 # DO NOT do this:
 # $? will always be zero, as it contains the exit code of 'local', not my_func
 local my_var="$(my_func)"
 (( $? == 0 )) || return

 …
}

@ee7 ee7 force-pushed the fetch-configlet-use-local branch from f51ea79 to 4a23f0e Compare October 31, 2022 21:59
@ee7 ee7 merged commit 013c66b into exercism:main Oct 31, 2022
@ee7 ee7 deleted the fetch-configlet-use-local branch October 31, 2022 22:23
@ee7 ee7 changed the title fetch-configlet: use local fetch-configlet: make some variables local Oct 31, 2022
petertseng pushed a commit to petertseng/exercism-rust that referenced this pull request Nov 17, 2022
From e.g. the Google Shell Style Guide [1]:

    Ensure that local variables are only seen inside a function and its
    children by using `local` when declaring them. This avoids polluting
    the global name space and inadvertently setting variables that may
    have significance outside the function.

    Declaration and assignment must be separate statements when the
    assignment value is provided by a command substitution; as the
    `local` builtin does not propagate the exit code from the command
    substitution.

[1] https://google.github.io/styleguide/shellguide.html#use-local-variables

exercism/configlet#691
petertseng pushed a commit to petertseng/exercism-haskell that referenced this pull request Nov 17, 2022
From e.g. the Google Shell Style Guide [1]:

    Ensure that local variables are only seen inside a function and its
    children by using `local` when declaring them. This avoids polluting
    the global name space and inadvertently setting variables that may
    have significance outside the function.

    Declaration and assignment must be separate statements when the
    assignment value is provided by a command substitution; as the
    `local` builtin does not propagate the exit code from the command
    substitution.

[1] https://google.github.io/styleguide/shellguide.html#use-local-variables

exercism/configlet#691
petertseng pushed a commit to petertseng/exercism-haskell that referenced this pull request Nov 17, 2022
From e.g. the Google Shell Style Guide [1]:

    Ensure that local variables are only seen inside a function and its
    children by using `local` when declaring them. This avoids polluting
    the global name space and inadvertently setting variables that may
    have significance outside the function.

    Declaration and assignment must be separate statements when the
    assignment value is provided by a command substitution; as the
    `local` builtin does not propagate the exit code from the command
    substitution.

[1] https://google.github.io/styleguide/shellguide.html#use-local-variables

exercism/configlet#691
petertseng pushed a commit to petertseng/exercism-rust that referenced this pull request Nov 17, 2022
From e.g. the Google Shell Style Guide [1]:

    Ensure that local variables are only seen inside a function and its
    children by using `local` when declaring them. This avoids polluting
    the global name space and inadvertently setting variables that may
    have significance outside the function.

    Declaration and assignment must be separate statements when the
    assignment value is provided by a command substitution; as the
    `local` builtin does not propagate the exit code from the command
    substitution.

[1] https://google.github.io/styleguide/shellguide.html#use-local-variables

exercism/configlet#691
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.

2 participants