-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinter_rules.yaml
More file actions
425 lines (367 loc) · 12.4 KB
/
Copy pathlinter_rules.yaml
File metadata and controls
425 lines (367 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# =============================================================================
# Embedded AI Linter Rules
# Based on JSF AV C++ Coding Standards (Doc. No. 2RDU00001 Rev C)
# Simplified for embedded AI / edge deployment contexts
#
# Each rule has:
# enabled: true/false to toggle the rule
# severity: "error" | "warning" | "info"
# jsf_ref: original JSF AV Rule number(s) for traceability
# params: rule-specific thresholds or configuration
# =============================================================================
meta:
name: "Embedded AI Linter"
version: "1.0.0"
description: >
Simplified JSF AV rules adapted for safety-aware embedded C++ code
used in the Embedded AI book projects.
file_extensions: [".cpp", ".h", ".hpp", ".c"]
# ---------------------------------------------------------------------------
# Category 1: Code Size and Complexity
# ---------------------------------------------------------------------------
complexity:
max_function_length:
enabled: true
severity: warning
jsf_ref: "AV Rule 1"
params:
max_lines: 100 # JSF allows 200; tightened for book examples
description: "Function bodies shall not exceed the configured line limit."
max_function_args:
enabled: true
severity: warning
jsf_ref: "AV Rule 110"
params:
max_args: 6 # JSF allows 7
description: "Functions shall not have more than the configured number of parameters."
max_line_length:
enabled: true
severity: info
jsf_ref: "AV Rule 41"
params:
max_chars: 100 # JSF allows 120; tightened for book formatting
description: "Source lines shall not exceed the configured character limit."
# ---------------------------------------------------------------------------
# Category 2: Prohibited Language Features
# ---------------------------------------------------------------------------
prohibited_features:
no_goto:
enabled: true
severity: error
jsf_ref: "AV Rule 189"
pattern: "\\bgoto\\b"
description: "The goto statement shall not be used."
no_continue:
enabled: true
severity: error
jsf_ref: "AV Rule 190"
pattern: "\\bcontinue\\b"
description: "The continue statement shall not be used."
no_exceptions:
enabled: true
severity: error
jsf_ref: "AV Rule 208"
patterns:
- "\\bthrow\\b"
- "\\bcatch\\b"
- "\\btry\\b"
description: "C++ exceptions (throw, catch, try) shall not be used."
no_unions:
enabled: true
severity: error
jsf_ref: "AV Rule 153"
pattern: "\\bunion\\b"
description: "Unions shall not be used."
no_comma_operator:
enabled: true
severity: error
jsf_ref: "AV Rule 168"
description: "The comma operator shall not be used (excluding for-loop init and function args)."
no_errno:
enabled: true
severity: warning
jsf_ref: "AV Rule 17"
pattern: "\\berrno\\b"
description: "The error indicator errno shall not be used."
no_setjmp_longjmp:
enabled: true
severity: error
jsf_ref: "AV Rule 20"
patterns:
- "\\bsetjmp\\b"
- "\\blongjmp\\b"
description: "setjmp and longjmp shall not be used."
no_signal_h:
enabled: true
severity: error
jsf_ref: "AV Rule 21"
pattern: "<signal\\.h>|<csignal>"
description: "The signal handling facilities shall not be used."
no_stdio:
enabled: false # Disabled: book examples use printf for demonstration
severity: warning
jsf_ref: "AV Rule 22"
pattern: "<stdio\\.h>|<cstdio>"
description: "The I/O library stdio.h shall not be used."
no_atoi_atof:
enabled: true
severity: warning
jsf_ref: "AV Rule 23"
patterns:
- "\\batof\\b"
- "\\batoi\\b"
- "\\batol\\b"
description: "atof, atoi, and atol shall not be used."
no_abort_exit:
enabled: true
severity: error
jsf_ref: "AV Rule 24"
patterns:
- "\\babort\\s*\\("
- "(?<!_)exit\\s*\\("
- "\\bgetenv\\s*\\("
- "\\bsystem\\s*\\("
description: "abort, exit, getenv, and system shall not be used."
no_recursion:
enabled: true
severity: warning
jsf_ref: "AV Rule 119"
description: "Functions shall not call themselves directly or indirectly."
no_register:
enabled: true
severity: info
jsf_ref: "AV Rule 140"
pattern: "\\bregister\\b"
description: "The register storage class specifier shall not be used."
no_pointer_arithmetic:
enabled: true
severity: warning
jsf_ref: "AV Rule 215"
description: "Pointer arithmetic should be avoided. Use array indexing or iterators."
# ---------------------------------------------------------------------------
# Category 3: Type Safety
# ---------------------------------------------------------------------------
type_safety:
no_raw_int_types:
enabled: true
severity: warning
jsf_ref: "AV Rule 209"
patterns:
- "(?<!\\w)\\bint\\b(?!\\w|_t|8|16|32|64)"
- "(?<!\\w)\\bshort\\b(?!\\w)"
- "(?<!\\w)\\blong\\b(?!\\w)"
description: >
Basic types int, short, long shall not be used directly.
Use fixed-width types: int8_t, int16_t, int32_t, uint8_t, etc.
no_c_style_casts:
enabled: true
severity: error
jsf_ref: "AV Rule 185"
description: >
C++ style casts (static_cast, reinterpret_cast, const_cast) shall be
used instead of C-style casts.
no_implicit_narrowing:
enabled: true
severity: warning
jsf_ref: "AV Rule 180"
description: "Implicit conversions that may lose information shall not be used."
no_octal_constants:
enabled: true
severity: error
jsf_ref: "AV Rule 149"
pattern: "(?<!\\.)\\b0[0-7]+\\b"
description: "Octal constants (other than zero) shall not be used."
hex_uppercase:
enabled: true
severity: info
jsf_ref: "AV Rule 150"
pattern: "0x[0-9a-fA-F]*[a-f][0-9a-fA-F]*"
description: "Hexadecimal constants shall use uppercase letters."
literal_suffix_uppercase:
enabled: true
severity: info
jsf_ref: "AV Rule 14"
pattern: "\\d+[uUlLfF]*[ul]"
description: "Literal suffixes shall use uppercase letters (e.g. 1U, 2.0F, 3L)."
# ---------------------------------------------------------------------------
# Category 4: Memory and Resource Safety
# ---------------------------------------------------------------------------
memory_safety:
no_dynamic_alloc_after_init:
enabled: true
severity: error
jsf_ref: "AV Rule 206"
description: >
Allocation/deallocation from the free store (heap) shall not occur
after initialization. Use static allocation or memory pools.
no_malloc_free:
enabled: true
severity: error
jsf_ref: "AV Rule 206"
patterns:
- "\\bmalloc\\s*\\("
- "\\bfree\\s*\\("
- "\\bcalloc\\s*\\("
- "\\brealloc\\s*\\("
description: "C-style memory allocation (malloc/free/calloc/realloc) shall not be used."
no_raw_new_delete:
enabled: true
severity: warning
jsf_ref: "AV Rule 206"
patterns:
- "(?<!operator)\\bnew\\b"
- "(?<!operator)\\bdelete\\b"
description: >
Raw new/delete should be avoided outside initialization.
Prefer RAII, containers, or static allocation.
volatile_only_for_hardware:
enabled: true
severity: warning
jsf_ref: "AV Rule 205"
pattern: "\\bvolatile\\b"
description: >
The volatile keyword shall only be used when directly interfacing
with hardware registers. Flag for manual review.
# ---------------------------------------------------------------------------
# Category 5: Control Flow
# ---------------------------------------------------------------------------
control_flow:
braces_required:
enabled: true
severity: error
jsf_ref: "AV Rule 59"
description: >
The body of if, else if, else, while, do-while, and for statements
shall always be enclosed in braces.
switch_default_required:
enabled: true
severity: warning
jsf_ref: "AV Rule 194"
description: "All switch statements shall contain a default case."
switch_break_required:
enabled: true
severity: error
jsf_ref: "AV Rule 193"
description: "Every non-empty case in a switch shall be terminated with break."
no_float_loop_counter:
enabled: true
severity: error
jsf_ref: "AV Rule 197"
pattern: "for\\s*\\([^)]*(?:float|double)[^)]*;"
description: "Floating-point variables shall not be used as loop counters."
no_float_exact_compare:
enabled: true
severity: error
jsf_ref: "AV Rule 202"
description: "Floating-point values shall not be tested for exact equality."
single_return:
enabled: false # Disabled: modern embedded style permits early returns
severity: info
jsf_ref: "AV Rule 113"
description: "Functions should have a single exit point."
# ---------------------------------------------------------------------------
# Category 6: Style and Naming
# ---------------------------------------------------------------------------
style:
no_tabs:
enabled: true
severity: info
jsf_ref: "AV Rule 43"
description: "Tab characters should not be used for indentation."
no_magic_numbers:
enabled: true
severity: warning
jsf_ref: "AV Rule 151"
description: >
Numeric literals (other than 0 and 1) shall not appear in code.
Use named constants or constexpr.
params:
allowed_values: [0, 1, 2, -1]
one_declaration_per_line:
enabled: true
severity: warning
jsf_ref: "AV Rule 152"
description: "Multiple variable declarations shall not appear on the same line."
no_commented_out_code:
enabled: true
severity: warning
jsf_ref: "AV Rule 127"
description: "Commented-out code shall be deleted."
no_identifier_leading_underscore:
enabled: true
severity: warning
jsf_ref: "AV Rule 47"
pattern: "(?:int|float|double|char|bool|auto|void|const|static|unsigned|signed|uint\\d+_t|int\\d+_t|size_t)\\s+_\\w+"
description: "Identifiers shall not begin with an underscore."
include_guard_required:
enabled: true
severity: error
jsf_ref: "AV Rule 27, 35"
description: "Header files shall use #ifndef/#define/#endif include guards."
cpp_comments_only:
enabled: true
severity: info
jsf_ref: "AV Rule 126"
description: "Only C++ style comments (//) shall be used."
# ---------------------------------------------------------------------------
# Category 7: Class Design
# ---------------------------------------------------------------------------
classes:
virtual_destructor_required:
enabled: true
severity: error
jsf_ref: "AV Rule 78"
description: "All base classes with a virtual function shall define a virtual destructor."
explicit_constructors:
enabled: true
severity: warning
jsf_ref: "AV Rule 177"
description: >
Single-argument constructors should be marked explicit to prevent
implicit conversions.
no_public_data_in_classes:
enabled: true
severity: warning
jsf_ref: "AV Rule 67"
description: "Public data members should only be used in structs, not classes."
# ---------------------------------------------------------------------------
# Category 8: Embedded / Safety Specific
# ---------------------------------------------------------------------------
embedded:
no_endian_assumptions:
enabled: true
severity: warning
jsf_ref: "AV Rule 210"
description: >
Algorithms shall not make assumptions about byte ordering.
Flag casts between pointer types and integer types for review.
no_uninitialized_variables:
enabled: true
severity: error
jsf_ref: "AV Rule 142"
description: "All variables shall be initialized before use."
no_unreachable_code:
enabled: true
severity: warning
jsf_ref: "AV Rule 186"
description: "There shall be no unreachable code."
define_only_for_guards:
enabled: true
severity: warning
jsf_ref: "AV Rule 29, 30, 31"
description: >
The #define directive shall only be used for include guards.
Use constexpr for constants, inline functions for macros.
# ---------------------------------------------------------------------------
# Suppressions
# ---------------------------------------------------------------------------
suppressions:
# Inline suppression comment marker.
# Place "// NOLINT(rule_name)" at end of line to suppress.
inline_marker: "NOLINT"
# Files or directories to exclude from linting entirely.
excluded_paths:
- "third_party/"
- "vendor/"
- "test/"
- "build/"