Skip to content

CI: fix some more linter advice for old code#6317

Merged
algorandskiy merged 4 commits intoalgorand:masterfrom
cce:clean-more-linters
May 23, 2025
Merged

CI: fix some more linter advice for old code#6317
algorandskiy merged 4 commits intoalgorand:masterfrom
cce:clean-more-linters

Conversation

@cce
Copy link
Copy Markdown
Contributor

@cce cce commented May 9, 2025

Summary

Following on #6315 this fixes all issues raised by the nilerr linter, and some of the govet issues, for older parts of the codebase. For govet it focuses just on error-shadowing warnings of the form shadow: declaration of "err" shadows declaration at line X by using a script (source in comment on 9e92a30) that parses each error and calls gopls rename to rename err to err1, err1 to err2, etc.

Test Plan

Existing tests should pass.

cce added 2 commits May 6, 2025 15:58
TARGET_VAR="err"
NEW_VAR="err1"

if [ "$#" -ge 1 ]; then
  TARGET_VAR="$1"
fi

if [ "$#" -ge 2 ]; then
  NEW_VAR="$2"
fi

echo "Will rename shadowed '$TARGET_VAR' variables to '$NEW_VAR'"

extract_location() {
  local error_line="$1"
  echo "$error_line" | grep -o "[^:]*:[0-9]*:[0-9]*" | head -1
}

echo "Running 'make lint' to find shadowed '$TARGET_VAR' variables..."
lint_output=$(make lint | grep "\"$TARGET_VAR\" shadows")
issue_count=$(echo "$lint_output" | grep -c .)
echo "Found $issue_count potential '$TARGET_VAR' shadowing issues"

echo "$lint_output" | while read -r line; do
  echo "----------------------------------------"
  echo "Processing: $line"
  if [[ $line == *"\"$TARGET_VAR\" shadows"* ]]; then
    # Extract file and position information
    location=$(extract_location "$line")
    if [ -z "$location" ]; then
      echo "Failed to extract location from: $line"
      continue
    fi
    echo "About to execute: gopls rename -w '$location' '$NEW_VAR'"
    gopls rename -w "$location" "$NEW_VAR"

    rename_result=$?
    if [ $rename_result -eq 0 ]; then
      echo "Successfully renamed variable '$TARGET_VAR' to '$NEW_VAR' at $location"
    else
      echo "Failed to rename variable with exit code $rename_result."
    fi
  fi
done
@codecov
Copy link
Copy Markdown

codecov bot commented May 9, 2025

Codecov Report

Attention: Patch coverage is 8.47458% with 270 lines in your changes missing coverage. Please review.

Project coverage is 51.64%. Comparing base (039c933) to head (99cf56c).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
cmd/goal/clerk.go 0.00% 32 Missing ⚠️
cmd/algod/main.go 0.00% 18 Missing ⚠️
cmd/goal/wallet.go 0.00% 18 Missing ⚠️
cmd/netgoal/generate.go 0.00% 18 Missing ⚠️
logging/cyclicWriter.go 14.28% 15 Missing and 3 partials ⚠️
data/account/account.go 23.80% 11 Missing and 5 partials ⚠️
gen/generate.go 26.31% 10 Missing and 4 partials ⚠️
cmd/pingpong/runCmd.go 0.00% 10 Missing ⚠️
cmd/algokey/multisig.go 0.00% 9 Missing ⚠️
cmd/diagcfg/telemetry.go 0.00% 9 Missing ⚠️
... and 32 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6317      +/-   ##
==========================================
- Coverage   51.65%   51.64%   -0.01%     
==========================================
  Files         649      649              
  Lines       86964    86964              
==========================================
- Hits        44918    44914       -4     
- Misses      39192    39193       +1     
- Partials     2854     2857       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

algorandskiy
algorandskiy previously approved these changes May 9, 2025
@cce cce requested a review from jannotti May 13, 2025 16:33
jannotti
jannotti previously approved these changes May 13, 2025
Copy link
Copy Markdown
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

Seems good. What's weird is that we're just doing what the compiler would have done anyway. So, if this is worth a linter complaining about, why is it ok to paper it over with a script? Presumably, the linter is worried that when you shadowed err you didn't really mean to, and you instead meant to assign to the top-level err and have some code, lower down, return it. I suppose we don't need to worry that we're papering over that mistake, because after the transformation, we would instead get a linter error that err1 was ignored.
Is that all right? I had to type it out to convince myself.

@cce
Copy link
Copy Markdown
Contributor Author

cce commented May 22, 2025

So, if this is worth a linter complaining about, why is it ok to paper it over with a script? Presumably, the linter is worried that when you shadowed err you didn't really mean to, and you instead meant to assign to the top-level err and have some code, lower down, return it. I suppose we don't need to worry that we're papering over that mistake, because after the transformation, we would instead get a linter error that err1 was ignored.
Is that all right? I had to type it out to convince myself.

Yes, it forces you to consider whether you wanted to shadow or not — we originally introduced this linter because a unintentional use of a shadowed variable led to a real bug, so we turned it on for new code. Retroactively going back and updating the codebase just makes it uniform, so the same standard is followed everywhere.

@cce cce dismissed stale reviews from jannotti and algorandskiy via b53087a May 22, 2025 17:33
@cce cce requested review from algorandskiy and jannotti May 22, 2025 17:34
@algorandskiy algorandskiy merged commit 7ce14c2 into algorand:master May 23, 2025
19 checks passed
@cce cce deleted the clean-more-linters branch May 23, 2025 16:59
cce added a commit to cce/go-algorand that referenced this pull request May 29, 2025
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.

3 participants