Skip to content

Commit df1bad4

Browse files
themr0cclaude
andcommitted
RHIDP-12779: Fix all shellcheck alerts across CQA scripts
- SC1091: Add disable for dynamic source paths - SC2329: Suppress for callback/helper functions invoked indirectly - SC2034: Suppress for variables used by sourcing scripts (CQA_FORMAT, CQA_OUTPUT_FORMAT, CQA_DELEGATES_TO) - SC2155: Separate local declarations from assignments - SC2318: Split combined local declarations - SC2004: Remove unnecessary $ in arithmetic expressions - SC2094: Suppress false positive for cqa_is_in_block (reads cached data) - SC2001: Replace sed with parameter expansion for CQA number extraction - Remove unused variables (level, file_fixed, need_ar_fix) - Rename loop variable to avoid shadowing function parameter (target -> delegate_to) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dded38f commit df1bad4

20 files changed

Lines changed: 88 additions & 35 deletions

build/scripts/cqa-00-orphaned-modules.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@
1313
#
1414
# Autofix (--fix): Deletes orphaned files (git rm if tracked, rm otherwise)
1515

16+
# shellcheck disable=SC1091
1617
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
1718

1819
# Custom arg parsing: accept standard flags but don't require a target file
1920
CQA_FIX_MODE=false
21+
# shellcheck disable=SC2034 # CQA_FORMAT/CQA_FIX_MODE used by cqa-lib output functions
2022
CQA_FORMAT="checklist"
23+
# shellcheck disable=SC2034
2124
for arg in "$@"; do
2225
case "$arg" in
2326
--fix) CQA_FIX_MODE=true ;;
2427
--all) ;; # accepted, ignored (always scans everything)
2528
--format=*) CQA_FORMAT="${arg#--format=}" ;;
2629
--format) ;; # next arg handled below
2730
checklist|json)
28-
# Could be the value after --format
2931
if [[ "${_prev_arg:-}" == "--format" ]]; then
3032
CQA_FORMAT="$arg"
3133
fi

build/scripts/cqa-01-asciidoctor-dita-vale.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
# - ShortDescription -> CQA #8
1717
# - DocumentId -> CQA #10
1818

19+
# shellcheck disable=SC1091
1920
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2021
cqa_parse_args "$0" "$@"
2122

23+
# shellcheck disable=SC2034 # Used by delegation framework
2224
CQA_DELEGATES_TO=("ShortDescription:8" "DocumentId:10")
2325

2426
[[ -f ".vale-dita-only.ini" ]] || { echo "Error: .vale-dita-only.ini not found" >&2; exit 1; }
2527

28+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
2629
_cqa01_check() {
2730
local target="$1"
2831

@@ -185,11 +188,11 @@ try:
185188
kind = 'manual'
186189
print(f\"{f}\t{i['Line']}\t{kind}\t{target}\t{fix_type}\t{check}: {i['Message']}\")
187190
except: pass
188-
" 2>/dev/null | while IFS=$'\t' read -r file line kind target fix_type message; do
191+
" 2>/dev/null | while IFS=$'\t' read -r file line kind delegate_to fix_type message; do
189192
case "$kind" in
190193
autofix) cqa_fail_autofix "$file" "$line" "$message" ;;
191194
manual) cqa_fail_manual "$file" "$line" "$message" ;;
192-
delegated) cqa_delegated "$file" "$line" "$target" "$message" "$fix_type" ;;
195+
delegated) cqa_delegated "$file" "$line" "$delegate_to" "$message" "$fix_type" ;;
193196
esac
194197
done
195198
else

build/scripts/cqa-02-assembly-structure.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,27 @@
1717
# Autofix: content type, context save/restore, ID suffix, :context:, prerequisites heading,
1818
# additional resources format
1919

20+
# shellcheck disable=SC1091
2021
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2122
cqa_parse_args "$0" "$@"
2223

23-
# Helper: get line number of first match
24+
# shellcheck disable=SC2329
2425
_lineno() { grep -n "$1" "$2" 2>/dev/null | head -1 | cut -d: -f1; }
2526

27+
# shellcheck disable=SC2329
2628
_fix_content_type_first_line() {
2729
local file="$1"
2830
sed -i '/^:_mod-docs-content-type:/d' "$file"
2931
sed -i '1s/^/:_mod-docs-content-type: ASSEMBLY\n/' "$file"
3032
}
3133

34+
# shellcheck disable=SC2329
3235
_fix_add_context_save() {
3336
local file="$1"
3437
sed -i '1a\ifdef::context[:parent-context: {context}]' "$file"
3538
}
3639

40+
# shellcheck disable=SC2329
3741
_fix_add_context_restore() {
3842
local file="$1"
3943
sed -i '/^ifdef::parent-context\[:context: {parent-context}\]$/d' "$file"
@@ -42,6 +46,7 @@ _fix_add_context_restore() {
4246
printf '\nifdef::parent-context[:context: {parent-context}]\nifndef::parent-context[:!context:]\n' >> "$file"
4347
}
4448

49+
# shellcheck disable=SC2329
4550
_fix_context_line() {
4651
local file="$1" title_ln="$2"
4752
sed -i '/^:context:/d' "$file"
@@ -52,6 +57,7 @@ _fix_context_line() {
5257
fi
5358
}
5459

60+
# shellcheck disable=SC2329
5561
_cqa02_check() {
5662
local target="$1"
5763

@@ -74,7 +80,8 @@ _cqa02_check() {
7480
[[ -f "$file" ]] || continue
7581

7682
cqa_file_start "$file"
77-
local is_master=$([[ "$(basename "$file")" == "master.adoc" ]] && echo true || echo false)
83+
local is_master
84+
is_master=$([[ "$(basename "$file")" == "master.adoc" ]] && echo true || echo false)
7885

7986
# Check 1: Content type on first line
8087
local first_line
@@ -205,7 +212,6 @@ _cqa02_check() {
205212
fi
206213

207214
# Check 9: Additional resources format
208-
local need_ar_fix=false
209215
if grep -q "^\.Additional resources" "$file"; then
210216
local ar_ln
211217
ar_ln=$(_lineno "^\.Additional resources" "$file")

build/scripts/cqa-03-content-is-modularized.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
# - Adds/fixes content type metadata
1212
# - Normalizes section list formatting
1313

14+
# shellcheck disable=SC1091
1415
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
1516
cqa_parse_args "$0" "$@"
1617

17-
# Detect content type from file content and filename
18+
# shellcheck disable=SC2329 # Helper functions invoked from _cqa03_check
1819
_detect_content_type() {
1920
local file="$1"
2021
local bn
@@ -40,19 +41,19 @@ _detect_content_type() {
4041
esac
4142
}
4243

43-
# Count occurrences of content type metadata
44+
# shellcheck disable=SC2329
4445
_count_type_occurrences() {
4546
grep -c "^:_mod-docs-content-type:" "$1" 2>/dev/null || echo "0"
4647
}
4748

48-
# Fix content type metadata
49+
# shellcheck disable=SC2329
4950
_fix_content_type() {
5051
local file="$1" type="$2"
5152
sed -i '/^:_mod-docs-content-type:/d' "$file"
5253
sed -i "1s/^/:_mod-docs-content-type: ${type}\n\n/" "$file"
5354
}
5455

55-
# Fix list formatting in a section (.Procedure or .Verification)
56+
# shellcheck disable=SC2329
5657
_fix_section_lists() {
5758
local file="$1" section="$2"
5859

@@ -100,6 +101,7 @@ _fix_section_lists() {
100101
return 0
101102
}
102103

104+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
103105
_cqa03_check() {
104106
local target="$1"
105107

build/scripts/cqa-04-modules-use-official-templates.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
# - ASSEMBLY and SNIPPET files
2121
# - master.adoc and attributes.adoc files
2222

23+
# shellcheck disable=SC1091
2324
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2425
cqa_parse_args "$0" "$@"
2526

27+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
2628
_cqa04_check() {
2729
local target="$1"
2830

build/scripts/cqa-05-modular-elements-checklist.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
# - Removes admonition titles
1818
# - Adds missing image alt text quotes
1919

20+
# shellcheck disable=SC1091
2021
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2122
cqa_parse_args "$0" "$@"
2223

2324
readonly PATTERN_BLOCK_TITLE='^\.[A-Z]'
2425

26+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
2527
_cqa05_check() {
2628
local target="$1"
2729

build/scripts/cqa-06-assemblies-use-the-official-template-assemblies-ar.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
# - Non-assembly files (PROCEDURE, CONCEPT, REFERENCE, SNIPPET)
1818
# - attributes.adoc files
1919

20+
# shellcheck disable=SC1091
2021
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2122
cqa_parse_args "$0" "$@"
2223

24+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
2325
_cqa06_check() {
2426
local target="$1"
2527

build/scripts/cqa-07-toc-max-3-levels.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
# - Content inside source/listing blocks (----, ....)
1616
# - attributes.adoc files
1717

18+
# shellcheck disable=SC1091
1819
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
1920
cqa_parse_args "$0" "$@"
2021

22+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
2123
_cqa07_check() {
2224
local target="$1"
2325

@@ -35,10 +37,10 @@ _cqa07_check() {
3537
local violation_line_nums=()
3638
local line_num=0
3739

40+
# shellcheck disable=SC2094 # cqa_is_in_block reads cached data, not $file
3841
while IFS= read -r line; do
3942
line_num=$((line_num + 1))
4043

41-
# Skip content inside blocks
4244
if cqa_is_in_block "$file" "$line_num"; then
4345
continue
4446
fi

build/scripts/cqa-08-short-description-content.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# - SNIPPET files
1717
# - attributes.adoc and master.adoc files
1818

19+
# shellcheck disable=SC1091
1920
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2021
cqa_parse_args "$0" "$@"
2122

@@ -49,6 +50,7 @@ SELF_REF_REMOVABLE=(
4950
"In this section, we "
5051
)
5152

53+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
5254
_cqa08_check() {
5355
local target="$1"
5456

build/scripts/cqa-09-short-description-format.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
# Skips:
1717
# - SNIPPET files
1818

19+
# shellcheck disable=SC1091
1920
source "$(dirname "${BASH_SOURCE[0]}")/cqa-lib.sh"
2021
cqa_parse_args "$0" "$@"
2122

23+
# shellcheck disable=SC2329 # Invoked indirectly via cqa_run_for_each_title
2224
_cqa09_check() {
2325
local target="$1"
2426

0 commit comments

Comments
 (0)