jarbin-c-coding-style 2.0.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 (186) hide show
  1. jarbin_c_coding_style-2.0.0.dist-info/METADATA +150 -0
  2. jarbin_c_coding_style-2.0.0.dist-info/RECORD +186 -0
  3. jarbin_c_coding_style-2.0.0.dist-info/WHEEL +4 -0
  4. jarbin_c_coding_style-2.0.0.dist-info/entry_points.txt +2 -0
  5. jarbin_c_coding_style-2.0.0.dist-info/licenses/LICENSE +674 -0
  6. sources/__init__.py +0 -0
  7. sources/__main__.py +6 -0
  8. sources/analysis/__init__.py +0 -0
  9. sources/analysis/directives.py +258 -0
  10. sources/analysis/lexer.py +288 -0
  11. sources/analysis/parser.py +1754 -0
  12. sources/analysis/project.py +286 -0
  13. sources/analysis/source.py +326 -0
  14. sources/analysis/syntax.py +238 -0
  15. sources/analysis/tokens.py +116 -0
  16. sources/analysis/unit.py +700 -0
  17. sources/application.py +118 -0
  18. sources/build_info.json +6 -0
  19. sources/cli/__init__.py +0 -0
  20. sources/cli/arguments.py +507 -0
  21. sources/cli/completion.py +610 -0
  22. sources/cli/context.py +258 -0
  23. sources/cli/converters.py +204 -0
  24. sources/cli/help.py +162 -0
  25. sources/cli/parser.py +659 -0
  26. sources/configs/__init__.py +0 -0
  27. sources/configs/editor.py +207 -0
  28. sources/configs/ini.py +327 -0
  29. sources/configs/project.py +735 -0
  30. sources/configs/schema/__init__.py +0 -0
  31. sources/configs/schema/project.py +68 -0
  32. sources/constants.py +801 -0
  33. sources/diagnostics/__init__.py +0 -0
  34. sources/diagnostics/fingerprint.py +82 -0
  35. sources/diagnostics/model.py +146 -0
  36. sources/engine/__init__.py +0 -0
  37. sources/engine/api.py +355 -0
  38. sources/engine/examples.py +157 -0
  39. sources/engine/outcome.py +114 -0
  40. sources/engine/plan.py +440 -0
  41. sources/engine/runner.py +345 -0
  42. sources/engine/scanner.py +179 -0
  43. sources/enums.py +838 -0
  44. sources/errors/__init__.py +0 -0
  45. sources/errors/exceptions.py +727 -0
  46. sources/fixers/__init__.py +0 -0
  47. sources/fixers/base.py +209 -0
  48. sources/fixers/conflicts.py +129 -0
  49. sources/fixers/diff.py +73 -0
  50. sources/fixers/engine.py +434 -0
  51. sources/fixers/journal.py +290 -0
  52. sources/fixers/kinds.py +30 -0
  53. sources/fixers/layout.py +411 -0
  54. sources/fixers/model.py +151 -0
  55. sources/fixers/registry.py +54 -0
  56. sources/fixers/text.py +353 -0
  57. sources/fixers/verify.py +123 -0
  58. sources/fixers/writer.py +88 -0
  59. sources/integrations/__init__.py +0 -0
  60. sources/integrations/ci/__init__.py +0 -0
  61. sources/integrations/ci/github.py +183 -0
  62. sources/integrations/editors/__init__.py +0 -0
  63. sources/integrations/git/__init__.py +0 -0
  64. sources/integrations/git/repository.py +176 -0
  65. sources/integrations/update/__init__.py +0 -0
  66. sources/integrations/update/installers.py +529 -0
  67. sources/integrations/update/releases.py +397 -0
  68. sources/integrations/update/state.py +143 -0
  69. sources/outputs/__init__.py +0 -0
  70. sources/outputs/github/__init__.py +0 -0
  71. sources/outputs/github/renderer.py +135 -0
  72. sources/outputs/html/__init__.py +0 -0
  73. sources/outputs/html/renderer.py +694 -0
  74. sources/outputs/json/__init__.py +0 -0
  75. sources/outputs/json/renderer.py +154 -0
  76. sources/outputs/json/report.schema.json +121 -0
  77. sources/outputs/junit/__init__.py +0 -0
  78. sources/outputs/junit/renderer.py +151 -0
  79. sources/outputs/registry.py +135 -0
  80. sources/outputs/report.py +224 -0
  81. sources/outputs/sarif/__init__.py +0 -0
  82. sources/outputs/sarif/renderer.py +182 -0
  83. sources/outputs/terminal/__init__.py +0 -0
  84. sources/outputs/terminal/renderer.py +184 -0
  85. sources/outputs/terminal/style.py +159 -0
  86. sources/rules/__init__.py +0 -0
  87. sources/rules/arguments.py +362 -0
  88. sources/rules/catalog.py +227 -0
  89. sources/rules/categories/advanced/constant_pointers.ini +46 -0
  90. sources/rules/categories/advanced/line_break_at_end_of_file.ini +44 -0
  91. sources/rules/categories/advanced/static.ini +65 -0
  92. sources/rules/categories/advanced/typing.ini +47 -0
  93. sources/rules/categories/control_structures/conditional_branching.ini +89 -0
  94. sources/rules/categories/control_structures/goto.ini +45 -0
  95. sources/rules/categories/control_structures/ternary_operators.ini +57 -0
  96. sources/rules/categories/extensions/language_extensions.ini +71 -0
  97. sources/rules/categories/files_organization/contents_of_the_repository.ini +85 -0
  98. sources/rules/categories/files_organization/file_coherence.ini +166 -0
  99. sources/rules/categories/files_organization/file_extension.ini +68 -0
  100. sources/rules/categories/files_organization/fixtures/program +0 -0
  101. sources/rules/categories/files_organization/naming_files_and_folders.ini +74 -0
  102. sources/rules/categories/functions/coherence_of_functions.ini +45 -0
  103. sources/rules/categories/functions/comments_inside_a_function.ini +45 -0
  104. sources/rules/categories/functions/functions_without_parameters.ini +39 -0
  105. sources/rules/categories/functions/naming_functions.ini +79 -0
  106. sources/rules/categories/functions/number_of_columns.ini +61 -0
  107. sources/rules/categories/functions/number_of_lines.ini +70 -0
  108. sources/rules/categories/functions/number_of_parameters.ini +64 -0
  109. sources/rules/categories/functions/structures_as_parameters.ini +44 -0
  110. sources/rules/categories/global_scope/constant_values.ini +49 -0
  111. sources/rules/categories/global_scope/file_header.ini +92 -0
  112. sources/rules/categories/global_scope/global_variables.ini +53 -0
  113. sources/rules/categories/global_scope/include.ini +39 -0
  114. sources/rules/categories/global_scope/indentation_of_preprocessor.ini +62 -0
  115. sources/rules/categories/global_scope/inline_assembly.ini +43 -0
  116. sources/rules/categories/global_scope/leading_trailing_lines.ini +58 -0
  117. sources/rules/categories/global_scope/line_endings.ini +53 -0
  118. sources/rules/categories/global_scope/separation_of_functions.ini +61 -0
  119. sources/rules/categories/global_scope/trailing_spaces.ini +45 -0
  120. sources/rules/categories/header_files/content.ini +104 -0
  121. sources/rules/categories/header_files/include_guard.ini +47 -0
  122. sources/rules/categories/header_files/macros.ini +57 -0
  123. sources/rules/categories/layout_inside_a_function_scope/blank_lines.ini +71 -0
  124. sources/rules/categories/layout_inside_a_function_scope/code_line_content.ini +112 -0
  125. sources/rules/categories/layout_inside_a_function_scope/curly_brackets.ini +94 -0
  126. sources/rules/categories/layout_inside_a_function_scope/indentation.ini +96 -0
  127. sources/rules/categories/layout_inside_a_function_scope/spaces.ini +113 -0
  128. sources/rules/categories/layout_inside_a_function_scope/variable_declarations.ini +65 -0
  129. sources/rules/categories/variables_and_types/naming_identifiers.ini +74 -0
  130. sources/rules/categories/variables_and_types/pointers.ini +67 -0
  131. sources/rules/categories/variables_and_types/structures.ini +47 -0
  132. sources/rules/data/verbs.txt +182 -0
  133. sources/rules/definition.py +430 -0
  134. sources/rules/loader.py +925 -0
  135. sources/rules/paths.py +6 -0
  136. sources/rules/primitives/__init__.py +0 -0
  137. sources/rules/primitives/base.py +297 -0
  138. sources/rules/primitives/braces.py +211 -0
  139. sources/rules/primitives/directives.py +203 -0
  140. sources/rules/primitives/indentation.py +376 -0
  141. sources/rules/primitives/layout.py +199 -0
  142. sources/rules/primitives/naming.py +277 -0
  143. sources/rules/primitives/project.py +62 -0
  144. sources/rules/primitives/registry.py +49 -0
  145. sources/rules/primitives/repository.py +129 -0
  146. sources/rules/primitives/review.py +87 -0
  147. sources/rules/primitives/semantic.py +319 -0
  148. sources/rules/primitives/spacing.py +210 -0
  149. sources/rules/primitives/structure.py +586 -0
  150. sources/rules/primitives/syntax.py +200 -0
  151. sources/rules/primitives/text.py +408 -0
  152. sources/rules/primitives/tokens.py +84 -0
  153. sources/rules/template.py +138 -0
  154. sources/selftest/__init__.py +0 -0
  155. sources/selftest/cases.py +292 -0
  156. sources/services.py +90 -0
  157. sources/subcommands/__init__.py +0 -0
  158. sources/subcommands/base.py +45 -0
  159. sources/subcommands/check/__init__.py +0 -0
  160. sources/subcommands/check/command.py +45 -0
  161. sources/subcommands/check/fixing.py +224 -0
  162. sources/subcommands/check/handler.py +757 -0
  163. sources/subcommands/info/__init__.py +0 -0
  164. sources/subcommands/info/command.py +45 -0
  165. sources/subcommands/info/handler.py +527 -0
  166. sources/subcommands/registry.py +37 -0
  167. sources/subcommands/rule/__init__.py +0 -0
  168. sources/subcommands/rule/command.py +45 -0
  169. sources/subcommands/rule/handler.py +1067 -0
  170. sources/subcommands/rule/render.py +273 -0
  171. sources/subcommands/runner.py +124 -0
  172. sources/subcommands/test/__init__.py +0 -0
  173. sources/subcommands/test/command.py +45 -0
  174. sources/subcommands/test/handler.py +166 -0
  175. sources/subcommands/test/render.py +219 -0
  176. sources/subcommands/test/runner.py +430 -0
  177. sources/subcommands/update/__init__.py +0 -0
  178. sources/subcommands/update/command.py +45 -0
  179. sources/subcommands/update/handler.py +408 -0
  180. sources/utils/__init__.py +0 -0
  181. sources/utils/build_info.py +188 -0
  182. sources/utils/git.py +73 -0
  183. sources/utils/globs.py +98 -0
  184. sources/utils/logging.py +154 -0
  185. sources/utils/schema.py +77 -0
  186. sources/utils/versions.py +87 -0
@@ -0,0 +1,430 @@
1
+ import re
2
+ from collections.abc import Mapping
3
+ from dataclasses import dataclass
4
+ from typing import Any
5
+
6
+ from sources.enums import (
7
+ BananaSupport,
8
+ CodeContext,
9
+ Detection,
10
+ ExampleKind,
11
+ FileKind,
12
+ FixApplicability,
13
+ NodeKind,
14
+ ReportMode,
15
+ RuleStatus,
16
+ SeverityLevel,
17
+ StorageFilter,
18
+ )
19
+ from sources.rules.arguments import ArgumentSpec
20
+
21
+
22
+ @dataclass(frozen=True, slots=True)
23
+ class EpitechInfo:
24
+ """
25
+ `[epitech]` section of a rule: link to the official coding style.
26
+ (dataclass)
27
+
28
+ Attributes
29
+ ----------
30
+ ref : str | None
31
+ Official reference, e.g. "C-L3".
32
+ version : int | None
33
+ Coding-style document version the rule implements.
34
+ banana : BananaSupport | None
35
+ Support level of the official checker.
36
+ manual_part : str
37
+ What remains to be checked by a human.
38
+ """
39
+
40
+ ref: str | None = None
41
+ version: int | None = None
42
+ banana: BananaSupport | None = None
43
+ manual_part: str = ""
44
+
45
+
46
+ @dataclass(frozen=True, slots=True)
47
+ class Selection:
48
+ """
49
+ `target` and `where.*` keys of a check (plan 03, section 6.2).
50
+ (dataclass)
51
+
52
+ Attributes
53
+ ----------
54
+ target : str | None
55
+ What the check looks at (primitive-specific), or None for the primitive default.
56
+ file_kinds : frozenset[FileKind]
57
+ `where.file_kind` (empty: no restriction besides `applies_to`).
58
+ contexts : frozenset[CodeContext]
59
+ `where.context`: the item must be in at least one of them (empty: no restriction).
60
+ not_contexts : frozenset[CodeContext] | None
61
+ `where.not_context`: the item must be in none of them (None: primitive default).
62
+ nodes : frozenset[NodeKind]
63
+ `where.node`: accepted node kinds (empty: no restriction).
64
+ name : re.Pattern[str] | None
65
+ `where.name`: regular expression searched in the item name.
66
+ storage : StorageFilter | None
67
+ `where.storage`: storage class filter.
68
+ """
69
+
70
+ target: str | None = None
71
+ file_kinds: frozenset[FileKind] = frozenset()
72
+ contexts: frozenset[CodeContext] = frozenset()
73
+ not_contexts: frozenset[CodeContext] | None = None
74
+ nodes: frozenset[NodeKind] = frozenset()
75
+ name: re.Pattern[str] | None = None
76
+ storage: StorageFilter | None = None
77
+
78
+ def storage_matches(self, storage: frozenset[str]) -> bool:
79
+ """
80
+ Whether a set of storage specifiers passes `where.storage`.
81
+
82
+ Parameters
83
+ ----------
84
+ storage : frozenset[str]
85
+ Storage specifiers of the item.
86
+
87
+ Returns
88
+ ----------
89
+ bool
90
+ True when accepted.
91
+ """
92
+ match self.storage:
93
+ case None:
94
+ return True
95
+ case StorageFilter.STATIC:
96
+ return "static" in storage
97
+ case StorageFilter.EXTERN:
98
+ return "extern" in storage
99
+ case StorageFilter.NONE:
100
+ return not storage & {"static", "extern"}
101
+ case StorageFilter.NOT_STATIC:
102
+ return "static" not in storage
103
+ return True
104
+
105
+ def name_matches(self, name: str | None) -> bool:
106
+ """
107
+ Whether a name passes `where.name`.
108
+
109
+ Parameters
110
+ ----------
111
+ name : str | None
112
+ Name of the item.
113
+
114
+ Returns
115
+ ----------
116
+ bool
117
+ True when accepted (items without name fail a name filter).
118
+ """
119
+ if self.name is None:
120
+ return True
121
+ return name is not None and self.name.search(name) is not None
122
+
123
+ def contexts_match(self, contexts: frozenset[CodeContext], default_excluded: frozenset[CodeContext]) -> bool:
124
+ """
125
+ Whether the contexts of an item pass `where.context` and `where.not_context`.
126
+
127
+ Parameters
128
+ ----------
129
+ contexts : frozenset[CodeContext]
130
+ Contexts of the item.
131
+ default_excluded : frozenset[CodeContext]
132
+ Contexts excluded when `where.not_context` is not set.
133
+
134
+ Returns
135
+ ----------
136
+ bool
137
+ True when accepted.
138
+ """
139
+ excluded: frozenset[CodeContext] = default_excluded if self.not_contexts is None else self.not_contexts
140
+ if contexts & excluded:
141
+ return False
142
+ return not self.contexts or bool(contexts & self.contexts)
143
+
144
+
145
+ @dataclass(frozen=True, slots=True)
146
+ class ParameterValue:
147
+ """
148
+ Value of one primitive parameter in a `[check:*]` section.
149
+ (dataclass)
150
+
151
+ Attributes
152
+ ----------
153
+ key : str
154
+ Parameter key.
155
+ raw : str
156
+ Value as written.
157
+ line : int
158
+ 1-based line in the rule file.
159
+ reference : str | None
160
+ Name of the argument for `@argument` values, else None.
161
+ value : Any
162
+ Coerced literal value (None for references).
163
+ """
164
+
165
+ key: str
166
+ raw: str
167
+ line: int
168
+ reference: str | None
169
+ value: Any
170
+
171
+
172
+ @dataclass(frozen=True, slots=True)
173
+ class CheckDefinition:
174
+ """
175
+ One `[check:<id>]` section.
176
+ (dataclass)
177
+
178
+ Attributes
179
+ ----------
180
+ id : str
181
+ Check identifier.
182
+ kind : str
183
+ Primitive name.
184
+ description : str
185
+ Human-readable description.
186
+ severity : SeverityLevel | None
187
+ Severity override (None: the rule severity).
188
+ detection : Detection | None
189
+ Detection override (None: the rule detection).
190
+ applies_to : frozenset[FileKind] | None
191
+ File kinds override (None: the rule file kinds).
192
+ selection : Selection
193
+ `target` and `where.*` keys.
194
+ parameters : Mapping[str, ParameterValue]
195
+ Primitive parameters, by key.
196
+ report : ReportMode
197
+ Report granularity.
198
+ message : str
199
+ Message template ("" for the primitive default).
200
+ fix : FixApplicability
201
+ Fix applicability.
202
+ fix_kind : str | None
203
+ Fix primitive (plan 07).
204
+ line : int
205
+ 1-based line of the section header.
206
+ """
207
+
208
+ id: str
209
+ kind: str
210
+ description: str
211
+ severity: SeverityLevel | None
212
+ detection: Detection | None
213
+ applies_to: frozenset[FileKind] | None
214
+ selection: Selection
215
+ parameters: Mapping[str, ParameterValue]
216
+ report: ReportMode
217
+ message: str
218
+ fix: FixApplicability
219
+ fix_kind: str | None
220
+ line: int
221
+
222
+
223
+ @dataclass(frozen=True, slots=True)
224
+ class ExpectedFinding:
225
+ """
226
+ One `<path>:<line>:<column>:<check_id>` entry of an example `expect` list.
227
+ (dataclass)
228
+
229
+ Attributes
230
+ ----------
231
+ path : str
232
+ File of the finding.
233
+ line : int
234
+ 1-based line.
235
+ column : int
236
+ 1-based column.
237
+ check : str
238
+ Check identifier.
239
+ """
240
+
241
+ path: str
242
+ line: int
243
+ column: int
244
+ check: str
245
+
246
+ def __str__(self) -> str:
247
+ """
248
+ Render the entry as written in rule files.
249
+
250
+ Returns
251
+ ----------
252
+ str
253
+ "path:line:column:check".
254
+ """
255
+ return f"{self.path}:{self.line}:{self.column}:{self.check}"
256
+
257
+
258
+ @dataclass(frozen=True, slots=True)
259
+ class ExampleFile:
260
+ """
261
+ One file of an example project.
262
+ (dataclass)
263
+
264
+ Attributes
265
+ ----------
266
+ path : str
267
+ Relative path inside the example project.
268
+ content : bytes
269
+ Exact content.
270
+ """
271
+
272
+ path: str
273
+ content: bytes
274
+
275
+
276
+ @dataclass(frozen=True, slots=True)
277
+ class ExampleDefinition:
278
+ """
279
+ One `[example:<id>]` with its files.
280
+ (dataclass)
281
+
282
+ Attributes
283
+ ----------
284
+ id : str
285
+ Example identifier.
286
+ kind : ExampleKind
287
+ good or bad.
288
+ description : str
289
+ Human-readable description.
290
+ expect : tuple[ExpectedFinding, ...]
291
+ Findings the example must produce (review items included).
292
+ files : tuple[ExampleFile, ...]
293
+ Files of the example project.
294
+ """
295
+
296
+ id: str
297
+ kind: ExampleKind
298
+ description: str
299
+ expect: tuple[ExpectedFinding, ...]
300
+ files: tuple[ExampleFile, ...]
301
+
302
+
303
+ @dataclass(frozen=True, slots=True)
304
+ class RuleDefinition:
305
+ """
306
+ A rule loaded from its `.ini` file (schema 2).
307
+ (dataclass)
308
+
309
+ Attributes
310
+ ----------
311
+ id : str
312
+ `<category>/<name>`.
313
+ category : str
314
+ Category directory.
315
+ name : str
316
+ Rule name.
317
+ source : str
318
+ File the rule was loaded from.
319
+ builtin : bool
320
+ Whether the rule ships with JCCS.
321
+ code : str
322
+ Code shown in reports (`code`, else the Epitech reference, else the ID).
323
+ title : str
324
+ Short title.
325
+ summary : str
326
+ Paraphrase of the rule.
327
+ rationale : str
328
+ Why the rule exists.
329
+ applies_to : frozenset[FileKind]
330
+ File kinds the rule checks.
331
+ severity : SeverityLevel
332
+ Default severity.
333
+ detection : Detection
334
+ Default detection level of the checks.
335
+ status : RuleStatus
336
+ Lifecycle status.
337
+ since : str
338
+ JCCS version that introduced the rule.
339
+ deprecated_by : str
340
+ Replacement rule, if deprecated.
341
+ aliases : tuple[str, ...]
342
+ Extra selectors resolving to this rule (the Epitech reference is added automatically).
343
+ tags : tuple[str, ...]
344
+ Free tags.
345
+ docs_url : str
346
+ Documentation link.
347
+ suppressible : bool
348
+ Whether inline suppressions and baselines may hide the rule (always False for fatal rules).
349
+ requires_jccs : str
350
+ JCCS version constraint.
351
+ supersedes : tuple[str, ...]
352
+ Rules disabled when this one is active.
353
+ conflicts_with : tuple[str, ...]
354
+ Rules that may not be active together with this one.
355
+ epitech : EpitechInfo
356
+ Link to the official coding style.
357
+ arguments : Mapping[str, ArgumentSpec]
358
+ Tunable arguments, by name.
359
+ checks : tuple[CheckDefinition, ...]
360
+ Checks, in file order.
361
+ examples : tuple[ExampleDefinition, ...]
362
+ Executable examples.
363
+ """
364
+
365
+ id: str
366
+ category: str
367
+ name: str
368
+ source: str
369
+ builtin: bool
370
+ code: str
371
+ title: str
372
+ summary: str
373
+ rationale: str
374
+ applies_to: frozenset[FileKind]
375
+ severity: SeverityLevel
376
+ detection: Detection
377
+ status: RuleStatus
378
+ since: str
379
+ deprecated_by: str
380
+ aliases: tuple[str, ...]
381
+ tags: tuple[str, ...]
382
+ docs_url: str
383
+ suppressible: bool
384
+ requires_jccs: str
385
+ supersedes: tuple[str, ...]
386
+ conflicts_with: tuple[str, ...]
387
+ epitech: EpitechInfo
388
+ arguments: Mapping[str, ArgumentSpec]
389
+ checks: tuple[CheckDefinition, ...]
390
+ examples: tuple[ExampleDefinition, ...]
391
+
392
+ def check(self, check_id: str) -> CheckDefinition:
393
+ """
394
+ Get a check by its identifier.
395
+
396
+ Parameters
397
+ ----------
398
+ check_id : str
399
+ Check identifier.
400
+
401
+ Returns
402
+ ----------
403
+ CheckDefinition
404
+ The check.
405
+
406
+ Raises
407
+ ----------
408
+ KeyError
409
+ The rule has no such check.
410
+ """
411
+ for check in self.checks:
412
+ if check.id == check_id:
413
+ return check
414
+ raise KeyError(check_id)
415
+
416
+ @property
417
+ def selectors(self) -> tuple[str, ...]:
418
+ """
419
+ Every name that selects this rule: ID, Epitech reference and aliases.
420
+
421
+ Returns
422
+ ----------
423
+ tuple[str, ...]
424
+ The selectors.
425
+ """
426
+ names: list[str] = [self.id]
427
+ if self.epitech.ref:
428
+ names.append(self.epitech.ref)
429
+ names.extend(alias for alias in self.aliases if alias not in names)
430
+ return tuple(names)