Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ clang-format>=19.1.6
clang-tidy>=19.1.0
colorama>=0.4.6
gersemi>=0.16.2
shellcheck-py>=0.10.0
yamllint>=1.35.1
1 change: 1 addition & 0 deletions taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vars:
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
G_CMAKE_CACHE: "{{.G_BUILD_DIR}}/CMakeCache.txt"
G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json"
G_SCRIPT_DIR: "{{.ROOT_DIR}}/tools/scripts"
# Project-specific variables
G_YSTDLIB_CPP_SRC_DIR: "{{.ROOT_DIR}}/src/ystdlib"

Expand Down
66 changes: 66 additions & 0 deletions taskfiles/lint-sh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: "3"

tasks:
sh:
# NOTE: shellcheck does not have the ability to fix errors.
aliases:
- "sh-check"
- "sh-fix"
desc: "Runs the shell script linters. Only checks for warnings and violations."
vars:
SHELLCHECK_FLAGS: "--enable=all --severity=style --external-sources --norc"
sources:
- "{{.G_LINT_VENV_CHECKSUM_FILE}}"
- "{{.G_SCRIPT_DIR}}/**/*.sh"
- "{{.TASKFILE}}"
deps:
- "venv"
cmds:
- task: "linux-shellcheck"
vars:
FLAGS: "{{.SHELLCHECK_FLAGS}}"
SRC_PATHS:
ref: ".G_LINT_SH_DIRS"
VENV_DIR: "{{.G_LINT_VENV_DIR}}"
- task: "macos-shellcheck"
vars:
FLAGS: "{{.SHELLCHECK_FLAGS}}"
SRC_PATHS:
ref: ".G_LINT_SH_DIRS"
VENV_DIR: "{{.G_LINT_VENV_DIR}}"

linux-shellcheck:
internal: true
vars:
EXCLUDES:
- "**/macos"
- "**/centos-stream-9"
requires:
vars: ["FLAGS", "SRC_PATHS", "VENV_DIR"]
platforms: ["linux"] # Requires raw strings and cannot interpret variable substitutions
cmd: |-
. "{{.VENV_DIR}}/bin/activate"
find {{- range .SRC_PATHS}} "{{.}}" {{- end}} \
\( {{- range $i, $path := .EXCLUDES }}{{if $i}} -o {{end}} -path '{{ $path }}'{{end}} \) \
-prune -o \
-type f -iname "*.sh" \
-print0 | \
xargs -0 shellcheck {{.FLAGS}}

macos-shellcheck:
internal: true
vars:
EXCLUDES:
- "**/linux"
- "**/centos-stream-9"
requires:
vars: ["FLAGS", "SRC_PATHS", "VENV_DIR"]
platforms: ["darwin"]
cmd: |-
. "{{.VENV_DIR}}/bin/activate"
find {{- range .SRC_PATHS}} "{{.}}" {{- end}} \
\( {{- range $i, $path := .EXCLUDES }}{{if $i}} -o {{end}} -path '{{ $path }}'{{end}} \) \
-prune -o \
-type f -iname "*.sh" \
-print0 | \
xargs -0 shellcheck {{.FLAGS}}
7 changes: 7 additions & 0 deletions taskfiles/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ includes:
cpp:
flatten: true
taskfile: "./lint-cpp.yaml"
sh:
flatten: true
taskfile: "./lint-sh.yaml"
yaml:
flatten: true
taskfile: "./lint-yaml.yaml"

vars:
G_LINT_SH_DIRS:
- "{{.G_SCRIPT_DIR}}"
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv"
G_LINT_VENV_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/lint#venv.md5"
G_LINT_CPP_DIRS:
Expand All @@ -23,13 +28,15 @@ tasks:
cmds:
- task: "cmake-check"
- task: "cpp-check"
- task: "sh-check"
- task: "yaml-check"

fix:
desc: "Runs the full suite of linters and fixes some violations."
cmds:
- task: "cmake-fix"
- task: "cpp-fix"
- task: "sh-fix"
- task: "yaml-fix"

venv:
Expand Down
4 changes: 4 additions & 0 deletions tools/scripts/lib_install/centos-stream-9/centos-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# This should only be lintable on centos.
source /etc/centos-release
3 changes: 3 additions & 0 deletions tools/scripts/lib_install/general-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "Hello world"
4 changes: 4 additions & 0 deletions tools/scripts/lib_install/linux/linux-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# This should only be lintable on linux.
source /etc/os-release
5 changes: 5 additions & 0 deletions tools/scripts/lib_install/macos/macos-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# This should only be lintable on macos.
# shellcheck disable=SC1094
source /System/Library/CoreServices/SystemVersion.plist