blob: 75b5eef0ca8248c8b847af905d8f27b9bf036b09 [file] [edit]
#!/bin/bash
# Copyright 2026 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#### CATEGORY=Source tree
#### PREBUILTS=${PREBUILT_BLACK_DIR} ${PREBUILT_BUILDIFIER} ${PREBUILT_CLANG_DIR} ${PREBUILT_DART_DIR} ${PREBUILT_GN} ${PREBUILT_GO_DIR} ${PREBUILT_KEEP_SORTED} ${PREBUILT_PYTHON3} ${PREBUILT_RUST_DIR} ${PREBUILT_SHAC}
### runs static analysis checks on modified files via SHAC
## Usage: fx lint [options] [files...] [-- shac_args...]
##
## Runs static analysis checks registered in SHAC on modified source files
## (or on explicit files if specified).
##
## Options:
## --fix Apply automated fixes emitted by checks (runs 'shac fix').
## --all Run checks across all tracked files in the repository.
## --only <check> Run only the specified check(s) (comma-separated or repeated).
## --skip <check> Skip the specified check(s) (comma-separated or repeated).
## --commit-msg Lint commit message (alias for --only=commit_msg).
## --files <files> Comma-separated list of specific files to lint.
## -v, --verbose Print verbose command execution output.
## --dry-run Print shac commands without executing.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
if [[ -z "${JIRI_PACKAGES_DIR}" ]]; then
if git_common_dir=$(git -C "${FUCHSIA_DIR}" rev-parse --git-common-dir 2>/dev/null) && [[ -d "${git_common_dir}" ]]; then
parent_root=$(cd "${git_common_dir}/.." 2>/dev/null && pwd)
packages_dir="${parent_root}/.jiri_root/packages"
if [[ -d "${packages_dir}" ]]; then
export JIRI_PACKAGES_DIR="${packages_dir}"
fi
fi
fi
export PREBUILT_SHAC
export PYTHONPATH="${FUCHSIA_DIR}/tools/devshell/lib${PYTHONPATH:+:${PYTHONPATH}}"
exec "${PREBUILT_PYTHON3}" "${FUCHSIA_DIR}/tools/devshell/lint.py" "$@"