codeveto 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.
- codeveto/__init__.py +3 -0
- codeveto/__main__.py +8 -0
- codeveto/ai/__init__.py +19 -0
- codeveto/ai/harness.py +303 -0
- codeveto/ai/packets.py +855 -0
- codeveto/ai/policy.py +222 -0
- codeveto/ai/prompt.py +101 -0
- codeveto/ai/providers/__init__.py +178 -0
- codeveto/ai/providers/claude.py +247 -0
- codeveto/ai/providers/openai_compat.py +246 -0
- codeveto/ai/runner.py +293 -0
- codeveto/ai/verify.py +324 -0
- codeveto/anchor.py +211 -0
- codeveto/cli.py +247 -0
- codeveto/cli_explain.py +49 -0
- codeveto/cli_hook.py +31 -0
- codeveto/cli_init.py +254 -0
- codeveto/cli_mcp.py +29 -0
- codeveto/cli_packets.py +35 -0
- codeveto/cli_publish.py +29 -0
- codeveto/cli_review.py +362 -0
- codeveto/cli_rules.py +78 -0
- codeveto/cli_verify.py +47 -0
- codeveto/config.py +1229 -0
- codeveto/data/README.md +16 -0
- codeveto/data/ai-wire.schema.json +53 -0
- codeveto/data/prompts/system.md +57 -0
- codeveto/data/report-v1.schema.json +268 -0
- codeveto/data/templates/forgejo-codeveto.yml +104 -0
- codeveto/data/templates/github-codeveto.yml +18 -0
- codeveto/embedded.py +311 -0
- codeveto/engine.py +1570 -0
- codeveto/git.py +1549 -0
- codeveto/globs.py +348 -0
- codeveto/integrations/__init__.py +1 -0
- codeveto/integrations/hooks.py +327 -0
- codeveto/integrations/mcp.py +770 -0
- codeveto/integrations/mcp_ai.py +77 -0
- codeveto/integrations/prepush.py +222 -0
- codeveto/jsonsafe.py +60 -0
- codeveto/languages.py +539 -0
- codeveto/lexers.py +2560 -0
- codeveto/model.py +372 -0
- codeveto/publish/__init__.py +28 -0
- codeveto/publish/action.py +330 -0
- codeveto/publish/common.py +84 -0
- codeveto/publish/diff.py +208 -0
- codeveto/publish/event.py +241 -0
- codeveto/publish/forgejo.py +184 -0
- codeveto/publish/github.py +380 -0
- codeveto/publish/http.py +263 -0
- codeveto/publish/pull.py +218 -0
- codeveto/publish/untrusted.py +110 -0
- codeveto/py.typed +0 -0
- codeveto/redact.py +113 -0
- codeveto/render/__init__.py +64 -0
- codeveto/render/agent.py +43 -0
- codeveto/render/github.py +101 -0
- codeveto/render/json.py +23 -0
- codeveto/render/markdown.py +208 -0
- codeveto/render/safe.py +249 -0
- codeveto/render/sarif.py +217 -0
- codeveto/render/text.py +210 -0
- codeveto/report.py +252 -0
- codeveto/rules/__init__.py +84 -0
- codeveto/rules/agent.py +2972 -0
- codeveto/rules/base.py +1026 -0
- codeveto/rules/ci.py +1708 -0
- codeveto/rules/config.py +493 -0
- codeveto/rules/deps.py +1693 -0
- codeveto/rules/docker.py +479 -0
- codeveto/rules/examples/__init__.py +148 -0
- codeveto/rules/examples/agent.py +839 -0
- codeveto/rules/examples/ci.py +1046 -0
- codeveto/rules/examples/config.py +191 -0
- codeveto/rules/examples/deps.py +369 -0
- codeveto/rules/examples/docker.py +157 -0
- codeveto/rules/examples/go.py +241 -0
- codeveto/rules/examples/hygiene.py +466 -0
- codeveto/rules/examples/js.py +462 -0
- codeveto/rules/examples/python.py +595 -0
- codeveto/rules/examples/rust.py +268 -0
- codeveto/rules/examples/secrets.py +561 -0
- codeveto/rules/examples/security.py +608 -0
- codeveto/rules/examples/shell.py +174 -0
- codeveto/rules/examples/sql.py +194 -0
- codeveto/rules/examples/tests.py +497 -0
- codeveto/rules/go.py +328 -0
- codeveto/rules/hygiene.py +1094 -0
- codeveto/rules/js.py +768 -0
- codeveto/rules/python.py +1642 -0
- codeveto/rules/rust.py +209 -0
- codeveto/rules/secrets.py +1335 -0
- codeveto/rules/security.py +3680 -0
- codeveto/rules/shell.py +867 -0
- codeveto/rules/sql.py +629 -0
- codeveto/rules/tests.py +1404 -0
- codeveto/schema.py +384 -0
- codeveto/statements.py +607 -0
- codeveto/worktree.py +1176 -0
- codeveto/yamlish.py +1179 -0
- codeveto-0.1.0.dist-info/METADATA +253 -0
- codeveto-0.1.0.dist-info/RECORD +106 -0
- codeveto-0.1.0.dist-info/WHEEL +4 -0
- codeveto-0.1.0.dist-info/entry_points.txt +2 -0
- codeveto-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""Examples for the rust pack."""
|
|
2
|
+
|
|
3
|
+
from codeveto.rules.base import bad, good
|
|
4
|
+
|
|
5
|
+
EXAMPLES = {
|
|
6
|
+
"rust/todo-macro": [
|
|
7
|
+
bad(
|
|
8
|
+
"src/export.rs",
|
|
9
|
+
"pub fn export(format: Format) -> Result<Vec<u8>, Error> {\n"
|
|
10
|
+
" match format {\n"
|
|
11
|
+
" Format::Json => to_json(),\n"
|
|
12
|
+
" Format::Csv => todo!(), // expect\n"
|
|
13
|
+
" }\n"
|
|
14
|
+
"}\n",
|
|
15
|
+
note="The CSV branch compiles and panics the first time a user picks it.",
|
|
16
|
+
),
|
|
17
|
+
bad(
|
|
18
|
+
"src/storage/s3.rs",
|
|
19
|
+
"impl Backend for S3 {\n"
|
|
20
|
+
" fn delete(&self, key: &str) -> io::Result<()> {\n"
|
|
21
|
+
' unimplemented!("delete {key}") // expect\n'
|
|
22
|
+
" }\n"
|
|
23
|
+
"}\n",
|
|
24
|
+
),
|
|
25
|
+
good(
|
|
26
|
+
"src/export.rs",
|
|
27
|
+
"/// Exports data. Formats still to do: `todo!()` is never used here.\n"
|
|
28
|
+
"pub fn export(format: Format) -> Result<Vec<u8>, Error> {\n"
|
|
29
|
+
" match format {\n"
|
|
30
|
+
" Format::Json => to_json(),\n"
|
|
31
|
+
' Format::Csv => Err(Error::Unsupported("csv")),\n'
|
|
32
|
+
" }\n"
|
|
33
|
+
"}\n"
|
|
34
|
+
"\n"
|
|
35
|
+
"#[cfg(test)]\n"
|
|
36
|
+
"mod tests {\n"
|
|
37
|
+
" #[test]\n"
|
|
38
|
+
" fn csv() {\n"
|
|
39
|
+
" todo!()\n"
|
|
40
|
+
" }\n"
|
|
41
|
+
"}\n",
|
|
42
|
+
note="Doc comments and #[cfg(test)] code are not reported.",
|
|
43
|
+
),
|
|
44
|
+
good(
|
|
45
|
+
"tests/export.rs",
|
|
46
|
+
"#[test]\n"
|
|
47
|
+
"fn exports_csv() {\n"
|
|
48
|
+
" todo!(\"write once CSV lands\")\n"
|
|
49
|
+
"}\n",
|
|
50
|
+
note="Integration tests under tests/ are test files.",
|
|
51
|
+
),
|
|
52
|
+
],
|
|
53
|
+
"rust/dbg-macro": [
|
|
54
|
+
bad(
|
|
55
|
+
"src/parse.rs",
|
|
56
|
+
"pub fn parse(input: &str) -> Vec<Token> {\n"
|
|
57
|
+
" let tokens = dbg!(lex(input)); // expect\n"
|
|
58
|
+
" tokens\n"
|
|
59
|
+
"}\n",
|
|
60
|
+
),
|
|
61
|
+
bad(
|
|
62
|
+
"src/lib.rs",
|
|
63
|
+
"#[cfg(test)]\n"
|
|
64
|
+
"mod tests {\n"
|
|
65
|
+
" #[test]\n"
|
|
66
|
+
" fn adds() {\n"
|
|
67
|
+
" dbg!(super::add(1, 2)); // expect\n"
|
|
68
|
+
" }\n"
|
|
69
|
+
"}\n",
|
|
70
|
+
note="dbg! is a leftover in tests too.",
|
|
71
|
+
),
|
|
72
|
+
good(
|
|
73
|
+
"src/parse.rs",
|
|
74
|
+
"pub fn parse(input: &str) -> Vec<Token> {\n"
|
|
75
|
+
" let tokens = lex(input);\n"
|
|
76
|
+
' log::debug!("tokens: {tokens:?}");\n'
|
|
77
|
+
" tokens\n"
|
|
78
|
+
"}\n",
|
|
79
|
+
),
|
|
80
|
+
good(
|
|
81
|
+
"src/help.rs",
|
|
82
|
+
'pub const HINT: &str = "use dbg!(value) to inspect a value";\n'
|
|
83
|
+
"// dbg!(x) was removed\n",
|
|
84
|
+
note="Inside a string or a comment it is only text.",
|
|
85
|
+
),
|
|
86
|
+
],
|
|
87
|
+
"rust/unsafe-block": [
|
|
88
|
+
bad(
|
|
89
|
+
"src/ffi.rs",
|
|
90
|
+
"pub fn pid() -> i32 {\n"
|
|
91
|
+
" unsafe { libc::getpid() } // expect\n"
|
|
92
|
+
"}\n",
|
|
93
|
+
),
|
|
94
|
+
bad(
|
|
95
|
+
"src/buf.rs",
|
|
96
|
+
"pub fn first(v: &[u8]) -> u8 {\n"
|
|
97
|
+
" // SAFETY: callers check that v is not empty.\n"
|
|
98
|
+
" let b = unsafe { // expect\n"
|
|
99
|
+
" *v.get_unchecked(0)\n"
|
|
100
|
+
" };\n"
|
|
101
|
+
" b\n"
|
|
102
|
+
"}\n",
|
|
103
|
+
note="A SAFETY comment helps the reviewer but every new block still needs one.",
|
|
104
|
+
),
|
|
105
|
+
good(
|
|
106
|
+
"src/buf.rs",
|
|
107
|
+
"pub fn first(v: &[u8]) -> Option<u8> {\n"
|
|
108
|
+
" v.first().copied()\n"
|
|
109
|
+
"}\n",
|
|
110
|
+
),
|
|
111
|
+
good(
|
|
112
|
+
"src/ffi.rs",
|
|
113
|
+
"/// Calls into C; see `unsafe { }` rules in CONTRIBUTING.\n"
|
|
114
|
+
"pub unsafe fn raw_pid() -> i32;\n"
|
|
115
|
+
"unsafe impl Send for Handle {}\n",
|
|
116
|
+
note="Declarations (unsafe fn, unsafe impl) are not blocks.",
|
|
117
|
+
),
|
|
118
|
+
],
|
|
119
|
+
"rust/unwrap": [
|
|
120
|
+
bad(
|
|
121
|
+
"src/config.rs",
|
|
122
|
+
"pub fn load(path: &Path) -> Config {\n"
|
|
123
|
+
" let text = fs::read_to_string(path).unwrap(); // expect\n"
|
|
124
|
+
" toml::from_str(&text).unwrap() // expect\n"
|
|
125
|
+
"}\n",
|
|
126
|
+
),
|
|
127
|
+
bad(
|
|
128
|
+
"src/server.rs",
|
|
129
|
+
"pub fn bind(addr: &str) -> TcpListener {\n"
|
|
130
|
+
" TcpListener::bind(addr)\n"
|
|
131
|
+
" .map_err(Error::from)\n"
|
|
132
|
+
" .unwrap() // expect\n"
|
|
133
|
+
"}\n",
|
|
134
|
+
note="A chained call on its own line.",
|
|
135
|
+
),
|
|
136
|
+
good(
|
|
137
|
+
"src/config.rs",
|
|
138
|
+
"pub fn load(path: &Path) -> Result<Config, Error> {\n"
|
|
139
|
+
" let text = fs::read_to_string(path)?;\n"
|
|
140
|
+
' let port = env::var("PORT").ok().and_then(|p| p.parse().ok()).unwrap_or(80);\n'
|
|
141
|
+
' let cfg = toml::from_str(&text).expect("config validated at startup");\n'
|
|
142
|
+
" Ok(cfg.with_port(port))\n"
|
|
143
|
+
"}\n"
|
|
144
|
+
"\n"
|
|
145
|
+
"#[cfg(test)]\n"
|
|
146
|
+
"mod tests {\n"
|
|
147
|
+
" #[test]\n"
|
|
148
|
+
" fn loads() {\n"
|
|
149
|
+
' super::load(Path::new("x.toml")).unwrap();\n'
|
|
150
|
+
" }\n"
|
|
151
|
+
"}\n",
|
|
152
|
+
note="unwrap_or, expect and test code are not reported.",
|
|
153
|
+
),
|
|
154
|
+
good(
|
|
155
|
+
"build.rs",
|
|
156
|
+
"fn main() {\n"
|
|
157
|
+
' let out = std::env::var("OUT_DIR").unwrap();\n'
|
|
158
|
+
' println!("cargo:rerun-if-changed={out}");\n'
|
|
159
|
+
"}\n",
|
|
160
|
+
note="A build script fails the build visibly; unwrap is the idiom there.",
|
|
161
|
+
),
|
|
162
|
+
],
|
|
163
|
+
"rust/panic": [
|
|
164
|
+
bad(
|
|
165
|
+
"src/pool.rs",
|
|
166
|
+
"pub fn get(&self, id: usize) -> &Conn {\n"
|
|
167
|
+
" match self.conns.get(id) {\n"
|
|
168
|
+
" Some(c) => c,\n"
|
|
169
|
+
' None => panic!("no connection {id}"), // expect\n'
|
|
170
|
+
" }\n"
|
|
171
|
+
"}\n",
|
|
172
|
+
),
|
|
173
|
+
bad(
|
|
174
|
+
"src/codec.rs",
|
|
175
|
+
"fn decode(b: u8) -> Kind {\n"
|
|
176
|
+
" if b > 3 {\n"
|
|
177
|
+
' panic!["bad kind byte"]; // expect\n'
|
|
178
|
+
" }\n"
|
|
179
|
+
" KINDS[b as usize]\n"
|
|
180
|
+
"}\n",
|
|
181
|
+
),
|
|
182
|
+
good(
|
|
183
|
+
"src/pool.rs",
|
|
184
|
+
"pub fn get(&self, id: usize) -> Result<&Conn, PoolError> {\n"
|
|
185
|
+
" self.conns.get(id).ok_or(PoolError::Missing(id))\n"
|
|
186
|
+
"}\n"
|
|
187
|
+
"\n"
|
|
188
|
+
"#[cfg(test)]\n"
|
|
189
|
+
"mod tests {\n"
|
|
190
|
+
" #[test]\n"
|
|
191
|
+
" #[should_panic]\n"
|
|
192
|
+
" fn missing() {\n"
|
|
193
|
+
' panic!("expected");\n'
|
|
194
|
+
" }\n"
|
|
195
|
+
"}\n",
|
|
196
|
+
),
|
|
197
|
+
good(
|
|
198
|
+
"examples/demo.rs",
|
|
199
|
+
"fn main() {\n"
|
|
200
|
+
' let arg = std::env::args().nth(1).unwrap_or_else(|| panic!("usage: demo FILE"));\n'
|
|
201
|
+
' println!("{arg}");\n'
|
|
202
|
+
"}\n",
|
|
203
|
+
note="Examples are small programs; panicking on bad input is fine there.",
|
|
204
|
+
),
|
|
205
|
+
],
|
|
206
|
+
"rust/transmute": [
|
|
207
|
+
bad(
|
|
208
|
+
"src/bits.rs",
|
|
209
|
+
"pub fn to_bits(x: f32) -> u32 {\n"
|
|
210
|
+
" unsafe { std::mem::transmute(x) } // expect\n"
|
|
211
|
+
"}\n",
|
|
212
|
+
),
|
|
213
|
+
bad(
|
|
214
|
+
"src/handle.rs",
|
|
215
|
+
"pub fn from_raw(p: *const u8) -> &'static Header {\n"
|
|
216
|
+
" unsafe { mem::transmute::<*const u8, &Header>(p) } // expect\n"
|
|
217
|
+
"}\n",
|
|
218
|
+
note="Turbofish form; a pointer cast to a reference with an invented lifetime.",
|
|
219
|
+
),
|
|
220
|
+
good(
|
|
221
|
+
"src/bits.rs",
|
|
222
|
+
"pub fn to_bits(x: f32) -> u32 {\n"
|
|
223
|
+
" x.to_bits()\n"
|
|
224
|
+
"}\n",
|
|
225
|
+
),
|
|
226
|
+
good(
|
|
227
|
+
"src/docs.rs",
|
|
228
|
+
"/// Never use `mem::transmute(x)` for this; see to_bits.\n"
|
|
229
|
+
"pub fn transmuted_count(xs: &[Item]) -> usize {\n"
|
|
230
|
+
" xs.iter().filter(|x| x.transmuted).count()\n"
|
|
231
|
+
"}\n",
|
|
232
|
+
note="Comments and names that only contain the word are not calls.",
|
|
233
|
+
),
|
|
234
|
+
],
|
|
235
|
+
"rust/allow-attribute": [
|
|
236
|
+
bad(
|
|
237
|
+
"src/lib.rs",
|
|
238
|
+
"#![allow(dead_code)] // expect\n"
|
|
239
|
+
"\n"
|
|
240
|
+
"pub mod api;\n",
|
|
241
|
+
note="A crate-wide allow hides every unused item.",
|
|
242
|
+
),
|
|
243
|
+
bad(
|
|
244
|
+
"src/api.rs",
|
|
245
|
+
"#[allow(clippy::too_many_arguments)] // expect\n"
|
|
246
|
+
"pub fn create(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8, g: u8, h: u8) {}\n",
|
|
247
|
+
),
|
|
248
|
+
good(
|
|
249
|
+
"src/api.rs",
|
|
250
|
+
'#[expect(clippy::too_many_arguments, reason = "mirrors the C API")]\n'
|
|
251
|
+
"pub fn create(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8, g: u8, h: u8) {}\n",
|
|
252
|
+
note="#[expect] warns once the lint no longer fires, so it is not reported.",
|
|
253
|
+
),
|
|
254
|
+
good(
|
|
255
|
+
"src/lib.rs",
|
|
256
|
+
"#![deny(missing_docs)]\n"
|
|
257
|
+
'//! Use `#[allow(...)]` sparingly.\n'
|
|
258
|
+
"pub mod api;\n",
|
|
259
|
+
),
|
|
260
|
+
good(
|
|
261
|
+
"src/ffi.rs",
|
|
262
|
+
"#[allow(non_camel_case_types)]\npub type c_int = i32;\n\n"
|
|
263
|
+
"#[allow(non_snake_case, non_upper_case_globals)]\n"
|
|
264
|
+
"pub struct stat { pub st_mode: u32 }\n",
|
|
265
|
+
note="FFI bindings allow naming lints to keep C's names.",
|
|
266
|
+
),
|
|
267
|
+
],
|
|
268
|
+
}
|