Migrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.
中文简介正在准备中。当前显示原文说明。
シェルスクリプト品質のためのShellCheck静的解析の設定と使用をマスター。リンティングインフラの設定、コード問題の修正、またはスクリプトの移植性の確保時に使用してください。
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
English | 日本語
ShellCheckの設定と使用に関する包括的なガイダンス。静的コード解析を通じてシェルスクリプトの品質を改善し、一般的な落とし穴を捕捉し、ベストプラクティスを実施します。
ShellCheckは、シェルスクリプトを分析し問題のあるパターンを検出する静的解析ツールです。以下をサポートします:
# macOS with Homebrew
brew install shellcheck
# Ubuntu/Debian
apt-get install shellcheck
# From source
git clone https://github.com/koalaman/shellcheck.git
cd shellcheck
make build
make install
# インストールを確認
shellcheck --version
プロジェクトルートに.shellcheckrcを作成:
# ターゲットシェルを指定
shell=bash
# オプションチェックを有効化
enable=avoid-nullary-conditions
enable=require-variable-braces
# 特定の警告を無効化
disable=SC1091
disable=SC2086
# デフォルトシェルターゲットを設定
export SHELLCHECK_SHELL=bash
# 厳格モードを有効化
export SHELLCHECK_STRICT=true
# 設定ファイルの場所を指定
export SHELLCHECK_CONFIG=~/.shellcheckrc
# SC1004: バックスラッシュ継続が改行に続かない
echo hello\\\nworld # エラー - 行継続が必要
# SC1008: 演算子`=='の無効なデータ
if [[ $var = "value" ]]; then # ==の前のスペース
true
fi
# SC2009: grepの代わりにpgrepまたはpidofの使用を検討
ps aux | grep -v grep | grep myprocess # 代わりにpgrepを使用
# SC2012: `ls`は閲覧のみに使用。信頼性のある出力には`find`を使用
for file in $(ls -la) # より良い方法: findまたはグロビングを使用
# SC2015: if-then-elseの代わりに&&と||を使用するのを避ける
[[ -f "$file" ]] && echo "found" || echo "not found" # より明確でない
# SC2016: 式はシングルクォートで展開されない
echo '$VAR' # リテラル$VAR、変数展開ではない
# SC2026: この単語は非標準。他のシェル用スクリプトで使用する場合はPOSIXLY_CORRECTを設定
# SC2086: グロビングと単語分割を防ぐためダブルクォート
for i in $list; do # 次であるべき: for i in $listまたはfor i in "$list"
echo "$i"
done
# SC2115: パスのリテラルチルダは展開されない。代わりに$HOMEを使用
~/.bashrc # 文字列内では、"$HOME/.bashrc"を使用
# SC2181: `if`で直接終了コードをチェック、リストで間接的ではない
some_command
if [ $? -eq 0 ]; then # より良い方法: if some_command; then
# SC2206: 単語分割を防ぐためクォートまたはIFSを設定
array=( $items ) # 次を使用すべき: array=( $items )
# SC3010: POSIX shでは、'cond && foo'の代わりに'case'を使用
[[ $var == "value" ]] && do_something # POSIXでない
# SC3043: POSIX shでは、'local'は未定義
function my_func() {
local var=value # 一部のシェルではPOSIXでない
}
#!/bin/bash
# 最大の移植性のため設定
shellcheck \
--shell=sh \
--external-sources \
--check-sourced \
script.sh
#!/bin/bash
# Bash開発のため設定
shellcheck \
--shell=bash \
--exclude=SC1091,SC2119 \
--enable=all \
script.sh
#!/bin/bash
set -Eeuo pipefail
# すべてのシェルスクリプトを分析し、問題で失敗
find . -type f -name "*.sh" | while read -r script; do
echo "Checking: $script"
shellcheck \
--shell=bash \
--format=gcc \
--exclude=SC1091 \
"$script" || exit 1
done
# 分析するシェル方言
shell=bash
# オプションチェックを有効化
enable=avoid-nullary-conditions,require-variable-braces,check-unassigned-uppercase
# 特定の警告を無効化
# SC1091: ソースされたファイルをフォローしない(多くの誤検出)
disable=SC1091
# SC2119: function_name--(引数)の代わりにfunction_nameを使用
disable=SC2119
# コンテキストのため外部ファイルをソース
external-sources=true
#!/bin/bash
# .git/hooks/pre-commit
#!/bin/bash
set -e
# このコミットで変更されたすべてのシェルスクリプトを検索
git diff --cached --name-only | grep '\\.sh$' | while read -r script; do
echo "Linting: $script"
if ! shellcheck "$script"; then
echo "ShellCheck failed on $script"
exit 1
fi
done
name: ShellCheck
on: [push, pull_request]
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
run: |
sudo apt-get install shellcheck
find . -type f -name "*.sh" -exec shellcheck {} \\;
shellcheck:
stage: lint
image: koalaman/shellcheck-alpine
script:
- find . -type f -name "*.sh" -exec shellcheck {} \\;
allow_failure: false
#!/bin/bash
# 行全体の警告を無効化
# shellcheck disable=SC2086
for file in $(ls -la); do
echo "$file"
done
# スクリプト全体で無効化
# shellcheck disable=SC1091,SC2119
# 複数の警告を無効化(形式は異なる)
command_that_fails() {
# shellcheck disable=SC2015
[ -f "$1" ] && echo "found" || echo "not found"
}
# sourceディレクティブの特定のチェックを無効化
# shellcheck source=./helper.sh
source helper.sh
# 問題
for i in $list; do done
# 解決策
for i in $list; do done # $listが既にクォートされている場合、または
for i in "${list[@]}"; do done # listが配列の場合
# 問題
some_command
if [ $? -eq 0 ]; then
echo "success"
fi
# 解決策
if some_command; then
echo "success"
fi
# 問題
[ -f "$file" ] && echo "exists" || echo "not found"
# 解決策 - より明確な意図
if [ -f "$file" ]; then
echo "exists"
else
echo "not found"
fi
# 問題
echo 'Variable value: $VAR'
# 解決策
echo "Variable value: $VAR"
# 問題
ps aux | grep -v grep | grep myprocess
# 解決策
pgrep -f myprocess
#!/bin/bash
# シーケンシャルチェック
for script in *.sh; do
shellcheck "$script"
done
# 並列チェック(より速い)
find . -name "*.sh" -print0 | \
xargs -0 -P 4 -n 1 shellcheck
#!/bin/bash
CACHE_DIR=".shellcheck_cache"
mkdir -p "$CACHE_DIR"
check_script() {
local script="$1"
local hash
local cache_file
hash=$(sha256sum "$script" | cut -d' ' -f1)
cache_file="$CACHE_DIR/$hash"
if [[ ! -f "$cache_file" ]]; then
if shellcheck "$script" > "$cache_file" 2>&1; then
touch "$cache_file.ok"
else
return 1
fi
fi
[[ -f "$cache_file.ok" ]]
}
find . -name "*.sh" | while read -r script; do
check_script "$script" || exit 1
done
shellcheck script.sh
# 出力:
# script.sh:1:3: warning: foo is referenced but not assigned. [SC2154]
shellcheck --format=gcc script.sh
# 出力:
# script.sh:1:3: warning: foo is referenced but not assigned.
shellcheck --format=json script.sh
# 出力:
# [{"file": "script.sh", "line": 1, "column": 3, "level": "warning", "code": 2154, "message": "..."}]
shellcheck --format=quiet script.sh
# 問題が見つかった場合は非ゼロを返す、それ以外は出力なし
--enable=allを使用还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Migrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.
中文简介正在准备中。当前显示原文说明。
ハイブリッドモード、段階的コンポーネント書き換え、依存性注入更新を使用してAngularJSからAngularへ移行します。AngularJSアプリケーションのアップグレード、フレームワーク移行の計画、またはレガシーAngularコードのモダナイゼーション時に使用します。
中文简介正在准备中。当前显示原文说明。
開発者を喜ばせる直感的でスケーラブルで保守可能なAPIを構築するために、RESTとGraphQL APIの設計原則をマスターします。新しいAPIの設計、API仕様のレビュー、またはAPI設計標準の確立時に使用してください。
中文简介正在准备中。当前显示原文说明。
Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.
中文简介正在准备中。当前显示原文说明。
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use when architecting complex backend systems or refactoring existing applications for better maintainability.
中文简介正在准备中。当前显示原文说明。
クリーンアーキテクチャ、ヘキサゴナルアーキテクチャ、ドメイン駆動設計を含む実証済みのバックエンドアーキテクチャパターンを実装します。複雑なバックエンドシステムの設計や、保守性向上のための既存アプリケーションのリファクタリング時に使用します。
中文简介正在准备中。当前显示原文说明。