rbtr-lang-bash 2026.7.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rbtr_lang_bash/__init__.py +1 -0
- rbtr_lang_bash/bash.scm +34 -0
- rbtr_lang_bash/plugin.py +64 -0
- rbtr_lang_bash/py.typed +0 -0
- rbtr_lang_bash/tests/__init__.py +0 -0
- rbtr_lang_bash/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +4 -0
- rbtr_lang_bash/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +254 -0
- rbtr_lang_bash/tests/cases_docstrings.py +112 -0
- rbtr_lang_bash/tests/cases_extraction.py +138 -0
- rbtr_lang_bash/tests/samples/bash/bash.sh +34 -0
- rbtr_lang_bash/tests/samples/bash/lib/colours.sh +4 -0
- rbtr_lang_bash/tests/test_docstrings.py +50 -0
- rbtr_lang_bash/tests/test_extraction.py +54 -0
- rbtr_lang_bash/tests/test_samples.py +82 -0
- rbtr_lang_bash-2026.7.0.dev0.dist-info/METADATA +8 -0
- rbtr_lang_bash-2026.7.0.dev0.dist-info/RECORD +18 -0
- rbtr_lang_bash-2026.7.0.dev0.dist-info/WHEEL +4 -0
- rbtr_lang_bash-2026.7.0.dev0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Bash language plugin package."""
|
rbtr_lang_bash/bash.scm
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
; Top-level comments (Bash: single `comment` type).
|
|
2
|
+
(comment) @comment
|
|
3
|
+
|
|
4
|
+
(function_definition
|
|
5
|
+
name: (word) @_fn_name) @function
|
|
6
|
+
|
|
7
|
+
(command
|
|
8
|
+
name: (command_name
|
|
9
|
+
(word) @_cmd)
|
|
10
|
+
.
|
|
11
|
+
(word) @_import_module
|
|
12
|
+
(#eq? @_cmd "source")) @import
|
|
13
|
+
|
|
14
|
+
(command
|
|
15
|
+
name: (command_name
|
|
16
|
+
(word) @_cmd)
|
|
17
|
+
.
|
|
18
|
+
(word) @_import_module
|
|
19
|
+
(#eq? @_cmd ".")) @import
|
|
20
|
+
|
|
21
|
+
(program
|
|
22
|
+
(variable_assignment
|
|
23
|
+
name: (variable_name) @_var_name) @variable)
|
|
24
|
+
|
|
25
|
+
(program
|
|
26
|
+
(declaration_command
|
|
27
|
+
(variable_assignment
|
|
28
|
+
name: (variable_name) @_var_name)) @variable)
|
|
29
|
+
|
|
30
|
+
(command
|
|
31
|
+
name: (command_name (word) @_cmd)
|
|
32
|
+
argument: (concatenation (word) @_var_name)
|
|
33
|
+
(#eq? @_cmd "alias")
|
|
34
|
+
(#match? @_var_name "=")) @variable
|
rbtr_lang_bash/plugin.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Bash language plugin.
|
|
2
|
+
|
|
3
|
+
Provides function extraction only — Bash has no import system,
|
|
4
|
+
class system, or module structure.
|
|
5
|
+
|
|
6
|
+
Extracted chunks::
|
|
7
|
+
|
|
8
|
+
deploy() { echo deploying; } → function "deploy", scope ""
|
|
9
|
+
function setup { ... } → function "setup", scope ""
|
|
10
|
+
alias ll="ls -l" → variable "ll", scope ""
|
|
11
|
+
|
|
12
|
+
No classes or methods are extracted.
|
|
13
|
+
|
|
14
|
+
An `alias` name parses as one `word` fused with its `=` (`ll=`), which no
|
|
15
|
+
query can split. The `name_extractor` strips the trailing `=`; no other
|
|
16
|
+
bash name ends in one.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
22
|
+
|
|
23
|
+
from rbtr.languages.registration import (
|
|
24
|
+
LanguageRegistration,
|
|
25
|
+
NameResolver,
|
|
26
|
+
QueryExtraction,
|
|
27
|
+
load_query,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from tree_sitter import Node
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# ── Query ────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# ── Plugin ───────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
bash = LanguageRegistration(
|
|
41
|
+
id="bash",
|
|
42
|
+
extensions=frozenset({".sh", ".bash", ".zsh"}),
|
|
43
|
+
filenames=frozenset(
|
|
44
|
+
{
|
|
45
|
+
"Bashrc",
|
|
46
|
+
".bashrc",
|
|
47
|
+
".bash_profile",
|
|
48
|
+
".zshrc",
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
grammar_module="tree_sitter_bash",
|
|
52
|
+
extraction=QueryExtraction(
|
|
53
|
+
query=load_query(__package__, "bash"),
|
|
54
|
+
),
|
|
55
|
+
extraction_serial=4,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@bash.name_extractor
|
|
60
|
+
def _strip_alias_eq(
|
|
61
|
+
resolver: NameResolver, capture_name: str, node: Node, captures: dict[str, list[Node]]
|
|
62
|
+
) -> str:
|
|
63
|
+
"""Default name, with the `=` the grammar fuses onto an alias removed."""
|
|
64
|
+
return resolver(capture_name, node, captures).rstrip("=")
|
rbtr_lang_bash/py.typed
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "d39ad69c069b6285",
|
|
4
|
+
"blob_sha": "sha1",
|
|
5
|
+
"file_path": "bash.sh",
|
|
6
|
+
"kind": "comment",
|
|
7
|
+
"name": "<anonymous>",
|
|
8
|
+
"scope": "",
|
|
9
|
+
"language": "bash",
|
|
10
|
+
"content": "#!/usr/bin/env bash\n# Greeter — print greetings for named recipients.\n#\n# Bash has no classes or methods; the plugin extracts functions,\n# top-level variable assignments (including export/declare/readonly),\n# aliases, and source/. imports.",
|
|
11
|
+
"line_start": 1,
|
|
12
|
+
"line_end": 6,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "ca906d45e5c8e1da",
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "bash.sh",
|
|
24
|
+
"kind": "import",
|
|
25
|
+
"name": "source ./lib/colours.sh",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "bash",
|
|
28
|
+
"content": "source ./lib/colours.sh",
|
|
29
|
+
"line_start": 8,
|
|
30
|
+
"line_end": 8,
|
|
31
|
+
"metadata": {
|
|
32
|
+
"module": "./lib/colours.sh",
|
|
33
|
+
"names": "",
|
|
34
|
+
"dots": "",
|
|
35
|
+
"language_hint": ""
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "19b95c899d99e1f5",
|
|
40
|
+
"blob_sha": "sha1",
|
|
41
|
+
"file_path": "bash.sh",
|
|
42
|
+
"kind": "import",
|
|
43
|
+
"name": ". /etc/greeter.conf",
|
|
44
|
+
"scope": "",
|
|
45
|
+
"language": "bash",
|
|
46
|
+
"content": ". /etc/greeter.conf",
|
|
47
|
+
"line_start": 9,
|
|
48
|
+
"line_end": 9,
|
|
49
|
+
"metadata": {
|
|
50
|
+
"module": "/etc/greeter.conf",
|
|
51
|
+
"names": "",
|
|
52
|
+
"dots": "",
|
|
53
|
+
"language_hint": ""
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "dbf8d8210a1c9118",
|
|
58
|
+
"blob_sha": "sha1",
|
|
59
|
+
"file_path": "bash.sh",
|
|
60
|
+
"kind": "variable",
|
|
61
|
+
"name": "DEFAULT_GREETING",
|
|
62
|
+
"scope": "",
|
|
63
|
+
"language": "bash",
|
|
64
|
+
"content": "DEFAULT_GREETING=\"Hello\"",
|
|
65
|
+
"line_start": 11,
|
|
66
|
+
"line_end": 11,
|
|
67
|
+
"metadata": {
|
|
68
|
+
"module": "",
|
|
69
|
+
"names": "",
|
|
70
|
+
"dots": "",
|
|
71
|
+
"language_hint": ""
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "610d295f73434926",
|
|
76
|
+
"blob_sha": "sha1",
|
|
77
|
+
"file_path": "bash.sh",
|
|
78
|
+
"kind": "comment",
|
|
79
|
+
"name": "<anonymous>",
|
|
80
|
+
"scope": "",
|
|
81
|
+
"language": "bash",
|
|
82
|
+
"content": "# trailing comment: its own chunk",
|
|
83
|
+
"line_start": 11,
|
|
84
|
+
"line_end": 11,
|
|
85
|
+
"metadata": {
|
|
86
|
+
"module": "",
|
|
87
|
+
"names": "",
|
|
88
|
+
"dots": "",
|
|
89
|
+
"language_hint": ""
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "aa482bbea0e16ce3",
|
|
94
|
+
"blob_sha": "sha1",
|
|
95
|
+
"file_path": "bash.sh",
|
|
96
|
+
"kind": "variable",
|
|
97
|
+
"name": "LOCALE",
|
|
98
|
+
"scope": "",
|
|
99
|
+
"language": "bash",
|
|
100
|
+
"content": "# Standalone note, separated by blank lines from any definition.\n# Second line of the same block.\nLOCALE=\"${LANG:-en}\"",
|
|
101
|
+
"line_start": 13,
|
|
102
|
+
"line_end": 15,
|
|
103
|
+
"metadata": {
|
|
104
|
+
"module": "",
|
|
105
|
+
"names": "",
|
|
106
|
+
"dots": "",
|
|
107
|
+
"language_hint": ""
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"id": "fd2d219510e272c5",
|
|
112
|
+
"blob_sha": "sha1",
|
|
113
|
+
"file_path": "bash.sh",
|
|
114
|
+
"kind": "variable",
|
|
115
|
+
"name": "API_URL",
|
|
116
|
+
"scope": "",
|
|
117
|
+
"language": "bash",
|
|
118
|
+
"content": "export API_URL=\"https://example.com\"",
|
|
119
|
+
"line_start": 16,
|
|
120
|
+
"line_end": 16,
|
|
121
|
+
"metadata": {
|
|
122
|
+
"module": "",
|
|
123
|
+
"names": "",
|
|
124
|
+
"dots": "",
|
|
125
|
+
"language_hint": ""
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"id": "28c8e045bbc3c2fc",
|
|
130
|
+
"blob_sha": "sha1",
|
|
131
|
+
"file_path": "bash.sh",
|
|
132
|
+
"kind": "variable",
|
|
133
|
+
"name": "MAX_RETRIES",
|
|
134
|
+
"scope": "",
|
|
135
|
+
"language": "bash",
|
|
136
|
+
"content": "readonly MAX_RETRIES=3",
|
|
137
|
+
"line_start": 17,
|
|
138
|
+
"line_end": 17,
|
|
139
|
+
"metadata": {
|
|
140
|
+
"module": "",
|
|
141
|
+
"names": "",
|
|
142
|
+
"dots": "",
|
|
143
|
+
"language_hint": ""
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"id": "46c076160d937a23",
|
|
148
|
+
"blob_sha": "sha1",
|
|
149
|
+
"file_path": "bash.sh",
|
|
150
|
+
"kind": "variable",
|
|
151
|
+
"name": "COUNTER",
|
|
152
|
+
"scope": "",
|
|
153
|
+
"language": "bash",
|
|
154
|
+
"content": "declare -i COUNTER=0",
|
|
155
|
+
"line_start": 18,
|
|
156
|
+
"line_end": 18,
|
|
157
|
+
"metadata": {
|
|
158
|
+
"module": "",
|
|
159
|
+
"names": "",
|
|
160
|
+
"dots": "",
|
|
161
|
+
"language_hint": ""
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "9be9ed61fbcec8cf",
|
|
166
|
+
"blob_sha": "sha1",
|
|
167
|
+
"file_path": "bash.sh",
|
|
168
|
+
"kind": "variable",
|
|
169
|
+
"name": "greet",
|
|
170
|
+
"scope": "",
|
|
171
|
+
"language": "bash",
|
|
172
|
+
"content": "alias greet=\"format_greeting\"",
|
|
173
|
+
"line_start": 19,
|
|
174
|
+
"line_end": 19,
|
|
175
|
+
"metadata": {
|
|
176
|
+
"module": "",
|
|
177
|
+
"names": "",
|
|
178
|
+
"dots": "",
|
|
179
|
+
"language_hint": ""
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"id": "1c05f30beda1010c",
|
|
184
|
+
"blob_sha": "sha1",
|
|
185
|
+
"file_path": "bash.sh",
|
|
186
|
+
"kind": "function",
|
|
187
|
+
"name": "format_greeting",
|
|
188
|
+
"scope": "",
|
|
189
|
+
"language": "bash",
|
|
190
|
+
"content": "# Format a greeting for a single recipient.\nformat_greeting() {\n local name=\"$1\"\n echo \"${DEFAULT_GREETING}, ${name} (${LOCALE})\"\n}",
|
|
191
|
+
"line_start": 21,
|
|
192
|
+
"line_end": 25,
|
|
193
|
+
"metadata": {
|
|
194
|
+
"module": "",
|
|
195
|
+
"names": "",
|
|
196
|
+
"dots": "",
|
|
197
|
+
"language_hint": ""
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"id": "f6bed6e22b836142",
|
|
202
|
+
"blob_sha": "sha1",
|
|
203
|
+
"file_path": "bash.sh",
|
|
204
|
+
"kind": "function",
|
|
205
|
+
"name": "greet_all",
|
|
206
|
+
"scope": "",
|
|
207
|
+
"language": "bash",
|
|
208
|
+
"content": "# Greet every argument in turn.\ngreet_all() {\n for name in \"$@\"; do\n format_greeting \"$name\"\n done\n}",
|
|
209
|
+
"line_start": 27,
|
|
210
|
+
"line_end": 32,
|
|
211
|
+
"metadata": {
|
|
212
|
+
"module": "",
|
|
213
|
+
"names": "",
|
|
214
|
+
"dots": "",
|
|
215
|
+
"language_hint": ""
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"id": "c01f22efbc31cfad",
|
|
220
|
+
"blob_sha": "sha1",
|
|
221
|
+
"file_path": "lib/colours.sh",
|
|
222
|
+
"kind": "variable",
|
|
223
|
+
"name": "RED",
|
|
224
|
+
"scope": "",
|
|
225
|
+
"language": "bash",
|
|
226
|
+
"content": "#!/usr/bin/env bash\n# Terminal colour codes.\nRED='\\033[0;31m'",
|
|
227
|
+
"line_start": 1,
|
|
228
|
+
"line_end": 3,
|
|
229
|
+
"metadata": {
|
|
230
|
+
"module": "",
|
|
231
|
+
"names": "",
|
|
232
|
+
"dots": "",
|
|
233
|
+
"language_hint": ""
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"id": "472aaed6fa440473",
|
|
238
|
+
"blob_sha": "sha1",
|
|
239
|
+
"file_path": "lib/colours.sh",
|
|
240
|
+
"kind": "variable",
|
|
241
|
+
"name": "RESET",
|
|
242
|
+
"scope": "",
|
|
243
|
+
"language": "bash",
|
|
244
|
+
"content": "RESET='\\033[0m'",
|
|
245
|
+
"line_start": 4,
|
|
246
|
+
"line_end": 4,
|
|
247
|
+
"metadata": {
|
|
248
|
+
"module": "",
|
|
249
|
+
"names": "",
|
|
250
|
+
"dots": "",
|
|
251
|
+
"language_hint": ""
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Bash docstring-extraction test cases.
|
|
2
|
+
|
|
3
|
+
tree-sitter-bash uses a single `comment` node for any `#` line. Function
|
|
4
|
+
docs are a `#` comment run directly above the definition; a shebang
|
|
5
|
+
(`#!/bin/bash`) attaches to the first function only when no blank line
|
|
6
|
+
separates them.
|
|
7
|
+
|
|
8
|
+
Each `@case` returns `(lang, source, symbol_name, snippet)`; see
|
|
9
|
+
`test_docstrings.py` for the assertion direction per tag.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from pytest_cases import case
|
|
15
|
+
|
|
16
|
+
type DocstringCase = tuple[str, str, str, str]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@case(tags=["documented", "canonical", "exterior_doc"])
|
|
20
|
+
def case_bash_hash_doc_on_function() -> DocstringCase:
|
|
21
|
+
"""Canonical `#` comment above a shell function."""
|
|
22
|
+
src = """\
|
|
23
|
+
# Greet the user.
|
|
24
|
+
greet() {
|
|
25
|
+
echo hello
|
|
26
|
+
}
|
|
27
|
+
"""
|
|
28
|
+
return "bash", src, "greet", "Greet the user"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@case(tags=["documented", "canonical", "exterior_doc"])
|
|
32
|
+
def case_bash_multi_line_hash_doc() -> DocstringCase:
|
|
33
|
+
"""Multi-line `#` comment run."""
|
|
34
|
+
src = """\
|
|
35
|
+
# Greet the user.
|
|
36
|
+
#
|
|
37
|
+
# Reads the name from $1.
|
|
38
|
+
greet() {
|
|
39
|
+
echo hi $1
|
|
40
|
+
}
|
|
41
|
+
"""
|
|
42
|
+
return "bash", src, "greet", "Reads the name from"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@case(tags=["documented", "edge_case", "exterior_doc"])
|
|
46
|
+
def case_bash_shebang_attached_to_first_function() -> DocstringCase:
|
|
47
|
+
"""When a function follows the shebang with no blank line,
|
|
48
|
+
the shebang attaches — an honest consequence of the
|
|
49
|
+
flexible attachment policy. Recording this as a case so
|
|
50
|
+
any future tightening does not regress silently.
|
|
51
|
+
"""
|
|
52
|
+
src = """\
|
|
53
|
+
#!/bin/bash
|
|
54
|
+
# Entry point.
|
|
55
|
+
main() {
|
|
56
|
+
echo hi
|
|
57
|
+
}
|
|
58
|
+
"""
|
|
59
|
+
return "bash", src, "main", "#!/bin/bash"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@case(tags=["documented", "unconventional", "exterior_doc"])
|
|
63
|
+
def case_bash_comment_with_script_style_heading() -> DocstringCase:
|
|
64
|
+
"""Heading-like comment above a function attaches."""
|
|
65
|
+
src = """\
|
|
66
|
+
# ==== helpers ====
|
|
67
|
+
# Trim whitespace from $1.
|
|
68
|
+
trim() {
|
|
69
|
+
echo "$1"
|
|
70
|
+
}
|
|
71
|
+
"""
|
|
72
|
+
return "bash", src, "trim", "Trim whitespace"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@case(tags=["undocumented", "no_docs"])
|
|
76
|
+
def case_bash_fn_without_doc() -> DocstringCase:
|
|
77
|
+
"""Undocumented shell function."""
|
|
78
|
+
src = """\
|
|
79
|
+
bare() {
|
|
80
|
+
echo hi
|
|
81
|
+
}
|
|
82
|
+
"""
|
|
83
|
+
return "bash", src, "bare", "PHANTOM_DOC_TEXT_SHOULD_NEVER_APPEAR"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@case(tags=["undocumented", "boundary_not_attached"])
|
|
87
|
+
def case_bash_doc_detached_by_blank_line() -> DocstringCase:
|
|
88
|
+
"""Blank line breaks attachment."""
|
|
89
|
+
src = """\
|
|
90
|
+
# Orphan.
|
|
91
|
+
|
|
92
|
+
later() {
|
|
93
|
+
echo hi
|
|
94
|
+
}
|
|
95
|
+
"""
|
|
96
|
+
return "bash", src, "later", "Orphan"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@case(tags=["undocumented", "invalid"])
|
|
100
|
+
def case_bash_shebang_separated_by_blank_line() -> DocstringCase:
|
|
101
|
+
"""When a blank line separates the shebang from the first
|
|
102
|
+
function, the shebang stays detached — the same
|
|
103
|
+
blank-line rule applies uniformly to all comment kinds.
|
|
104
|
+
"""
|
|
105
|
+
src = """\
|
|
106
|
+
#!/bin/bash
|
|
107
|
+
|
|
108
|
+
main() {
|
|
109
|
+
echo hi
|
|
110
|
+
}
|
|
111
|
+
"""
|
|
112
|
+
return "bash", src, "main", "#!/bin/bash"
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Bash extraction test cases.
|
|
2
|
+
|
|
3
|
+
Each `@case` returns test data consumed by `test_extraction.py` via
|
|
4
|
+
`pytest-cases`.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import case
|
|
10
|
+
|
|
11
|
+
type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
|
|
12
|
+
type MixedCase = tuple[str, str, set[str], list[tuple[str, str]]]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@case(tags=["symbol"])
|
|
16
|
+
def case_bash_function_keyword() -> SymbolCase:
|
|
17
|
+
"""function deploy { ... }."""
|
|
18
|
+
src = """\
|
|
19
|
+
function deploy {
|
|
20
|
+
echo deploying
|
|
21
|
+
}
|
|
22
|
+
"""
|
|
23
|
+
return "bash", src, [("function", "deploy", "")]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@case(tags=["symbol"])
|
|
27
|
+
def case_bash_function_keyword_parens() -> SymbolCase:
|
|
28
|
+
"""function deploy() { ... }."""
|
|
29
|
+
src = """\
|
|
30
|
+
function deploy() {
|
|
31
|
+
echo deploying
|
|
32
|
+
}
|
|
33
|
+
"""
|
|
34
|
+
return "bash", src, [("function", "deploy", "")]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@case(tags=["symbol"])
|
|
38
|
+
def case_bash_function_posix() -> SymbolCase:
|
|
39
|
+
"""deploy() { ... } — POSIX syntax."""
|
|
40
|
+
src = """\
|
|
41
|
+
deploy() {
|
|
42
|
+
echo deploying
|
|
43
|
+
}
|
|
44
|
+
"""
|
|
45
|
+
return "bash", src, [("function", "deploy", "")]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@case(tags=["symbol"])
|
|
49
|
+
def case_bash_multiple_functions() -> SymbolCase:
|
|
50
|
+
"""Multiple shell functions."""
|
|
51
|
+
src = """\
|
|
52
|
+
function setup {
|
|
53
|
+
echo setup
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function teardown {
|
|
57
|
+
echo teardown
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
run() {
|
|
61
|
+
echo run
|
|
62
|
+
}
|
|
63
|
+
"""
|
|
64
|
+
return (
|
|
65
|
+
"bash",
|
|
66
|
+
src,
|
|
67
|
+
[
|
|
68
|
+
("function", "setup", ""),
|
|
69
|
+
("function", "teardown", ""),
|
|
70
|
+
("function", "run", ""),
|
|
71
|
+
],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@case(tags=["symbol"])
|
|
76
|
+
def case_bash_alias() -> SymbolCase:
|
|
77
|
+
"""An alias is a variable, named without the `=` the grammar fuses on."""
|
|
78
|
+
src = """\
|
|
79
|
+
alias ll="ls -l"
|
|
80
|
+
"""
|
|
81
|
+
return "bash", src, [("variable", "ll", "")]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@case(tags=["symbol"])
|
|
85
|
+
def case_bash_function_local_vars() -> SymbolCase:
|
|
86
|
+
"""Function with local variables."""
|
|
87
|
+
src = """\
|
|
88
|
+
setup() {
|
|
89
|
+
local dir="/tmp"
|
|
90
|
+
mkdir -p "$dir"
|
|
91
|
+
}
|
|
92
|
+
"""
|
|
93
|
+
return "bash", src, [("function", "setup", "")]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@case(tags=["symbol"])
|
|
97
|
+
def case_bash_function_conditionals() -> SymbolCase:
|
|
98
|
+
"""Function with conditionals."""
|
|
99
|
+
src = """\
|
|
100
|
+
check() {
|
|
101
|
+
if [ -f /tmp/x ]; then
|
|
102
|
+
echo yes
|
|
103
|
+
fi
|
|
104
|
+
}
|
|
105
|
+
"""
|
|
106
|
+
return "bash", src, [("function", "check", "")]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ── Mixed ───────────────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@case(tags=["symbol"])
|
|
113
|
+
def case_bash_assignment() -> SymbolCase:
|
|
114
|
+
"""Top-level variable assignment."""
|
|
115
|
+
return "bash", "MAX=100\n", [("variable", "MAX", "")]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@case(tags=["mixed"])
|
|
119
|
+
def case_bash_full_script() -> MixedCase:
|
|
120
|
+
"""Realistic shell script with doc comments on every
|
|
121
|
+
function. Expected-kinds tuple pins symbol extraction;
|
|
122
|
+
content invariants are in `test_docstrings.py`.
|
|
123
|
+
"""
|
|
124
|
+
src = """\
|
|
125
|
+
#!/bin/bash
|
|
126
|
+
|
|
127
|
+
# Deploy the current build to the given environment.
|
|
128
|
+
deploy() {
|
|
129
|
+
local env="$1"
|
|
130
|
+
echo "deploying to $env"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# Roll back the last deploy.
|
|
134
|
+
rollback() {
|
|
135
|
+
echo "rolling back"
|
|
136
|
+
}
|
|
137
|
+
"""
|
|
138
|
+
return "bash", src, {"function"}, []
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Greeter — print greetings for named recipients.
|
|
3
|
+
#
|
|
4
|
+
# Bash has no classes or methods; the plugin extracts functions,
|
|
5
|
+
# top-level variable assignments (including export/declare/readonly),
|
|
6
|
+
# aliases, and source/. imports.
|
|
7
|
+
|
|
8
|
+
source ./lib/colours.sh
|
|
9
|
+
. /etc/greeter.conf
|
|
10
|
+
|
|
11
|
+
DEFAULT_GREETING="Hello" # trailing comment: its own chunk
|
|
12
|
+
|
|
13
|
+
# Standalone note, separated by blank lines from any definition.
|
|
14
|
+
# Second line of the same block.
|
|
15
|
+
LOCALE="${LANG:-en}"
|
|
16
|
+
export API_URL="https://example.com"
|
|
17
|
+
readonly MAX_RETRIES=3
|
|
18
|
+
declare -i COUNTER=0
|
|
19
|
+
alias greet="format_greeting"
|
|
20
|
+
|
|
21
|
+
# Format a greeting for a single recipient.
|
|
22
|
+
format_greeting() {
|
|
23
|
+
local name="$1"
|
|
24
|
+
echo "${DEFAULT_GREETING}, ${name} (${LOCALE})"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Greet every argument in turn.
|
|
28
|
+
greet_all() {
|
|
29
|
+
for name in "$@"; do
|
|
30
|
+
format_greeting "$name"
|
|
31
|
+
done
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
greet_all "$@"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Bash docstring-extraction tests.
|
|
2
|
+
|
|
3
|
+
Bash docs are exterior (a leading `#` comment run); there are no
|
|
4
|
+
interior-doc cases, so only the documented / undocumented / exterior-doc
|
|
5
|
+
checks apply.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from pytest_cases import parametrize_with_cases
|
|
11
|
+
|
|
12
|
+
from rbtr.git import FileEntry
|
|
13
|
+
from rbtr.languages.extract import extract_file
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@parametrize_with_cases(
|
|
17
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="documented"
|
|
18
|
+
)
|
|
19
|
+
def test_documented_chunk_includes_doc_text(
|
|
20
|
+
lang: str, source: str, name: str, snippet: str
|
|
21
|
+
) -> None:
|
|
22
|
+
"""By default the chunk content carries the symbol's docs."""
|
|
23
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
24
|
+
chunk = next(c for c in chunks if c.name == name)
|
|
25
|
+
assert snippet in chunk.content, (
|
|
26
|
+
f"expected {snippet!r} in {lang}.{name} content; got:\n{chunk.content!r}"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@parametrize_with_cases(
|
|
31
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="undocumented"
|
|
32
|
+
)
|
|
33
|
+
def test_no_phantom_documentation(lang: str, source: str, name: str, snippet: str) -> None:
|
|
34
|
+
"""Symbols without documentation do not gain any in content."""
|
|
35
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
36
|
+
chunk = next(c for c in chunks if c.name == name)
|
|
37
|
+
assert snippet not in chunk.content, (
|
|
38
|
+
f"unexpected {snippet!r} in {lang}.{name} content; got:\n{chunk.content!r}"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@parametrize_with_cases(
|
|
43
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="exterior_doc"
|
|
44
|
+
)
|
|
45
|
+
def test_leading_doc_folds_into_symbol(lang: str, source: str, name: str, snippet: str) -> None:
|
|
46
|
+
"""A leading comment block folds into its symbol's chunk content."""
|
|
47
|
+
chunk = next(
|
|
48
|
+
c for c in extract_file(FileEntry("input", "sha1", source.encode()), lang) if c.name == name
|
|
49
|
+
)
|
|
50
|
+
assert snippet in chunk.content
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Bash extraction tests.
|
|
2
|
+
|
|
3
|
+
Construct/mixed cases (`cases_extraction.py`) drive the shared checks;
|
|
4
|
+
the function at the end pins bash's source/. import behaviour.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import parametrize_with_cases
|
|
10
|
+
|
|
11
|
+
from rbtr.git import FileEntry
|
|
12
|
+
from rbtr.index.models import ChunkKind
|
|
13
|
+
from rbtr.languages.extract import extract_file
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
|
|
17
|
+
def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
|
|
18
|
+
"""Each expected (kind, name, scope) tuple appears in the output."""
|
|
19
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
20
|
+
symbols = [(c.kind, c.name, c.scope) for c in chunks]
|
|
21
|
+
for exp in expected:
|
|
22
|
+
assert exp in symbols, f"expected {exp} not found in {symbols}"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@parametrize_with_cases(
|
|
26
|
+
"lang, source, expected_kinds, expected_methods", cases=".cases_extraction", has_tag="mixed"
|
|
27
|
+
)
|
|
28
|
+
def test_extracts_all_expected_kinds(
|
|
29
|
+
lang: str,
|
|
30
|
+
source: str,
|
|
31
|
+
expected_kinds: set[str],
|
|
32
|
+
expected_methods: list[tuple[str, str]],
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Realistic source produces all expected chunk kinds and method scoping."""
|
|
35
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
36
|
+
kinds = {c.kind for c in chunks}
|
|
37
|
+
for kind in expected_kinds:
|
|
38
|
+
assert kind in kinds, f"expected kind {kind!r} not in {kinds}"
|
|
39
|
+
methods = [(c.name, c.scope) for c in chunks if c.kind == ChunkKind.METHOD]
|
|
40
|
+
for name, scope in expected_methods:
|
|
41
|
+
assert (name, scope) in methods, f"expected method ({name}, {scope}) not in {methods}"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_bash_source_and_dot_extracted_as_imports() -> None:
|
|
45
|
+
"""source/. commands are captured as imports."""
|
|
46
|
+
src = """\
|
|
47
|
+
source ./env.sh
|
|
48
|
+
. /etc/profile
|
|
49
|
+
"""
|
|
50
|
+
chunks = extract_file(FileEntry("input", "sha1", src.encode()), "bash")
|
|
51
|
+
imports = [c for c in chunks if c.kind == ChunkKind.IMPORT]
|
|
52
|
+
assert len(imports) == 2
|
|
53
|
+
modules = {c.metadata.module for c in imports}
|
|
54
|
+
assert modules == {"./env.sh", "/etc/profile"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Bash sample extraction: the `samples/bash/` project through the real pipeline.
|
|
2
|
+
|
|
3
|
+
The snapshots are the golden record of what bash extraction produces;
|
|
4
|
+
regenerate with `pytest --snapshot-update` after an intended change.
|
|
5
|
+
Engine-wide invariants (determinism, line numbers, syntax-error recovery)
|
|
6
|
+
are covered once in core, not re-run per language.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
from tree_sitter import Parser
|
|
16
|
+
|
|
17
|
+
from rbtr.git import FileEntry
|
|
18
|
+
from rbtr.index.models import Chunk, ChunkKind, Edge
|
|
19
|
+
from rbtr.languages.edges import build_resolution_map, infer_import_edges
|
|
20
|
+
from rbtr.languages.extract import extract_file
|
|
21
|
+
from rbtr.languages.manager import get_manager
|
|
22
|
+
from rbtr.testing import render_edges
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from syrupy.assertion import SnapshotAssertion
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def project() -> list[tuple[str, str]]:
|
|
30
|
+
"""The `(relative path, text)` files of the `samples/bash/` project."""
|
|
31
|
+
root = Path(__file__).parent / "samples" / "bash"
|
|
32
|
+
return [
|
|
33
|
+
(str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture
|
|
38
|
+
def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
|
|
39
|
+
"""Chunks from every project file, each via the real `extract_file`."""
|
|
40
|
+
manager = get_manager()
|
|
41
|
+
out: list[Chunk] = []
|
|
42
|
+
for path, text in project:
|
|
43
|
+
lang = manager.detect_language(path) or "bash"
|
|
44
|
+
out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
|
|
45
|
+
return out
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.fixture
|
|
49
|
+
def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
|
|
50
|
+
"""Import edges inferred across the project's files."""
|
|
51
|
+
manager = get_manager()
|
|
52
|
+
return infer_import_edges(chunks, {p for p, _ in project}, build_resolution_map(manager))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
|
|
56
|
+
"""The sample exercises bash's function, variable, and import chunks."""
|
|
57
|
+
kinds = {c.kind for c in chunks}
|
|
58
|
+
assert {
|
|
59
|
+
ChunkKind.FUNCTION,
|
|
60
|
+
ChunkKind.VARIABLE,
|
|
61
|
+
ChunkKind.IMPORT,
|
|
62
|
+
ChunkKind.COMMENT,
|
|
63
|
+
} <= kinds
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
|
|
67
|
+
"""Every project file is valid source — no tree-sitter ERROR/MISSING nodes."""
|
|
68
|
+
manager = get_manager()
|
|
69
|
+
for path, text in project:
|
|
70
|
+
grammar = manager.grammar(manager.detect_language(path) or "bash")
|
|
71
|
+
assert grammar is not None
|
|
72
|
+
assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
|
|
76
|
+
assert chunks == snapshot_json
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_edges_match_snapshot(
|
|
80
|
+
chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
|
|
81
|
+
) -> None:
|
|
82
|
+
assert render_edges(edges, chunks) == snapshot_json
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
rbtr_lang_bash/__init__.py,sha256=gIm_kg0Z44nZ487E3GfD3rnqm01SbLASuvJz9IMeURQ,36
|
|
2
|
+
rbtr_lang_bash/bash.scm,sha256=6z_T45eiyqNWD7VS42YV5zYeFGdT7TjdTuK40vjxp2Y,693
|
|
3
|
+
rbtr_lang_bash/plugin.py,sha256=ERZQS7oc8yeZxA9E-3lSY3bOh4RpjkjdUn4lnI7NeZM,1883
|
|
4
|
+
rbtr_lang_bash/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
rbtr_lang_bash/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
rbtr_lang_bash/tests/__snapshots__/test_samples/test_edges_match_snapshot.json,sha256=T2W5YHLPuKqYLJZBcLQRHRhK2yfSMn-JCkg_U8H3JSU,147
|
|
7
|
+
rbtr_lang_bash/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json,sha256=MVRWRbVx4xr3GG8WANzvamnrMP2eAikAWdAbpdPVYI4,5869
|
|
8
|
+
rbtr_lang_bash/tests/cases_docstrings.py,sha256=LGUR8vywW6-VZ_ggGJ_sU3cwWQFhLN1zTXwjYbYbS-E,2783
|
|
9
|
+
rbtr_lang_bash/tests/cases_extraction.py,sha256=-GFzlKNMemgTCcZ6GVal05iXd1p_ppW74q9uG-pAivs,2977
|
|
10
|
+
rbtr_lang_bash/tests/samples/bash/bash.sh,sha256=nNGz3bDP5J8WztL2CUOzUEZZmSofbm4NldwxRzatCSc,848
|
|
11
|
+
rbtr_lang_bash/tests/samples/bash/lib/colours.sh,sha256=IA4qng78MNbspyC9-_hv1OB0uLFDqn0h4z63JhWZI7Y,78
|
|
12
|
+
rbtr_lang_bash/tests/test_docstrings.py,sha256=h-KpUyUEa5mYldkaihXNMHrPcpvnfdMLbMqDIEEkKxo,1885
|
|
13
|
+
rbtr_lang_bash/tests/test_extraction.py,sha256=IM6nsVCwWLr90abB2pX8gIlfumo-e2U1MNVQRtTWZwQ,2089
|
|
14
|
+
rbtr_lang_bash/tests/test_samples.py,sha256=NopyYvZ-ii6HleZFbqXadw0LV406DOStB3uemYvRQCQ,2855
|
|
15
|
+
rbtr_lang_bash-2026.7.0.dev0.dist-info/WHEEL,sha256=CoDSoyhtC_eO_tlxRYzsTraPv1fPJRXFx91k6ISeAvA,81
|
|
16
|
+
rbtr_lang_bash-2026.7.0.dev0.dist-info/entry_points.txt,sha256=wBTXG4ULNpbpy6Ab2s3Xn3gkLpbxle5HHhP_57BwHx0,52
|
|
17
|
+
rbtr_lang_bash-2026.7.0.dev0.dist-info/METADATA,sha256=yQGc4z4irpb2YCfLiYjW6IzLsgbnI_r_mNOMMBNjaR0,220
|
|
18
|
+
rbtr_lang_bash-2026.7.0.dev0.dist-info/RECORD,,
|