Skip to content

fetch-configlet: make some variables local#691

Merged
ee7 merged 5 commits intoexercism:mainfrom
ee7:fetch-configlet-use-local
Oct 31, 2022
Merged

fetch-configlet: make some variables local#691
ee7 merged 5 commits intoexercism:mainfrom
ee7:fetch-configlet-use-local

Conversation

@ee7
Copy link
Copy Markdown
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 requested a review from ErikSchierboom as a code owner October 27, 2022 11:30
@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