mirror of
https://github.com/searxng/searxng.git
synced 2025-09-04 01:08:33 +02:00
[enh] sh: add shell formatter
Related https://github.com/searxng/searxng/issues/4803
This commit is contained in:
parent
4b9644eb27
commit
2311d16497
8 changed files with 67 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM mcr.microsoft.com/devcontainers/base:debian
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get -y install python3 python3-venv valkey firefox-esr graphviz imagemagick librsvg2-bin fonts-dejavu shellcheck
|
||||
apt-get -y install python3 python3-venv valkey firefox-esr graphviz imagemagick librsvg2-bin fonts-dejavu shellcheck shfmt
|
||||
|
|
|
@ -50,3 +50,6 @@ max_line_length = 79
|
|||
|
||||
[*.yml]
|
||||
indent_size = 2
|
||||
|
||||
[[shell]]
|
||||
switch_case_indent = true
|
3
.github/workflows/integration.yml
vendored
3
.github/workflows/integration.yml
vendored
|
@ -34,6 +34,9 @@ jobs:
|
|||
- "3.13"
|
||||
|
||||
steps:
|
||||
- name: Install shfmt
|
||||
run: sudo apt-get install -y shfmt
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
|
|
8
Makefile
8
Makefile
|
@ -50,8 +50,8 @@ search.checker.%: install
|
|||
$(Q)./manage pyenv.cmd searxng-checker -v "$(subst _, ,$(patsubst search.checker.%,%,$@))"
|
||||
|
||||
PHONY += test ci.test test.shell
|
||||
ci.test: test.yamllint test.black test.types.ci test.pylint test.unit test.robot test.rst test.shell test.pybabel
|
||||
test: test.yamllint test.black test.types.dev test.pylint test.unit test.robot test.rst test.shell
|
||||
ci.test: test.yamllint test.shfmt test.black test.types.ci test.pylint test.unit test.robot test.rst test.shell test.pybabel
|
||||
test: test.yamllint test.shfmt test.black test.types.dev test.pylint test.unit test.robot test.rst test.shell
|
||||
test.shell:
|
||||
$(Q)shellcheck -x -s dash \
|
||||
container/entrypoint.sh
|
||||
|
@ -82,8 +82,8 @@ MANAGE += gecko.driver
|
|||
MANAGE += node.env node.env.dev node.clean
|
||||
MANAGE += py.build py.clean
|
||||
MANAGE += pyenv pyenv.install pyenv.uninstall
|
||||
MANAGE += format.python
|
||||
MANAGE += test.yamllint test.pylint test.black test.pybabel test.unit test.coverage test.robot test.rst test.clean test.themes test.types.dev test.types.ci
|
||||
MANAGE += format.python format.shell
|
||||
MANAGE += test.yamllint test.pylint test.shfmt test.black test.pybabel test.unit test.coverage test.robot test.rst test.clean test.themes test.types.dev test.types.ci
|
||||
MANAGE += themes.all themes.simple themes.fix themes.lint themes.test
|
||||
MANAGE += static.build.commit static.build.drop static.build.restore
|
||||
MANAGE += nvm.install nvm.clean nvm.status nvm.nodejs
|
||||
|
|
|
@ -161,3 +161,33 @@ To lint shell scripts we use ShellCheck_ - a shell script static analysis tool
|
|||
$ sudo dnf install ShellCheck
|
||||
|
||||
.. SNAP sh lint requirements
|
||||
|
||||
.. _sh format:
|
||||
|
||||
Format shell scripts
|
||||
====================
|
||||
|
||||
.. _shfmt: https://github.com/mvdan/sh
|
||||
|
||||
To format shell scripts we use shfmt_ - a shell script parser & formatter
|
||||
(:ref:`install buildhost <searxng.sh install buildhost>`).
|
||||
|
||||
.. tabs::
|
||||
|
||||
.. group-tab:: Ubuntu / debian
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
$ sudo apt install shfmt
|
||||
|
||||
.. group-tab:: Arch Linux
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
$ sudo pacman -S shfmt
|
||||
|
||||
.. group-tab:: Fedora / RHEL
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
$ sudo dnf install shfmt
|
||||
|
|
16
manage
16
manage
|
@ -51,6 +51,14 @@ GECKODRIVER_VERSION="v0.35.0"
|
|||
# SPHINXOPTS=
|
||||
BLACK_OPTIONS=("--target-version" "py311" "--line-length" "120" "--skip-string-normalization")
|
||||
BLACK_TARGETS=("--exclude" "(searx/static|searx/languages.py)" "--include" 'searxng.msg|\.pyi?$' "searx" "searxng_extra" "tests")
|
||||
SHFMT_TARGETS=(
|
||||
"./container/"
|
||||
"./docs/"
|
||||
"./searx/"
|
||||
"./searxng_extra/"
|
||||
"./tests/"
|
||||
"./utils/"
|
||||
"./manage")
|
||||
|
||||
YAMLLINT_FILES=()
|
||||
while IFS= read -r line; do
|
||||
|
@ -218,11 +226,17 @@ pyenv.uninstall() {
|
|||
}
|
||||
|
||||
format.python() {
|
||||
build_msg TEST "[format.python] black \$BLACK_TARGETS"
|
||||
build_msg TEST "[format.python] black ${BLACK_TARGETS[*]}"
|
||||
pyenv.cmd black "${BLACK_OPTIONS[@]}" "${BLACK_TARGETS[@]}"
|
||||
dump_return $?
|
||||
}
|
||||
|
||||
format.shell() {
|
||||
build_msg TEST "[format.shell] shfmt ${SHFMT_TARGETS[*]}"
|
||||
shfmt --list --write --apply-ignore --simplify "${SHFMT_TARGETS[@]}"
|
||||
dump_return $?
|
||||
}
|
||||
|
||||
docs.prebuild() {
|
||||
build_msg DOCS "build ${DOCS_BUILD}/includes"
|
||||
(
|
||||
|
|
|
@ -8,6 +8,7 @@ test.:
|
|||
pylint : lint ./searx, ./searxng_extra and ./tests
|
||||
pyright : static type check of python sources (.dev or .ci)
|
||||
black : check black code format
|
||||
shfmt : check shfmt code format
|
||||
unit : run unit tests
|
||||
coverage : run unit tests with coverage
|
||||
robot : run robot test
|
||||
|
@ -100,11 +101,17 @@ test.types.ci() {
|
|||
}
|
||||
|
||||
test.black() {
|
||||
build_msg TEST "[black] \$BLACK_TARGETS"
|
||||
build_msg TEST "[black] ${BLACK_TARGETS[*]}"
|
||||
pyenv.cmd black --check --diff "${BLACK_OPTIONS[@]}" "${BLACK_TARGETS[@]}"
|
||||
dump_return $?
|
||||
}
|
||||
|
||||
test.shfmt() {
|
||||
build_msg TEST "[shfmt] ${SHFMT_TARGETS[*]}"
|
||||
shfmt --list --diff --apply-ignore --simplify "${SHFMT_TARGETS[@]}"
|
||||
dump_return $?
|
||||
}
|
||||
|
||||
test.unit() {
|
||||
build_msg TEST 'tests/unit'
|
||||
# shellcheck disable=SC2086
|
||||
|
|
|
@ -66,7 +66,7 @@ git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev"
|
|||
SEARXNG_BUILD_PACKAGES_debian="\
|
||||
graphviz imagemagick texlive-xetex librsvg2-bin
|
||||
texlive-latex-recommended texlive-extra-utils fonts-dejavu
|
||||
latexmk shellcheck"
|
||||
latexmk shellcheck shfmt"
|
||||
|
||||
# pacman packages
|
||||
|
||||
|
@ -77,7 +77,7 @@ git base-devel libxml2"
|
|||
|
||||
SEARXNG_BUILD_PACKAGES_arch="\
|
||||
graphviz imagemagick texlive-bin extra/librsvg
|
||||
texlive-core texlive-latexextra ttf-dejavu shellcheck"
|
||||
texlive-core texlive-latexextra ttf-dejavu shellcheck shfmt"
|
||||
|
||||
# dnf packages
|
||||
|
||||
|
@ -90,7 +90,7 @@ SEARXNG_BUILD_PACKAGES_fedora="\
|
|||
graphviz graphviz-gd ImageMagick librsvg2-tools
|
||||
texlive-xetex-bin texlive-collection-fontsrecommended
|
||||
texlive-collection-latex dejavu-sans-fonts dejavu-serif-fonts
|
||||
dejavu-sans-mono-fonts ShellCheck"
|
||||
dejavu-sans-mono-fonts ShellCheck shfmt"
|
||||
|
||||
case $DIST_ID-$DIST_VERS in
|
||||
ubuntu-18.04)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue