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

https://github.com/jackdewinter/pymarkdown/issues/1322 #1323

Merged
merged 12 commits into from
Jan 20, 2025

Conversation

jackdewinter
Copy link
Owner

@jackdewinter jackdewinter commented Jan 20, 2025

#1322

closes #1322

Summary by Sourcery

Format shell scripts with shfmt, and lint them with shellcheck.

Build:

  • Format shell scripts with shfmt.
  • Lint shell scripts with Shellcheck and enforce the "require-variable-braces" rule.

CI:

  • Add shfmt and Shellcheck to the pre-commit configuration.

Copy link
Contributor

sourcery-ai bot commented Jan 20, 2025

Reviewer's Guide by Sourcery

This pull request focuses on improving the project's shell scripts by adding a linter and formatter to the pre-commit hooks, and updating the scripts to be more robust.

Flow diagram for updated shell script validation process

graph TD
    A[Shell Script] --> B{Pre-commit hooks}
    B --> C[ShFmt Formatter]
    B --> D[Shellcheck Linter]
    C --> E[Format shell script]
    D --> F[Validate shell script]
    E --> G[Formatted script]
    F --> |Pass| H[Valid script]
    F --> |Fail| I[Validation errors]
    style B fill:#f9f,stroke:#333,stroke-width:2px
Loading

File-Level Changes

Change Details Files
Added Shellcheck to pre-commit hooks.
  • Added shellcheck pre-commit hook.
  • Added arguments to shellcheck to require variable braces.
.pre-commit-config.yaml
Added ShFmt to pre-commit hooks.
  • Added shfmt pre-commit hook.
.pre-commit-config.yaml
Updated shell scripts to be more robust.
  • Replaced deprecated $(...) with backticks.
  • Replaced deprecated if [[ $var -ne 0 ]] with if [[ ${var} -ne 0 ]].
  • Replaced deprecated if [ -f "$TEMP_FILE" ] with if [ -f "${TEMP_FILE}" ].
  • Replaced deprecated if ! pushd . > "$TEMP_FILE" 2>&1 with if ! pushd "${SCRIPT_DIR}" > "${TEMP_FILE}" 2>&1.
  • Replaced deprecated echo "{...}" with echo "{...}".
  • Replaced deprecated local SCRIPT_RETURN_CODE=$1 with local SCRIPT_RETURN_CODE=${1}.
  • Replaced deprecated local COMPLETE_REASON=${2:-} with local COMPLETE_REASON=${2:-}.
  • Replaced deprecated if [[ $key_value == #* ]] with if [[ ${key_value} == #* ]].
  • Replaced deprecated `key=$(echo "$key_value"
cut -d '=' -f1)withkey=$(echo "${key_value}"

Assessment against linked issues

Issue Objective Addressed Explanation
#1322 Shellcheck should be executed over all project shell scripts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jackdewinter - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Hardcoded secret set SOURCERY_USER_KEY=0123456789abcdef0123456789abcdef01234567 should not be committed to the repository. (link)
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

fi

pipenv run python $PYTHON_PERFORMANCE_ARGUMENTS "${SCRIPT_DIR}/main.py" ${PARAMS[*]}
pipenv run python ${PYTHON_PERFORMANCE_ARGUMENTS} "${SCRIPT_DIR}/main.py" "${PARAMS[@]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Use "${array[@]}" consistently for array expansion across all scripts

While ${array[*]} works in many cases, "${array[@]}" handles spaces in parameters more reliably. Consider standardizing on [@] across all scripts.

Suggested implementation:

complete_process "${EXIT_CODE}"

The developer should also review any other scripts in the project for similar array expansions using ${array[*]} and standardize them to use "${array[@]}" for consistency.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (bf8ea06) to head (a09f302).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1323   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          191       191           
  Lines        21590     21590           
  Branches      3991      3991           
=========================================
  Hits         21590     21590           

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

@jackdewinter jackdewinter merged commit a140995 into main Jan 20, 2025
27 checks passed
@jackdewinter jackdewinter deleted the issue-1302 branch January 20, 2025 16:45
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.

Adding Shellcheck support for newly added shell scripts.
1 participant