codecop 0.1.0__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.
Files changed (222) hide show
  1. codecop/__init__.py +7 -0
  2. codecop/access.py +140 -0
  3. codecop/access_postgres.py +284 -0
  4. codecop/advisor.py +1512 -0
  5. codecop/advisor_bench.py +493 -0
  6. codecop/advisor_ch.py +2080 -0
  7. codecop/advisor_view.py +381 -0
  8. codecop/advisors.py +184 -0
  9. codecop/agent.py +221 -0
  10. codecop/agentfacts.py +745 -0
  11. codecop/apply/__init__.py +327 -0
  12. codecop/apply/check.py +344 -0
  13. codecop/apply/cli.py +162 -0
  14. codecop/apply/clickhouse.py +379 -0
  15. codecop/apply/common.py +238 -0
  16. codecop/apply/html.py +264 -0
  17. codecop/apply/patch.py +213 -0
  18. codecop/apply/postgres.py +102 -0
  19. codecop/apply/trial.py +166 -0
  20. codecop/assemble.py +104 -0
  21. codecop/baseline.py +1043 -0
  22. codecop/bench.py +2464 -0
  23. codecop/blockers.py +935 -0
  24. codecop/budget.py +980 -0
  25. codecop/catalog_profile.py +525 -0
  26. codecop/changed.py +261 -0
  27. codecop/cicmd.py +1002 -0
  28. codecop/cli.py +5421 -0
  29. codecop/client.py +729 -0
  30. codecop/coverage.py +1067 -0
  31. codecop/coverage_reasons.py +116 -0
  32. codecop/crashlog.py +70 -0
  33. codecop/datagen.py +766 -0
  34. codecop/datagen_postgres.py +630 -0
  35. codecop/datagen_sqlite.py +323 -0
  36. codecop/dbcli.py +885 -0
  37. codecop/definitions.py +457 -0
  38. codecop/discover/__init__.py +702 -0
  39. codecop/discover/arms.py +160 -0
  40. codecop/discover/base.py +234 -0
  41. codecop/discover/dialect.py +296 -0
  42. codecop/discover/elixir.py +64 -0
  43. codecop/discover/engine_go.py +320 -0
  44. codecop/discover/go.py +1947 -0
  45. codecop/discover/java.py +1528 -0
  46. codecop/discover/loops.py +1671 -0
  47. codecop/discover/named_go.py +258 -0
  48. codecop/discover/origins.py +4565 -0
  49. codecop/discover/origins_ts.py +1584 -0
  50. codecop/discover/orm_django.py +2772 -0
  51. codecop/discover/orm_django_models.py +814 -0
  52. codecop/discover/orm_django_sql.py +662 -0
  53. codecop/discover/orm_ent.py +565 -0
  54. codecop/discover/orm_ex_ecto.py +2138 -0
  55. codecop/discover/orm_go.py +2134 -0
  56. codecop/discover/orm_go_bun.py +602 -0
  57. codecop/discover/orm_go_run.py +636 -0
  58. codecop/discover/orm_go_types.py +1082 -0
  59. codecop/discover/orm_java.py +1450 -0
  60. codecop/discover/orm_jdbi.py +743 -0
  61. codecop/discover/orm_jooq.py +806 -0
  62. codecop/discover/orm_jpa.py +1307 -0
  63. codecop/discover/orm_mybatis.py +730 -0
  64. codecop/discover/orm_py.py +557 -0
  65. codecop/discover/orm_py_peewee.py +1266 -0
  66. codecop/discover/orm_py_prisma.py +298 -0
  67. codecop/discover/orm_rb_activerecord.py +1906 -0
  68. codecop/discover/orm_rust.py +1248 -0
  69. codecop/discover/orm_rust_seaorm.py +734 -0
  70. codecop/discover/orm_sqlalchemy.py +2475 -0
  71. codecop/discover/orm_stats.py +307 -0
  72. codecop/discover/orm_tables.py +29 -0
  73. codecop/discover/orm_ts.py +503 -0
  74. codecop/discover/orm_ts_drizzle.py +697 -0
  75. codecop/discover/orm_ts_knex.py +1117 -0
  76. codecop/discover/orm_ts_kysely.py +861 -0
  77. codecop/discover/orm_ts_prisma.py +1045 -0
  78. codecop/discover/orm_ts_schema.py +169 -0
  79. codecop/discover/orm_ts_sequelize.py +1401 -0
  80. codecop/discover/orm_ts_typeorm.py +1067 -0
  81. codecop/discover/probes.py +323 -0
  82. codecop/discover/python.py +595 -0
  83. codecop/discover/ruby.py +793 -0
  84. codecop/discover/rust.py +2378 -0
  85. codecop/discover/schema.py +520 -0
  86. codecop/discover/schema_ent.py +145 -0
  87. codecop/discover/schema_ts.py +420 -0
  88. codecop/discover/tsresolve.py +257 -0
  89. codecop/discover/typescript.py +1728 -0
  90. codecop/discover/xml_mapper.py +526 -0
  91. codecop/engines/__init__.py +515 -0
  92. codecop/engines/base.py +498 -0
  93. codecop/engines/clickhouse.py +1558 -0
  94. codecop/engines/pg_ddl.py +444 -0
  95. codecop/engines/pg_hints.py +137 -0
  96. codecop/engines/postgres.py +1060 -0
  97. codecop/engines/sqlite.py +742 -0
  98. codecop/families/__init__.py +3 -0
  99. codecop/families/build.py +280 -0
  100. codecop/families/cli.py +177 -0
  101. codecop/families/coverage_hook.py +62 -0
  102. codecop/families/driver.py +221 -0
  103. codecop/families/goslice.py +229 -0
  104. codecop/families/goslice_tool/go.mod +3 -0
  105. codecop/families/goslice_tool/main.go +403 -0
  106. codecop/families/holes.py +451 -0
  107. codecop/families/images/Dockerfile.go +5 -0
  108. codecop/families/images/Dockerfile.python +4 -0
  109. codecop/families/images/Dockerfile.rust +4 -0
  110. codecop/families/isolate.py +171 -0
  111. codecop/families/locate.py +270 -0
  112. codecop/families/model.py +301 -0
  113. codecop/families/plangate.py +271 -0
  114. codecop/families/tagpatch.py +174 -0
  115. codecop/fidelity.py +671 -0
  116. codecop/fixgroups.py +130 -0
  117. codecop/formerly.py +91 -0
  118. codecop/grantscript.py +254 -0
  119. codecop/groupbench.py +1375 -0
  120. codecop/groups.py +594 -0
  121. codecop/groups_view.py +186 -0
  122. codecop/heat.py +1405 -0
  123. codecop/heatcli.py +219 -0
  124. codecop/joins.py +1749 -0
  125. codecop/joins_view.py +127 -0
  126. codecop/kinds/__init__.py +507 -0
  127. codecop/kinds/calls/__init__.py +501 -0
  128. codecop/kinds/calls/extract.py +1097 -0
  129. codecop/kinds/calls/harness.py +408 -0
  130. codecop/kinds/calls/measure.py +342 -0
  131. codecop/kinds/calls/rules.py +139 -0
  132. codecop/kinds/calls/runners/RunCalls.java +167 -0
  133. codecop/kinds/calls/runners/run_go.go +141 -0
  134. codecop/kinds/calls/runners/run_node.js +186 -0
  135. codecop/kinds/calls/runners/run_python.py +319 -0
  136. codecop/kinds/calls/runners/run_rust.rs +200 -0
  137. codecop/kinds/calls/standin.py +340 -0
  138. codecop/kinds/pipeline.py +288 -0
  139. codecop/kinds/regex/__init__.py +1167 -0
  140. codecop/kinds/regex/engines/RegexHarness.java +129 -0
  141. codecop/kinds/regex/engines/run_go.go +294 -0
  142. codecop/kinds/regex/engines/run_node.js +99 -0
  143. codecop/kinds/regex/engines/run_python.py +295 -0
  144. codecop/kinds/regex/engines/run_rust.rs +149 -0
  145. codecop/kinds/regex/extract.py +1438 -0
  146. codecop/kinds/regex/harness.py +235 -0
  147. codecop/kinds/regex/measure.py +270 -0
  148. codecop/kinds/regex/shapes.py +418 -0
  149. codecop/kinds/regex/syntax.py +1721 -0
  150. codecop/kinds/testkind.py +107 -0
  151. codecop/kinds/transaction/__init__.py +228 -0
  152. codecop/kinds/transaction/bind.py +355 -0
  153. codecop/kinds/transaction/measure.py +264 -0
  154. codecop/kinds/transaction/plan.py +462 -0
  155. codecop/kinds/transaction/rules.py +540 -0
  156. codecop/kinds/transaction/sandbox.py +94 -0
  157. codecop/kinds/transaction/scenarios.py +520 -0
  158. codecop/kinds/transaction/schedule.py +483 -0
  159. codecop/kinds/transaction/shapes.py +418 -0
  160. codecop/kinds/transaction/verify.py +293 -0
  161. codecop/live.py +237 -0
  162. codecop/loopbench.py +2071 -0
  163. codecop/loopschema.py +591 -0
  164. codecop/mcpserver.py +120 -0
  165. codecop/mechanism.py +214 -0
  166. codecop/members.py +200 -0
  167. codecop/multi.py +443 -0
  168. codecop/observed.py +1868 -0
  169. codecop/parts.py +102 -0
  170. codecop/patterns.py +830 -0
  171. codecop/patterns_view.py +559 -0
  172. codecop/plangate.py +242 -0
  173. codecop/profile.py +439 -0
  174. codecop/prompts/areas.md +19 -0
  175. codecop/prompts/observed_variants.md +20 -0
  176. codecop/prompts/profile.md +60 -0
  177. codecop/prompts/profile_postgres.md +68 -0
  178. codecop/prompts/profile_sizes.md +26 -0
  179. codecop/prompts/profile_sqlite.md +69 -0
  180. codecop/prompts/rank.md +84 -0
  181. codecop/prompts/rank_postgres.md +96 -0
  182. codecop/prompts/rank_sqlite.md +94 -0
  183. codecop/prompts/scenario_variants.md +20 -0
  184. codecop/rank.py +1473 -0
  185. codecop/realdb/__init__.py +688 -0
  186. codecop/realdb/clickhouse.py +1223 -0
  187. codecop/realdb/facts.py +815 -0
  188. codecop/realdb/locality.py +964 -0
  189. codecop/realdb/locks.py +355 -0
  190. codecop/realdb/match.py +531 -0
  191. codecop/realdb/postgres.py +643 -0
  192. codecop/realdb/ratios.py +77 -0
  193. codecop/realdb/sample.py +126 -0
  194. codecop/relations.py +227 -0
  195. codecop/report.py +1854 -0
  196. codecop/resources.py +332 -0
  197. codecop/resources_view.py +266 -0
  198. codecop/rules/entry_points.toml +1013 -0
  199. codecop/rules/sinks.toml +362 -0
  200. codecop/runsonce.py +8 -0
  201. codecop/sandboxschema.py +555 -0
  202. codecop/scenario_agent.py +172 -0
  203. codecop/scenario_bind.py +507 -0
  204. codecop/scenario_sql.py +971 -0
  205. codecop/scenarios.py +675 -0
  206. codecop/scenarios_view.py +274 -0
  207. codecop/schemacli.py +67 -0
  208. codecop/schemas/areas_output.schema.json +21 -0
  209. codecop/schemas/profile_output.schema.json +362 -0
  210. codecop/schemas/rank_output.schema.json +385 -0
  211. codecop/sizes.py +200 -0
  212. codecop/sqlinfo.py +558 -0
  213. codecop/typedparams.py +576 -0
  214. codecop/verdicts.py +212 -0
  215. codecop/writebench.py +720 -0
  216. codecop/writecost.py +440 -0
  217. codecop/writes.py +1208 -0
  218. codecop-0.1.0.dist-info/METADATA +42 -0
  219. codecop-0.1.0.dist-info/RECORD +222 -0
  220. codecop-0.1.0.dist-info/WHEEL +4 -0
  221. codecop-0.1.0.dist-info/entry_points.txt +2 -0
  222. codecop-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,1013 @@
1
+ # Where execution enters a codebase, per language, and what a directory name says
2
+ # about the code in it. This file is data: adding a framework is a change here.
3
+ #
4
+ # Every rule has
5
+ # match regex, searched in the dotted name of the thing matched:
6
+ # decorator / attribute / annotation name, or the callee of a call
7
+ # (`app.router.add_get`, `mux.HandleFunc`, `tokio::spawn`)
8
+ # kind http | workflow | activity | job | consumer | cli | main | test
9
+ #
10
+ # Rules for http:
11
+ # method "$1" = group 1 of `match`, upper-cased; "arg:N" = string argument N;
12
+ # "kw:NAME" = keyword argument; any other text is used as is. Empty = ANY.
13
+ # path index of the path argument (default 0)
14
+ # path_kwargs keyword names that may hold the path
15
+ # path_regex the rule only applies when the evaluated path matches (generic rules)
16
+ # Rules that register a handler by reference (`[[<lang>.call]]`):
17
+ # handler index of the handler argument; -1 = every argument after the path
18
+ # handler_kwargs keyword names that may hold the handler
19
+ # name index of a string argument that names the entry point (subject, topic)
20
+ # name_kwargs keyword names that may hold the name
21
+ # loop_only only when the function started contains an unbounded loop (background loops)
22
+ # structs Go: a struct value registers every exported method of its type
23
+ # each_method with `structs`: one entry point per method, named `<method> <group 1>/<Method>` (a gRPC service)
24
+ # each_interface with `each_method`: suffix of the generated interface that lists the service's methods
25
+ # Class rules (`on = "class"`): the entry points are the methods of the class whose
26
+ # own decorator / annotation / name matches `via`.
27
+ # Decorator rules of kind job / cli / consumer need a dotted name (`@app.task`) unless the bare
28
+ # name is listed in the rule's `bare`.
29
+ # `[[python.class]]` rules name entry points by method name:
30
+ # methods regex on the method name; group 1 is the HTTP method when `method = "$1"`
31
+ # bases optional regex: the class must have a base (direct, or through classes of the
32
+ # repo, compared by name) that matches
33
+ # path_attrs class attributes whose first string is the path (`PATH = "/x"`)
34
+ # name_attrs class attributes whose first string names a non-http entry point
35
+ # `views` on a `[[python.call]]` rule: the handler is a class, not a function.
36
+ # "class" its HTTP verb methods, viewset actions and `@action` methods (see `[python.views]`),
37
+ # one entry point each. `X.as_view()` as the handler of any route rule means the same.
38
+ # "viewset" the same, when the class has a base matching `[python.views] viewset_bases`
39
+ # path_literal the path argument must be a string literal, else the rule does not apply
40
+ # "service" every public method (a gRPC servicer), named `<method> <group 1>/<name>`;
41
+ # `each_class` is the suffix of the generated base class that lists the service's methods.
42
+
43
+ [common]
44
+ # Names too generic to resolve by name alone. A call to one of these is only
45
+ # followed when the receiver or the import says which definition it is.
46
+ ambiguous = [
47
+ "get", "set", "new", "run", "execute", "query", "handle", "init", "main", "start", "stop", "close", "open",
48
+ "call", "apply", "send", "recv", "receive", "read", "write", "load", "save", "create", "update", "delete", "remove",
49
+ "insert", "add", "put", "post", "patch", "list", "find", "fetch", "build", "parse", "format", "validate", "check",
50
+ "process", "do", "exec", "next", "poll", "len", "name", "id", "key", "value", "values", "keys", "items", "iter",
51
+ "map", "filter", "from", "into", "default", "clone", "fmt", "eq", "hash", "cmp", "drop", "as_str", "to_string",
52
+ "string", "error", "is_empty", "contains", "first", "last", "count", "push", "pop", "append", "extend", "clear",
53
+ "reset", "flush", "sync", "wait", "join", "spawn", "connect", "disconnect", "commit", "rollback", "begin", "ping",
54
+ "render", "serialize", "deserialize", "encode", "decode", "to_dict", "from_dict", "to_json", "from_json", "dump",
55
+ "dumps", "loads", "copy", "merge", "with", "then", "and", "or", "not", "is", "has", "len", "size", "type", "kind",
56
+ "status", "state", "config", "context", "client", "session", "request", "response", "result", "data", "info",
57
+ "debug", "warn", "warning", "log", "print", "test", "setup", "teardown", "setUp", "tearDown", "configure",
58
+ "register", "subscribe", "publish", "emit", "dispatch", "invoke", "submit", "schedule", "cancel", "shutdown",
59
+ "serve", "listen", "accept", "bind", "route", "router", "middleware", "wrap", "unwrap", "ok", "err", "some",
60
+ "equals", "hashCode", "toString", "compareTo", "getId", "getName", "builder", "of", "valueOf", "stream",
61
+ "String", "Error", "Close", "Run", "Get", "Set", "New", "Start", "Stop", "Do", "Execute", "Query", "Exec",
62
+ "Handle", "Read", "Write", "Len", "Name", "Init", "Next", "Scan", "Err", "Unwrap", "Validate", "Process",
63
+ "List", "Create", "Update", "Delete", "Insert", "Load", "Save", "Add", "Put", "Open", "Send", "Wait", "Reset",
64
+ "Parse", "Build", "Apply", "Call", "Check", "Find", "Fetch", "Count", "Sync", "Flush", "Ping", "Serve",
65
+ "ServeHTTP", "Register", "Finish", "Fail", "Step", "Value", "Key", "ID", "Type", "Kind", "Status", "State",
66
+ # standard-library and driver methods that repos also define
67
+ "acquire", "release", "lock", "unlock", "strip", "split", "lower", "upper", "replace", "sort", "index",
68
+ "setdefault", "result", "exception", "done", "cursor", "fetchall", "fetchone", "fetchmany", "json", "text",
69
+ "items", "total_seconds", "isoformat", "timestamp", "exists", "mkdir", "unlink", "rename", "seek", "tell",
70
+ "as_ref", "as_mut", "borrow", "to_owned", "to_vec", "into_iter", "collect", "unwrap_or", "ok_or", "and_then",
71
+ "map_err", "await", "take", "skip", "zip", "rev", "min", "max", "sum", "any", "all", "bind", "fetch_all",
72
+ "fetch_one", "fetch_optional", "transaction", "prepare", "finish", "abort", "elapsed", "duration", "sleep",
73
+ "Lock", "Unlock", "RLock", "RUnlock", "Done", "Cancel", "Commit", "Rollback", "Begin", "Prepare", "QueryRow",
74
+ "QueryContext", "ExecContext", "Marshal", "Unmarshal", "Encode", "Decode", "Format", "Before", "After", "Equal",
75
+ "size", "isEmpty", "contains", "containsKey", "forEach", "collect", "orElse", "isPresent", "length", "trim",
76
+ ]
77
+
78
+ # ---------------------------------------------------------------------------------------
79
+ [python]
80
+ # unbounded loop in a function body (marks a spawned function as a background job)
81
+ loop = '\bwhile\s+(True|1|not\s+\w+\.is_set\(\))\s*:|\bwhile\s+self\._?running\b'
82
+ # a file with a `__main__` guard is a long-running service (origin kind "main") when it
83
+ # contains one of these, else a command-line script (origin kind "cli")
84
+ service_main = '\buvicorn\.run\b|\bserve_forever\(|\brun_forever\(|\bapp\.run\(|\bweb\.run_app\(|\bWorker\(|\.start_polling\(|\bhypercorn\b|\bgunicorn\b'
85
+
86
+ # BlackSheep, FastAPI, Starlette, Flask 2 (`@app.get`), aiohttp RouteTableDef (`@routes.get`), Sanic, Quart
87
+ [[python.decorator]]
88
+ match = '(?:^|\.)(get|post|put|delete|patch|head|options)$'
89
+ kind = "http"
90
+ method = "$1"
91
+ path_kwargs = ["path", "pattern", "rule"]
92
+
93
+ [[python.decorator]]
94
+ match = '(?:^|\.)(websocket|ws|websocket_route)$'
95
+ kind = "http"
96
+ method = "WS"
97
+
98
+ # Flask / Quart / BlackSheep `@app.route("/x", methods=["GET"])`, FastAPI `@router.api_route`
99
+ [[python.decorator]]
100
+ match = '(?:^|\.)(route|api_route|custom_route)$'
101
+ kind = "http"
102
+ method = "kw:methods"
103
+ path_kwargs = ["path", "rule"]
104
+
105
+ # MCP servers (FastMCP): a tool, resource or prompt is called by a client request
106
+ [[python.decorator]]
107
+ match = '^(mcp|server|app)\.(tool|resource|prompt)$'
108
+ kind = "http"
109
+ method = "MCP"
110
+ path = -1
111
+
112
+ # Django REST framework `@api_view(["GET"])` (the path lives in urls.py)
113
+ [[python.decorator]]
114
+ match = '(?:^|\.)api_view$'
115
+ kind = "http"
116
+ method = "arg:0"
117
+ path = -1
118
+
119
+ # service lifecycle hooks: BlackSheep on_start, FastAPI on_event, Starlette lifespan, aiohttp on_startup
120
+ [[python.decorator]]
121
+ match = '(?:^|\.)(on_start|after_start|on_stop|on_event|on_startup|on_shutdown|lifespan|before_serving|before_server_start|after_server_start)$'
122
+ kind = "main"
123
+
124
+ # Temporal
125
+ [[python.decorator]]
126
+ match = '^workflow\.defn$'
127
+ kind = "workflow"
128
+ on = "class"
129
+ via = '^workflow\.(run|signal|query|update)$'
130
+ name_kwargs = ["name"]
131
+
132
+ [[python.decorator]]
133
+ match = '^activity\.defn$'
134
+ kind = "activity"
135
+ name_kwargs = ["name"]
136
+
137
+ # Celery, RQ, Dramatiq, Huey, arq; Sentry's `@instrumented_task`; Airflow TaskFlow `@task`, `@task.python`, `@dag`
138
+ [[python.decorator]]
139
+ match = '(?:^|\.)(task|shared_task|periodic_task|actor|job|cron|db_task|db_periodic_task|instrumented_task|retry_task)$'
140
+ kind = "job"
141
+ name_kwargs = ["name"]
142
+ bare = ["task", "shared_task", "job", "actor", "instrumented_task", "periodic_task"]
143
+
144
+ [[python.decorator]]
145
+ match = '^task\.(python|virtualenv|external_python|branch|short_circuit|sensor|docker|kubernetes|bash|branch_virtualenv|branch_external_python|skip_if|run_if|sensor)$|^(dag|task_group)$'
146
+ kind = "job"
147
+ bare = ["dag", "task_group"]
148
+
149
+ # Twisted / Synapse: a function run as a named background process
150
+ [[python.decorator]]
151
+ match = '(?:^|\.)wrap_as_background_process$'
152
+ kind = "job"
153
+ name = 0
154
+ bare = ["wrap_as_background_process"]
155
+
156
+ # APScheduler `@scheduler.scheduled_job(...)`, FastAPI-utils `@repeat_every`
157
+ [[python.decorator]]
158
+ match = '(?:^|\.)(scheduled_job|repeat_every|repeat_at|interval_schedule)$'
159
+ kind = "job"
160
+
161
+ # FastStream / nats-py / aiokafka style subscriber decorators
162
+ [[python.decorator]]
163
+ match = '(?:^|\.)(subscriber|subscribe|consumer|on_message|kafka_listener|agent)$'
164
+ kind = "consumer"
165
+ name = 0
166
+
167
+ # click / typer commands
168
+ [[python.decorator]]
169
+ match = '(?:^|\.)(command|callback)$'
170
+ kind = "cli"
171
+
172
+ # BlackSheep `app.router.add_get(path, handler)`, aiohttp `router.add_get(path, handler)`
173
+ [[python.call]]
174
+ match = '(?:^|\.)add_(get|post|put|delete|patch|head|options)$'
175
+ kind = "http"
176
+ method = "$1"
177
+ path = 0
178
+ handler = -1
179
+
180
+ # aiohttp `web.get(path, handler)` in a route list
181
+ [[python.call]]
182
+ match = '^web\.(get|post|put|delete|patch|head|options)$'
183
+ kind = "http"
184
+ method = "$1"
185
+ path = 0
186
+ handler = -1
187
+
188
+ # BlackSheep / aiohttp `add_route(method, path, handler)`, Starlette `add_route(path, endpoint, methods=[...])`
189
+ [[python.call]]
190
+ match = '(?:^|\.)(add_route|add_api_route|add_websocket_route|add_ws)$'
191
+ kind = "http"
192
+ method = "kw:methods"
193
+ path = -2
194
+ handler = -1
195
+ handler_kwargs = ["endpoint", "handler", "route"]
196
+
197
+ # Flask `app.add_url_rule(rule, endpoint, view_func)`
198
+ [[python.call]]
199
+ match = '(?:^|\.)add_url_rule$'
200
+ kind = "http"
201
+ method = "kw:methods"
202
+ path = 0
203
+ handler = -1
204
+ handler_kwargs = ["view_func"]
205
+
206
+ # Django REST framework `router.register(r"users", UserViewSet)`: the first argument is a string, the
207
+ # second a class of the repo with viewset actions (anything else called `register` yields nothing)
208
+ [[python.call]]
209
+ match = '(?:^|\.)register$'
210
+ kind = "http"
211
+ path = 0
212
+ path_literal = true
213
+ handler = 1
214
+ handler_kwargs = ["viewset"]
215
+ views = "viewset"
216
+
217
+ # gRPC: `add_FooServicer_to_server(FooService(), server)` generated by grpcio-tools
218
+ [[python.call]]
219
+ match = '(?:^|\.)add_(\w+)Servicer_to_server$'
220
+ kind = "http"
221
+ method = "GRPC"
222
+ path = -1
223
+ handler = 0
224
+ views = "service"
225
+ each_class = "Servicer"
226
+
227
+ # Starlette `Route("/x", endpoint)`, Django `path("x/", view)` / `re_path` / `url`
228
+ [[python.call]]
229
+ match = '^(Route|WebSocketRoute|path|re_path|url)$'
230
+ kind = "http"
231
+ method = "kw:methods"
232
+ path = 0
233
+ handler = -1
234
+ handler_kwargs = ["endpoint", "view"]
235
+
236
+ # APScheduler `scheduler.add_job(fn, "interval", ...)`, `schedule.every().do(fn)`, RQ `queue.enqueue(fn)`
237
+ [[python.call]]
238
+ match = '(?:^|\.)(add_job|add_periodic_task|enqueue|enqueue_in|enqueue_at|add_cron_job|add_interval_job)$'
239
+ kind = "job"
240
+ handler = 0
241
+ handler_kwargs = ["func"]
242
+
243
+ [[python.call]]
244
+ match = '\.do$'
245
+ kind = "job"
246
+ handler = 0
247
+ requires = 'every\('
248
+
249
+ # NATS `js.subscribe("subject", cb=handler)`, pub/sub style `subscribe(topic, callback)`
250
+ [[python.call]]
251
+ match = '(?:^|\.)(subscribe|pull_subscribe|queue_subscribe|add_consumer|add_handler|add_message_handler)$'
252
+ kind = "consumer"
253
+ name = 0
254
+ handler = -1
255
+ handler_kwargs = ["cb", "callback", "handler", "on_message"]
256
+
257
+ # a named coroutine or thread target started in the background, when it loops forever
258
+ [[python.call]]
259
+ match = '(?:^|\.)(create_task|ensure_future|run_coroutine_threadsafe|start_soon)$|(?:^|\.)Thread$'
260
+ kind = "job"
261
+ handler = 0
262
+ handler_kwargs = ["target"]
263
+ loop_only = true
264
+
265
+ # Twisted / Synapse background work: `register_background_update_handler("name", fn)`,
266
+ # `run_as_background_process("desc", fn)`, `clock.looping_call(fn, ms)`, `clock.call_later(s, fn)`
267
+ # `keep_edge`: the function also stays reachable from the code that schedules it.
268
+ [[python.call]]
269
+ match = '(?:^|\.)(register_background_update_handler|run_as_background_process)$'
270
+ kind = "job"
271
+ name = 0
272
+ handler = 1
273
+ keep_edge = true
274
+
275
+ [[python.call]]
276
+ match = '(?:^|\.)(looping_call|looping_call_now)$'
277
+ kind = "job"
278
+ handler = 0
279
+ keep_edge = true
280
+
281
+ [[python.call]]
282
+ match = '(?:^|\.)(call_later|callLater|call_when_running|callWhenRunning)$'
283
+ kind = "job"
284
+ handler = 1
285
+ keep_edge = true
286
+
287
+ # Synapse federation: `registry.register_edu_handler(EduTypes.X, fn)`, `register_query_handler("profile", fn)`
288
+ [[python.call]]
289
+ match = '(?:^|\.)register_(edu|query)_handler$'
290
+ kind = "consumer"
291
+ name = 0
292
+ handler = 1
293
+
294
+ # A class decorator that registers the class as a view (NetBox `@register_model_view(Site, "edit", path="edit")`):
295
+ # `views = "class"` makes the verb methods of the class, its own and those inherited from base views in the
296
+ # repository, the entry points, named `<VERB> <Model>/<name or path>`.
297
+ [[python.decorator]]
298
+ match = '(?:^|\.)register_model_view$'
299
+ kind = "http"
300
+ on = "class"
301
+ views = "class"
302
+ path_kwargs = ["path"]
303
+
304
+ # Class-based views: Django `View`, DRF `APIView` / `ViewSet`, Sentry `Endpoint`, Flask `MethodView`.
305
+ # A class becomes entry points where it is registered: `path("x/", V.as_view())`, `router.register("x", V)`.
306
+ [python.views]
307
+ factory = ["as_view"]
308
+ verbs = ["get", "post", "put", "patch", "delete", "head", "options"]
309
+ action_decorator = '(?:^|\.)(action|detail_route|list_route)$'
310
+ # `router.register("x", V)` only counts when V has a base named like one of these (through the repo's classes)
311
+ viewset_bases = '(ViewSet|ViewSetMixin|APIView|GenericAPIView|ModelMixin)$'
312
+
313
+ # Actions a framework base class serves when the class in the repository does not define them. The entry point
314
+ # exists (PUT reaches `UpdateModelMixin.update`); the method has no source here.
315
+ [python.views.provided]
316
+ ModelViewSet = ["list", "retrieve", "create", "update", "partial_update", "destroy"]
317
+ ReadOnlyModelViewSet = ["list", "retrieve"]
318
+ ListModelMixin = ["list"]
319
+ RetrieveModelMixin = ["retrieve"]
320
+ CreateModelMixin = ["create"]
321
+ UpdateModelMixin = ["update", "partial_update"]
322
+ DestroyModelMixin = ["destroy"]
323
+ ListAPIView = ["get"]
324
+ RetrieveAPIView = ["get"]
325
+ CreateAPIView = ["post"]
326
+ UpdateAPIView = ["put", "patch"]
327
+ DestroyAPIView = ["delete"]
328
+ ListCreateAPIView = ["get", "post"]
329
+ RetrieveUpdateAPIView = ["get", "put", "patch"]
330
+ RetrieveDestroyAPIView = ["get", "delete"]
331
+ RetrieveUpdateDestroyAPIView = ["get", "put", "patch", "delete"]
332
+
333
+ [python.views.actions]
334
+ list = "GET"
335
+ retrieve = "GET"
336
+ create = "POST"
337
+ update = "PUT"
338
+ partial_update = "PATCH"
339
+ destroy = "DELETE"
340
+
341
+ # Calls a framework makes that the source does not show. A view class names a helper class in `attrs` (or returns
342
+ # it from one of `methods`); the framework runs the helper's methods inside the view's entry points: those matching
343
+ # `reads` from every entry point, those matching `writes` from the ones named by `write_actions` and from `@action`
344
+ # methods. The origin says so: `verified: false`, `via.kind: "framework"`.
345
+ [[python.framework]]
346
+ attrs = ["serializer_class"]
347
+ methods = ["get_serializer_class"]
348
+ reads = '^(to_representation|get_\w+)$'
349
+ writes = '^(create|update|save|validate(_\w+)?|to_internal_value|run_validation|is_valid)$'
350
+ write_actions = '^(create|update|partial_update|post|put|patch)$'
351
+ never = '^(destroy|delete|head|options)$' # entry points that do not run the helper at all
352
+ label = "Django REST framework runs the view's serializer"
353
+
354
+ # Twisted resources and Synapse servlets: `on_GET` / `render_GET` / `_async_render_GET`. The upper-case
355
+ # verb in the method name is the signal; the path is the class's PATTERNS / PATH.
356
+ [[python.class]]
357
+ methods = '^(?:on|render|_async_render)_(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD)$'
358
+ kind = "http"
359
+ method = "$1"
360
+ path_attrs = ["PATTERNS", "PATH"]
361
+
362
+ # Synapse replication endpoints: `class X(ReplicationEndpoint): NAME = "x"; async def _handle_request(...)`
363
+ [[python.class]]
364
+ methods = '^_handle_request$'
365
+ bases = '^ReplicationEndpoint$'
366
+ kind = "http"
367
+ method = "POST"
368
+ path_attrs = ["NAME"]
369
+
370
+ # Graphene (GraphQL): the executor calls `resolve_<field>` of a type for every query that selects the field, and a
371
+ # mutation's `mutate` / `perform_mutation`. Named `GRAPHQL <Type>.<field>` and `GRAPHQL <Mutation>`.
372
+ [[python.class]]
373
+ methods = '^resolve_(\w+)$'
374
+ bases = '(ObjectType|Interface|Connection)$'
375
+ kind = "http"
376
+ method = "GRAPHQL"
377
+
378
+ [[python.class]]
379
+ methods = '^(?:mutate|mutate_and_get_payload|perform_mutation)$'
380
+ bases = 'Mutation$'
381
+ kind = "http"
382
+ method = "GRAPHQL"
383
+
384
+ # Falcon resources: `on_get(self, req, resp)`
385
+ [[python.class]]
386
+ methods = '^on_(get|post|put|delete|patch)$'
387
+ bases = '(Resource|Controller|Handler|View|Endpoint)$'
388
+ kind = "http"
389
+ method = "$1"
390
+
391
+ # Airflow: an operator's `execute`, a sensor's `poke`, a deferred operator's callback, a trigger's `run`
392
+ [[python.class]]
393
+ methods = '^(execute|execute_complete|poke)$'
394
+ bases = '(Operator|Sensor|OperatorLink)$'
395
+ kind = "job"
396
+
397
+ [[python.class]]
398
+ methods = '^run$'
399
+ bases = '(^|\.)BaseTrigger$|Trigger$'
400
+ kind = "job"
401
+
402
+ # Django management commands: `class Command(BaseCommand): def handle(...)`
403
+ [[python.class]]
404
+ methods = '^handle$'
405
+ bases = '^BaseCommand$'
406
+ kind = "cli"
407
+
408
+ # Celery class-based tasks: `class X(Task): def run(...)`
409
+ [[python.class]]
410
+ methods = '^run$'
411
+ bases = '^(Task|PeriodicTask)$'
412
+ kind = "job"
413
+ name_attrs = ["name"]
414
+
415
+ [python.tests]
416
+ function = '^test'
417
+ class = '^Test|Tests?$'
418
+
419
+ # ---------------------------------------------------------------------------------------
420
+ [rust]
421
+ loop = '\bloop\s*\{|\.tick\(\)\s*\.await|\bwhile\s+let\s+Some\b[^{]*\b(recv|next)\(\)|\bwhile\s+true\b'
422
+
423
+ # utoipa (axum + utoipa-axum `routes!`): `#[utoipa::path(get, path = "/x")]`
424
+ [[rust.attribute]]
425
+ match = '^utoipa::path$'
426
+ kind = "http"
427
+ method = "utoipa"
428
+
429
+ # actix-web, rocket, poem, salvo: `#[get("/x")]`
430
+ [[rust.attribute]]
431
+ match = '^(?:\w+::)*(get|post|put|delete|patch|head|options)$'
432
+ kind = "http"
433
+ method = "$1"
434
+ path = 0
435
+
436
+ [[rust.attribute]]
437
+ match = '^(?:\w+::)*route$'
438
+ kind = "http"
439
+ method = "kw:method"
440
+ path = 0
441
+
442
+ [[rust.attribute]]
443
+ match = '^(tokio|actix_web|actix_rt|async_std|rocket|ntex)::main$|^(rocket::)?launch$'
444
+ kind = "main"
445
+
446
+ [[rust.attribute]]
447
+ match = '(?:^|::)(test|rstest|test_case|proptest|bench|quickcheck)$'
448
+ kind = "test"
449
+
450
+ # axum `.route("/x", get(handler).post(other))`; `nest` and `merge` carry the prefix
451
+ [rust.router]
452
+ route = ["route", "route_service"]
453
+ methods = ["get", "post", "put", "delete", "patch", "head", "options", "any", "trace", "connect",
454
+ "get_service", "post_service", "any_service", "on"]
455
+ nest = ["nest", "nest_service", "scope"]
456
+ merge = ["merge"]
457
+ fallback = ["fallback", "fallback_service"]
458
+ # utoipa-axum `routes!(handler, other)`: the handlers carry `#[utoipa::path]`
459
+ macros = ["routes"]
460
+
461
+ [[rust.call]]
462
+ match = '^(tokio::(task::)?spawn|tokio::spawn_local|task::spawn|spawn|tokio::task::spawn_blocking|std::thread::spawn|thread::spawn|async_std::task::spawn)$'
463
+ kind = "job"
464
+ handler = 0
465
+ loop_only = true
466
+
467
+ # tokio-cron-scheduler `Job::new_async("0 * * * * *", |..| ...)`, apalis, clokwerk are closures: not covered
468
+
469
+ # ---------------------------------------------------------------------------------------
470
+ [go]
471
+ loop = '\bfor\s*\{|\bfor\s+range\s+[\w.]+\.C\b|\bfor\s+(?:\w+\s*:?=\s*)?range\s+time\.Tick\(|\bfor\s+(?:\w+(?:\s*,\s*\w+)?\s*:?=\s*)?range\s+\w*[Cc]h(?:an)?\w*\s*\{'
472
+
473
+ # net/http `mux.HandleFunc("GET /x", h)`, gorilla `r.HandleFunc("/x", h).Methods("GET")`
474
+ [[go.call]]
475
+ match = '(?:^|\.)(HandleFunc|Handle)$'
476
+ kind = "http"
477
+ method = "chain:Methods"
478
+ path = 0
479
+ handler = -1
480
+ # `Handle` is a common name: the first argument must read as a path or a "METHOD /path" pattern
481
+ path_regex = '^((GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS) )?(/|…/)|^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS) …'
482
+
483
+ # chi `r.Get("/x", h)`, gin / echo `r.GET("/x", h)`, fiber `app.Get`
484
+ [[go.call]]
485
+ match = '\.(Get|Post|Put|Delete|Patch|Head|Options|GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$'
486
+ kind = "http"
487
+ method = "$1"
488
+ path = 0
489
+ handler = -1
490
+ # `.Get(ctx, key)` is also a cache or store read: the first argument must read as a path, or be the empty path a
491
+ # gin / echo group's own route is written with (`orgs.GET("", h)` serves the group's prefix)
492
+ path_regex = '^(/|…/)|^$'
493
+
494
+ [[go.call]]
495
+ match = '\.(Any|Method|MethodFunc|Match)$'
496
+ kind = "http"
497
+ method = ""
498
+ path = -2
499
+ handler = -1
500
+ path_regex = '^/'
501
+
502
+ # a local wrapper around the mux: any call whose first argument is a Go 1.22 pattern
503
+ [[go.call]]
504
+ match = ''
505
+ kind = "http"
506
+ path = 0
507
+ handler = -1
508
+ path_regex = '^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS) (/|…)'
509
+
510
+ # Temporal
511
+ [[go.call]]
512
+ match = '\.RegisterWorkflow(WithOptions)?$'
513
+ kind = "workflow"
514
+ handler = 0
515
+ name_option = "Name"
516
+
517
+ [[go.call]]
518
+ match = '\.RegisterActivity(WithOptions)?$'
519
+ kind = "activity"
520
+ handler = 0
521
+ name_option = "Name"
522
+ structs = true
523
+
524
+ # gRPC (protoc-gen-go-grpc): `pb.RegisterFooServer(grpcServer, impl)`. Every method of the service is an
525
+ # entry point of its own, `GRPC Foo/Method`: the methods of the generated `FooServer` interface when that is
526
+ # in the repo, else the exported methods of the registered value that take one or two arguments.
527
+ [[go.call]]
528
+ match = '(?:^|\.)Register(\w+)Server$'
529
+ kind = "http"
530
+ method = "GRPC"
531
+ path = -1
532
+ handler = 1
533
+ structs = true
534
+ each_method = true
535
+ each_interface = "Server"
536
+
537
+ # robfig/cron `c.AddFunc("@every 1m", fn)`, gocron `s.Every(1).Minute().Do(fn)`
538
+ [[go.call]]
539
+ match = '\.(AddFunc|AddJob)$'
540
+ kind = "job"
541
+ handler = 1
542
+
543
+ [[go.call]]
544
+ match = '\.Do$'
545
+ kind = "job"
546
+ handler = 0
547
+ requires = '\.Every\('
548
+
549
+ # NATS `nc.Subscribe("subject", handler)`
550
+ [[go.call]]
551
+ match = '\.(Subscribe|QueueSubscribe|ChanSubscribe|SubscribeSync)$'
552
+ kind = "consumer"
553
+ name = 0
554
+ handler = -1
555
+
556
+ # `go loopFn()` where the function loops forever
557
+ [[go.call]]
558
+ match = '^go$'
559
+ kind = "job"
560
+ handler = 0
561
+ loop_only = true
562
+
563
+ [go.router]
564
+ # `g := r.Group("/api")` (gin, echo), `r.Route("/api", func(r chi.Router) {...})`, gorilla `PathPrefix("/api").Subrouter()`
565
+ group = ["Group", "Route", "PathPrefix"]
566
+ # `m.Combo("/x").Get(list).Post(create)` (macaron, flamego, Gitea's router): the path is the Combo's, each verb names handlers
567
+ combo = ["Combo"]
568
+
569
+ [go.tests]
570
+ function = '^(Test|Benchmark|Fuzz|Example)'
571
+
572
+ # ---------------------------------------------------------------------------------------
573
+ [java]
574
+ loop = '\bwhile\s*\(\s*true\s*\)|\bfor\s*\(\s*;\s*;\s*\)'
575
+ # class-level annotations whose value is a path prefix
576
+ prefix_annotations = ["RequestMapping", "Path"]
577
+
578
+ # Spring MVC / WebFlux
579
+ [[java.annotation]]
580
+ match = '^(Get|Post|Put|Delete|Patch)Mapping$'
581
+ kind = "http"
582
+ method = "$1"
583
+
584
+ [[java.annotation]]
585
+ match = '^RequestMapping$'
586
+ kind = "http"
587
+ method = "kw:method"
588
+
589
+ # JAX-RS / Quarkus / Micronaut: `@GET @Path("/x")`
590
+ [[java.annotation]]
591
+ match = '^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$'
592
+ kind = "http"
593
+ method = "$1"
594
+ path_annotation = "Path"
595
+
596
+ [[java.annotation]]
597
+ match = '^(Get|Post|Put|Delete|Patch)$'
598
+ kind = "http"
599
+ method = "$1"
600
+
601
+ [[java.annotation]]
602
+ match = '^(Scheduled|Schedules|SchedulerLock)$'
603
+ kind = "job"
604
+
605
+ # Spring GraphQL, Spring WebSocket / STOMP, Spring Cloud Stream function beans are not covered
606
+ [[java.annotation]]
607
+ match = '^(QueryMapping|MutationMapping|SubscriptionMapping|SchemaMapping)$'
608
+ kind = "http"
609
+ method = "GRAPHQL"
610
+
611
+ [[java.annotation]]
612
+ match = '^(SubscribeMapping|OnMessage|OnOpen)$'
613
+ kind = "http"
614
+ method = "WS"
615
+
616
+ [[java.annotation]]
617
+ match = '^(KafkaListener|RabbitListener|JmsListener|SqsListener|StreamListener|EventListener|TransactionalEventListener|MessageMapping|ServiceActivator|PulsarListener|RocketMQMessageListener|KafkaHandler|RabbitHandler|Incoming)$'
618
+ kind = "consumer"
619
+ name_kwargs = ["topics", "queues", "destination", "value", "topicPattern", "classes"]
620
+
621
+ # Temporal Java SDK
622
+ [[java.annotation]]
623
+ match = '^(WorkflowMethod|SignalMethod|QueryMethod|UpdateMethod)$'
624
+ kind = "workflow"
625
+
626
+ [[java.annotation]]
627
+ match = '^ActivityMethod$'
628
+ kind = "activity"
629
+
630
+ # runs once when the service starts
631
+ [[java.annotation]]
632
+ match = '^(PostConstruct|Bean)$'
633
+ kind = "main"
634
+
635
+ [[java.annotation]]
636
+ match = '^(Test|ParameterizedTest|RepeatedTest|TestFactory|TestTemplate|Property)$'
637
+ kind = "test"
638
+
639
+ # `class X implements ApplicationRunner { run(...) }` runs at startup
640
+ [[java.interface]]
641
+ match = '^(ApplicationRunner|CommandLineRunner|ApplicationListener|SmartLifecycle|InitializingBean)$'
642
+ kind = "main"
643
+ via = '^(run|onApplicationEvent|start|afterPropertiesSet)$'
644
+
645
+ [[java.interface]]
646
+ match = '^(Job|QuartzJobBean|Tasklet)$'
647
+ kind = "job"
648
+ via = '^(execute|executeInternal)$'
649
+
650
+ # Servlet API: `class X extends HttpServlet { doGet(...) }`
651
+ [[java.interface]]
652
+ match = '^(HttpServlet|GenericServlet)$'
653
+ kind = "http"
654
+ via = '^do(Get|Post|Put|Delete|Patch|Head|Options)$'
655
+ method = "$1"
656
+
657
+ # gRPC: `class X extends FooGrpc.FooImplBase { @Override public void bar(Req r, StreamObserver<Res> o) }`
658
+ # `override`: only methods marked @Override; `service`: the suffix cut from the base's name, `GRPC Foo/bar`
659
+ [[java.interface]]
660
+ match = '^\w+ImplBase$'
661
+ kind = "http"
662
+ via = '^\w+$'
663
+ method = "GRPC"
664
+ override = true
665
+ service = "ImplBase"
666
+
667
+ # Netty: `class X extends SimpleChannelInboundHandler<Msg> { channelRead0(...) }`
668
+ [[java.interface]]
669
+ match = '^(SimpleChannelInboundHandler|ChannelInboundHandlerAdapter|ChannelDuplexHandler|ChannelInboundHandler)$'
670
+ kind = "consumer"
671
+ via = '^(channelRead0?|messageReceived)$'
672
+
673
+ # Workflow engines that hand work to `execute` of a class implementing `Activity` / `Workflow`
674
+ # (Dependency-Track's durable execution engine, and others that name them so)
675
+ [[java.interface]]
676
+ match = '^Activity$'
677
+ kind = "activity"
678
+ via = '^execute$'
679
+
680
+ [[java.interface]]
681
+ match = '^Workflow$'
682
+ kind = "workflow"
683
+ via = '^execute$'
684
+
685
+ # Alpine event framework: `class X implements Subscriber { inform(Event e) }`
686
+ [[java.interface]]
687
+ match = '^(Subscriber|LoggableSubscriber|LoggableUncaughtExceptionHandler)$'
688
+ kind = "consumer"
689
+ via = '^inform$'
690
+
691
+ # ThingsBoard: actors (`doProcess` / `process` of a `TbActor`), rule nodes (`onMsg` of a `TbNode`)
692
+ [[java.interface]]
693
+ match = '^(TbActor|AbstractTbActor|ContextAwareActor|ComponentActor|RuleEngineComponentActor)$'
694
+ kind = "consumer"
695
+ via = '^(doProcess|process)$'
696
+
697
+ [[java.interface]]
698
+ match = '^(TbNode|TbAbstractExternalNode|TbAbstractRelationActionNode|TbAbstractAlarmNode)$'
699
+ kind = "consumer"
700
+ via = '^onMsg$'
701
+
702
+ # ---------------------------------------------------------------------------------------
703
+ # What a path says about the code in it. Checked on every directory name of the path
704
+ # (lower-cased): `dirs` match the whole name, `tokens` match one word of a name split on
705
+ # `-`, `_`, `.` and spaces. `files` are regexes on the file name. Order: the deepest
706
+ # directory wins; test paths are decided by the extractors (`is_test`).
707
+ [roles.migration]
708
+ dirs = ["migrations", "migration", "migrate", "alembic", "flyway", "liquibase", "db_migrations", "ddl",
709
+ "sqlx-migrations", "changelog", "changelogs"]
710
+ tokens = ["migrations", "migration"]
711
+ files = ['^V\d+__.*\.sql$', '^\d{3,}[_-].*\.sql$', '^\d{8,}.*\.sql$']
712
+
713
+ [roles.script]
714
+ dirs = ["scripts", "script", "examples", "example", "demo", "demos", "samples", "sample", "playground", "scratch",
715
+ "notebooks", "oneoff", "one_off", "adhoc", "ad_hoc", "legacy", "archive", "archived", "deprecated",
716
+ "attic", "old", "experiments", "poc", "sandbox"]
717
+ tokens = ["scripts", "script", "dryrun", "scratch", "legacy", "unused", "deprecated", "examples", "oneoff"]
718
+ files = ['^\.', '^tmp[_-]', '^scratch[_-]', '_scratch\.', '^manage\.py$']
719
+
720
+ [roles.tooling]
721
+ dirs = ["tools", "tool", "tooling", "ci", "deploy", "deployment", "deployments", "devops", "infra", "ops",
722
+ "docker", "benches", "bench", "benchmarks", "benchmark", "hack", "packaging", "devtools",
723
+ "xtask", "codegen", ".github", ".circleci", "k8s", "helm", "terraform", "smoke",
724
+ "loadtest", "load_tests", "docs", "doc"]
725
+ tokens = ["tools", "tooling", "bench", "benchmark", "smoke", "loadtest", "codegen"]
726
+ files = ['^build\.rs$', '^setup\.py$', '^noxfile\.py$', '^fabfile\.py$', '^tasks\.py$']
727
+
728
+ # ---------------------------------------------------------------------------------------
729
+ [typescript]
730
+ # TypeScript and JavaScript. Rules for calls and constructors also take
731
+ # names the last segment of the callee, for a fast first check (`app.get` -> "get")
732
+ # match regex on the callee chain with arguments dropped: `protectedProcedure.input().query`
733
+ # name_from "key": the entry is named after the property or variable it is assigned to
734
+ # join how a router prefix joins the name: "/" for paths (default), "." for tRPC
735
+ # exports_of_kwargs the options that name a module or object: each exported function is an entry
736
+ # Options objects are read as keyword arguments: `fastify.route({ method, url, handler })`.
737
+ # unbounded loop in a function body
738
+ loop = '\bwhile\s*\(\s*(?:true|1|!\s*[\w.]+)\s*\)|\bfor\s*\(\s*;\s*;\s*\)'
739
+ # a program (a package.json script or bin, a shebang, a main guard) is a long-running service
740
+ # (origin kind "main") when it contains one of these, else a command-line script (kind "cli")
741
+ service_main = '\.listen\s*\(|\bcreateServer\s*\(|\bNestFactory\.create|\bnew\s+Worker\s*\(|\bserve\s*\(|\bWorker\.create\s*\(|\.start(?:Polling)?\s*\('
742
+ # a file directly in one of these directories is taken to be a program; listed only when it reaches a query
743
+ program_dirs = '(?:^|/)(?:scripts?|bin|cli|commands?|seeds?|seeders?|cron|crons|jobs|tasks|migrations?|backgroundMigrations)/[^/]+$'
744
+
745
+ # calls whose callee may be a function of the repo that registers a handler it is given
746
+ # (`WorkerManager.register(queue, processor)` around `new Worker(queue, processor)`): such a function is
747
+ # found from its body; this only limits which calls are remembered while files are read
748
+ registration_like = '^(?:register|add|define|schedule|subscribe|consume|process|create|on|handle|listen|start|run|use|mount|route|get|post|put|patch|delete|cron|job|task|worker|queue|every)'
749
+
750
+ [typescript.router]
751
+ # `app.use("/prefix", router)`, Hono `app.route("/prefix", sub)`, Fastify `app.register(plugin, { prefix })`
752
+ mount = ["use", "route", "register", "mount", "basePath"]
753
+ # decorators whose argument is the path prefix of a class
754
+ class_prefix = ["Controller"]
755
+ # calls that build a router from an object: `createTRPCRouter({ traces: traceRouter })`
756
+ factory = ["router", "createTRPCRouter", "createRouter", "mergeRouters", "createCallerFactory"]
757
+
758
+ # Express, Koa router, Fastify, Hono, Elysia, itty-router, Polka: `app.get("/path", ...handlers)`.
759
+ # Only a call with a handler argument that is a function counts, so `axios.get("/x")` does not.
760
+ [[typescript.call]]
761
+ names = ["get", "post", "put", "delete", "patch", "head", "options", "all", "del"]
762
+ match = '(?:^|\.|\(\)\.)(get|post|put|delete|patch|head|options|all|del)$'
763
+ kind = "http"
764
+ method = "$1"
765
+ path = 0
766
+ path_regex = '^(?:/|\*|…/|\$\{)'
767
+ handler = -1
768
+
769
+ # AT Protocol XRPC (`@atproto/xrpc-server`): `server.add(com.atproto.server.getSession, { auth, handler })`.
770
+ # Named `XRPC <nsid>`: the first argument's dotted name is the route (`path_text`).
771
+ [[typescript.call]]
772
+ names = ["add"]
773
+ match = '(?:^|\.)add$'
774
+ kind = "http"
775
+ method = "XRPC"
776
+ path = 0
777
+ path_text = true
778
+ path_regex = '^(?:[a-z][\w-]*\.){2,}[A-Za-z]\w*$'
779
+ handler_kwargs = ["handler"]
780
+
781
+ # Fastify `app.route({ method, url, handler })`, Hapi `server.route({ method, path, handler })`
782
+ [[typescript.call]]
783
+ names = ["route"]
784
+ match = '(?:^|\.)route$'
785
+ kind = "http"
786
+ method = "kw:method"
787
+ path = -1
788
+ path_kwargs = ["url", "path"]
789
+ handler_kwargs = ["handler"]
790
+
791
+ # tRPC: `list: protectedProcedure.input(schema).query(async ({ ctx, input }) => ...)`
792
+ [[typescript.call]]
793
+ names = ["query", "mutation", "subscription"]
794
+ match = '[pP]rocedure\b.*\.(query|mutation|subscription)$'
795
+ kind = "http"
796
+ method = "TRPC"
797
+ path = -1
798
+ handler = 0
799
+ name_from = "key"
800
+ join = "."
801
+
802
+ # Bull `queue.process("name", fn)`, pg-boss `boss.work("queue", fn)`, Agenda `agenda.define("name", fn)`,
803
+ # graphile-worker / custom `registerWorker(name, fn)`
804
+ [[typescript.call]]
805
+ names = ["process", "work", "define", "registerWorker", "addWorker", "registerJob", "registerProcessor"]
806
+ match = '(?:[qQ]ueue\w*|[bB]oss\w*|agenda|worker\w*|Worker\w*|[jJ]obs?\w*)\.(?:process|work|define)$|(?:^|\.)(?:registerWorker|addWorker|registerJob|registerProcessor)$'
807
+ kind = "job"
808
+ name = 0
809
+ handler = -1
810
+
811
+ # node-cron `cron.schedule("* * * * *", fn)`, node-schedule `schedule.scheduleJob(spec, fn)`, croner `Cron(spec, fn)`
812
+ [[typescript.call]]
813
+ names = ["schedule", "scheduleJob", "Cron"]
814
+ match = '(?:^|\.)(?:cron\.schedule|schedule|scheduleJob|Cron)$'
815
+ kind = "job"
816
+ name = 0
817
+ handler = -1
818
+
819
+ # timers: listed only when the callback reaches a query
820
+ [[typescript.call]]
821
+ names = ["setInterval"]
822
+ match = '^setInterval$'
823
+ kind = "job"
824
+ handler = 0
825
+ tag = "loop"
826
+
827
+ # Inngest `inngest.createFunction({ id }, { event }, handler)`
828
+ [[typescript.call]]
829
+ names = ["createFunction"]
830
+ match = '(?:^|\.)createFunction$'
831
+ kind = "job"
832
+ name_kwargs = ["id", "name"]
833
+ handler = -1
834
+
835
+ # Trigger.dev `task({ id, run })`, `schedules.task({ id, cron, run })`
836
+ [[typescript.call]]
837
+ names = ["task", "schemaTask"]
838
+ match = '^(?:task|schemaTask|schedules\.task)$'
839
+ kind = "job"
840
+ name_kwargs = ["id"]
841
+ handler_kwargs = ["run"]
842
+
843
+ # kafkajs `consumer.run({ eachMessage })`, sqs-consumer `Consumer.create({ handleMessage })`
844
+ [[typescript.call]]
845
+ names = ["run", "create"]
846
+ match = '(?:[cC]onsumer\w*)\.(?:run|create)$'
847
+ kind = "consumer"
848
+ name_kwargs = ["queueUrl", "topic"]
849
+ handler_kwargs = ["eachMessage", "eachBatch", "handleMessage", "handleMessageBatch"]
850
+
851
+ # amqplib `channel.consume("queue", fn)`
852
+ [[typescript.call]]
853
+ names = ["consume"]
854
+ match = '(?:^|\.)consume$'
855
+ kind = "consumer"
856
+ name = 0
857
+ handler = 1
858
+
859
+ # Temporal: `Worker.create({ activities, workflowsPath: require.resolve("./workflows") })`
860
+ [[typescript.call]]
861
+ names = ["create"]
862
+ match = '(?:^|\.)Worker\.create$'
863
+ kind = "activity"
864
+ exports_of_kwargs = ["activities"]
865
+
866
+ [[typescript.call]]
867
+ names = ["create"]
868
+ match = '(?:^|\.)Worker\.create$'
869
+ kind = "workflow"
870
+ exports_of_kwargs = ["workflowsPath"]
871
+
872
+ # commander `program.command("x").action(fn)`
873
+ [[typescript.call]]
874
+ names = ["action"]
875
+ match = '\.action$'
876
+ kind = "cli"
877
+ handler = 0
878
+
879
+ # BullMQ `new Worker("queue", processor, opts)`, cron `new CronJob(spec, fn)`
880
+ [[typescript.new]]
881
+ names = ["Worker"]
882
+ match = '^Worker$'
883
+ kind = "job"
884
+ name = 0
885
+ handler = 1
886
+
887
+ [[typescript.new]]
888
+ names = ["CronJob", "Cron"]
889
+ match = '^(?:CronJob|Cron)$'
890
+ kind = "job"
891
+ name = 0
892
+ handler = 1
893
+
894
+ # NestJS controllers; the class's `@Controller("prefix")` is joined in front
895
+ [[typescript.decorator]]
896
+ match = '^(Get|Post|Put|Delete|Patch|Head|Options|All)$'
897
+ kind = "http"
898
+ method = "$1"
899
+
900
+ # NestJS GraphQL resolvers, type-graphql
901
+ [[typescript.decorator]]
902
+ match = '^(Query|Mutation|Subscription|ResolveField|FieldResolver|ResolveReference)$'
903
+ kind = "http"
904
+ method = "GRAPHQL"
905
+ path = -1
906
+
907
+ [[typescript.decorator]]
908
+ match = '^(SubscribeMessage|GrpcMethod|GrpcStreamMethod)$'
909
+ kind = "http"
910
+ method = "RPC"
911
+ path = -1
912
+
913
+ [[typescript.decorator]]
914
+ match = '^(MessagePattern|EventPattern|OnEvent|OnQueueEvent|RabbitSubscribe|RabbitRPC|SqsMessageHandler|OnWorkerEvent|EventsHandler|Subscribe|OnDatabaseBatchEvent|OnCustomBatchEvent)$'
915
+ kind = "consumer"
916
+ name = 0
917
+
918
+ [[typescript.decorator]]
919
+ match = '^(Cron|Interval|Timeout)$'
920
+ kind = "job"
921
+ name = 0
922
+
923
+ # Bull `@Process("name")` methods of a `@Processor("queue")` class
924
+ [[typescript.decorator]]
925
+ match = '^Process$'
926
+ kind = "job"
927
+ name = 0
928
+
929
+ # BullMQ: `@Processor("queue") class X extends WorkerHost { process(job) }`
930
+ [[typescript.decorator]]
931
+ match = '^Processor$'
932
+ kind = "job"
933
+ on = "class"
934
+ via = '^process$'
935
+ name = 0
936
+
937
+ # nest-commander: `@Command({ name }) class X extends CommandRunner { run() }`, and a project's own
938
+ # `@...Command(...)` class decorators (upgrade and maintenance commands with `up` / `down` / `execute`)
939
+ [[typescript.decorator]]
940
+ match = 'Command$'
941
+ kind = "cli"
942
+ on = "class"
943
+ via = '^(run|up|down|execute)$'
944
+ name_kwargs = ["name"]
945
+
946
+ # TypeORM migrations: `class X implements MigrationInterface { up(queryRunner) {} }` run from the migration CLI
947
+ [[typescript.decorator]]
948
+ match = '^MigrationInterface$'
949
+ kind = "cli"
950
+ on = "extends"
951
+ via = '^(up|down)$'
952
+
953
+ # Temporal with decorators (nestjs-temporal)
954
+ [[typescript.decorator]]
955
+ match = '^(Activity|ActivityMethod)$'
956
+ kind = "activity"
957
+
958
+ [[typescript.decorator]]
959
+ match = '^(WorkflowMethod|SignalMethod|QueryMethod)$'
960
+ kind = "workflow"
961
+
962
+ # Next.js App Router: `app/**/route.ts` exports one function per verb; the directory is the path
963
+ [[typescript.file]]
964
+ match = '(?:^|/)app/(?:(.*)/)?route\.[cm]?[jt]sx?$'
965
+ kind = "http"
966
+ exports = '^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$'
967
+ method = "$export"
968
+
969
+ # Next.js Pages Router API routes: the default export handles every verb
970
+ [[typescript.file]]
971
+ match = '(?:^|/)pages/(api(?:/.*)?)\.[cm]?[jt]sx?$'
972
+ kind = "http"
973
+ exports = '^default$'
974
+ method = "ANY"
975
+
976
+ # Next.js pages and layouts rendered on the server
977
+ [[typescript.file]]
978
+ match = '(?:^|/)app/(?:(.*)/)?(?:page|layout)\.[jt]sx?$'
979
+ kind = "http"
980
+ exports = '^(default|generateMetadata|generateStaticParams)$'
981
+ method = "GET"
982
+
983
+ [[typescript.file]]
984
+ match = '(?:^|/)pages/((?!api/).*)\.[jt]sx?$'
985
+ kind = "http"
986
+ exports = '^(getServerSideProps|getStaticProps|getStaticPaths|getInitialProps)$'
987
+ method = "GET"
988
+
989
+ # SvelteKit endpoints and server load functions, Remix / React Router loaders and actions
990
+ [[typescript.file]]
991
+ match = '(?:^|/)routes/(?:(.*)/)?\+server\.[jt]s$'
992
+ kind = "http"
993
+ exports = '^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|fallback)$'
994
+ method = "$export"
995
+
996
+ [[typescript.file]]
997
+ match = '(?:^|/)routes/(?:(.*)/)?\+(?:page|layout)\.server\.[jt]s$'
998
+ kind = "http"
999
+ exports = '^(load|actions)$'
1000
+ method = "GET"
1001
+
1002
+ [[typescript.file]]
1003
+ match = '(?:^|/)app/routes/(.*)\.[jt]sx?$'
1004
+ kind = "http"
1005
+ exports = '^(loader|action)$'
1006
+ method = "$export"
1007
+
1008
+ # a module that starts with "use server": every export is a server action
1009
+ [[typescript.directive]]
1010
+ match = 'use server'
1011
+ kind = "http"
1012
+ exports = '^(?!default$).+'
1013
+ method = "ACTION"