Skip to content

Commit 389b1da

Browse files
committed
test
1 parent 340ff58 commit 389b1da

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

.clinerules

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# .clinerules
2+
3+
## Creating ShellScript files
4+
5+
When creating a ShellScript file:
6+
7+
- Always include `./LICENSE` content as a comment at the end of the file
8+
9+
- Minimize dependencies on other ShellScript files whenever possible
10+
- `./README.md` にて、「環境に独立してインストール可能」と明示しているためです
11+
- ただし`./define-options.sh`と`./lib/fun.sh`は例外です。これらには依存してかまいません
12+
- これも`./README.md`にて、依存性を明示しているためです
13+
- `./lib/fun.sh`の用法については`./lib/fun.sh`の内容、もしくは[公式のREADME.md](https://raw.githubusercontent.com/ssledz/bash-fun/refs/heads/master/README.md)を参照してください
14+
15+
- `./lib`ディレクトリにあるライブラリが使えそうな場合は、優先的に使用してください
16+
- `./lib/fun.sh`は特に便利です。関数型プログラミングを意識してください
17+
18+
- 1行目には`#!/bin/bash`を記述してください
19+
20+
- その次に説明文と使用例を記述してください。例えば次のようになります
21+
- 使用例は網羅的に記述してください。ただしユーザーへの読みやすさ・シンプルさも忘れないでください
22+
23+
```sh:bin/dust
24+
#!/bin/bash
25+
26+
# An alternative of `rm`, but 'mv' to dustbox instead.
27+
#
28+
# ```shell-session
29+
# $ ls README.md # Checking existence of readme
30+
# $ dust README.md
31+
# mv README.md /home/aiya000/.backup/dustbox/README.md_2025-02-25_13:45:37.md
32+
# ```
33+
34+
# 以下、実装
35+
# ...
36+
37+
# 以下、./LICENSEの内容
38+
# ...
39+
```
40+
41+
- 「`./sources`について」セクションと「`./bin`について」を読み、ShellScriptファイルの配置を適切に行ってください
42+
- また配置されるShellScriptは、それぞれのセクションのそのルールに従います
43+
44+
- ユーザーに設定の余地をできるだけ与えてください
45+
- できるだけ環境変数として設定できるようにしてください
46+
- その場合`./define-options.sh`に以下のような内容を追記してください
47+
48+
```sh:define-options.sh
49+
# ...
50+
51+
[[ -z $BASH_TOYS_{変数名} ]] && export BASH_TOYS_{変数名}={デフォルト値}
52+
53+
# ...
54+
```
55+
56+
- ShellScriptを作ったあとは、テストを作成してください
57+
- テストに関するルールは'Creating Test Files'セクションに続きます
58+
59+
- 変数名を使用する場合は`${varname}`ではなく、できるだけ`$varname`を使用してください
60+
- ただし、`$varname`が文字列として解釈される場合は`${varname}`を使用してください
61+
62+
- 関数を定義する場合は必ず`function`を使用してください
63+
- 関数でローカル変数を意図して変数を定義する場合は、`local`を使用してください
64+
- 関数を定義する場合は、できるだけグローバル変数(トップレベルの`$1`など)を使わず、引数を使用してください
65+
- 関数のモジュール結合度を弱くしてください
66+
- 関数のモジュール強度を強くしてください
67+
68+
- ヘルパー関数を定義することは構いませんが、あまり数を増やさないようにしてください
69+
- つまり、不要なノイズは増やさないでください
70+
71+
以下は不要なヘルパー関数の例です。
72+
73+
```sh
74+
function has_glow () {
75+
# 条件式に直接書いても、そこまで可読性は落ちない
76+
command -v glow >/dev/null 2>&1
77+
}
78+
79+
function is_disable_glow_opt () {
80+
# 同上
81+
[[ $1 == '--disable-glow' ]]
82+
}
83+
```
84+
85+
逆に、以下は適切なヘルパー関数です。
86+
87+
```sh
88+
# Show help and exit
89+
function show_help () {
90+
cat << EOF
91+
bash-toys-help - Show help for bash-toys commands
92+
93+
Usage:
94+
bash-toys-help [--disable-glow] COMMAND
95+
bash-toys-help --help
96+
97+
Options:
98+
--disable-glow Do not use glow for markdown rendering
99+
--help Show this help message
100+
EOF
101+
exit 0
102+
}
103+
```
104+
105+
- ヘルパー関数の名前は`snake_case`で記述してください
106+
- ただし後述の、`./sources`に配置される`function {機能名}`については例外です
107+
- 詳しくは「`./sources`について」セクションを参照してください
108+
109+
- `;`の前後にはスペースを入れてください
110+
- `[ ... ]`の代わりに`[[ ... ]]`を使用してください
111+
112+
- `--help`が渡された場合は、ヘルプを表示するように実装してください
113+
- その際に、ヘルプを表示する以外の処理は行わないようにしてください
114+
115+
- もし`""`の代わりに`''`が使える場合は、`''`を使用してください
116+
- もし`''`すら必要ない場合は、積極的に省いてください
117+
118+
- コメントを書くのは構いませんが、コードを見ればわかると感じるものは、書かないください
119+
- できるだけコード自体が説明を行うようにしてください
120+
121+
以下はコメントが不要な例です。
122+
`# Show help and exit`が不要です。
123+
124+
```sh
125+
# Show help and exit
126+
function show_help () {
127+
cat << EOF
128+
cmd - ...
129+
130+
Usage:
131+
...
132+
133+
Options:
134+
...
135+
EOF
136+
exit 0
137+
}
138+
```
139+
140+
- shellcheckによるチェックを行ってください。修正できる場合は修正してください
141+
142+
### `./sources`について
143+
144+
- サブプロセスとして実行できないShellScript(カレントシェルに影響を及ぼす関数)は`./source`に配置してください
145+
- その際は、ファイル名は`{機能名}.sh`とし、その内部に`function {機能名} () { ... }`として関数を定義してください
146+
- `{機能名}`は`kebab-case`で記述してください
147+
148+
例えば以下のようなシェルスクリプトです。
149+
150+
```sh:source/define-alias.sh
151+
#!/bin/bash
152+
153+
# Defines alias.
154+
# ```shell-session
155+
# $ define-alias ll 'ls -l'
156+
# ```
157+
158+
function define-alias () {
159+
local name=$1 detail=$2
160+
eval "alias $name='$detail'"
161+
}
162+
```
163+
164+
それ以外の、サブプロセスとして実行できるShellScriptは、`./bin`に配置してください
165+
166+
### `./bin`について
167+
168+
- サブプロセスとして実行できるShellScriptは`./bin`に配置してください
169+
- その際は、ファイル名は`{機能名}`とし、拡張子に`.sh`を付けないでください
170+
171+
その他、「`./sources`について」セクションを参照してください。
172+
173+
## Creating Test Files
174+
175+
Almost all ShellScript files (executables and source files) in this project include usage instructions and an example in the following format:
176+
177+
```sh:bin/dust
178+
#!/bin/bash
179+
180+
# An alternative of `rm`, but 'mv' to dustbox instead.
181+
#
182+
# ```shell-session
183+
# # Simple usage
184+
# $ ls README.md # Check existence of readme
185+
# $ dust README.md
186+
# mv README.md /home/aiya000/.backup/dustbox/README.md_2025-02-25_13:45:37.md
187+
# ```
188+
189+
# ...
190+
```
191+
192+
If such a `shell-session` block is present, convert its contents into the `.bats` format.
193+
Ensure that all conditions are comprehensively covered in the tests.
194+
195+
The test output directory is `./test`, with files written in the `bats` format and using the `.bats` extension.
196+
197+
## Git
198+
199+
- コミットメッセージは英語で記述してください
200+
201+
- コミットメッセージは`{動詞} ...`のように書いてください
202+
- 動詞の先頭文字は大文字にしてください。例えば`Add ...`・`Fix ...`などです
203+
204+
- `gh`コマンドが有効な場合は、コミットをする前に`$ gh issue list`でIssueリストを確認し、コミットにより解決される見込みのあるIssueがある場合は、コミットメッセージの3行目に`Closes #{Issue番号}`を追記してください
205+
206+
## その他、全てにおいて
207+
208+
- `$ curl {url} | sh`や`$ curl {url} | bash`をするときは、必ず先に`{url}`の内容を読み、それが実行されたときの危険性を理解してください
209+
- もし危険性が存在する場合は、作業をそこで中断し、私に判断を仰いでください
210+
211+
- OSパッケージのインストール(例えば`$ sudo apt install {packages}`・`$ brew install {packages}`)が必要な場合は、一度作業を中断し、私に判断を仰いでください

0 commit comments

Comments
 (0)