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.
- jarbin_c_coding_style-2.0.0.dist-info/METADATA +150 -0
- jarbin_c_coding_style-2.0.0.dist-info/RECORD +186 -0
- jarbin_c_coding_style-2.0.0.dist-info/WHEEL +4 -0
- jarbin_c_coding_style-2.0.0.dist-info/entry_points.txt +2 -0
- jarbin_c_coding_style-2.0.0.dist-info/licenses/LICENSE +674 -0
- sources/__init__.py +0 -0
- sources/__main__.py +6 -0
- sources/analysis/__init__.py +0 -0
- sources/analysis/directives.py +258 -0
- sources/analysis/lexer.py +288 -0
- sources/analysis/parser.py +1754 -0
- sources/analysis/project.py +286 -0
- sources/analysis/source.py +326 -0
- sources/analysis/syntax.py +238 -0
- sources/analysis/tokens.py +116 -0
- sources/analysis/unit.py +700 -0
- sources/application.py +118 -0
- sources/build_info.json +6 -0
- sources/cli/__init__.py +0 -0
- sources/cli/arguments.py +507 -0
- sources/cli/completion.py +610 -0
- sources/cli/context.py +258 -0
- sources/cli/converters.py +204 -0
- sources/cli/help.py +162 -0
- sources/cli/parser.py +659 -0
- sources/configs/__init__.py +0 -0
- sources/configs/editor.py +207 -0
- sources/configs/ini.py +327 -0
- sources/configs/project.py +735 -0
- sources/configs/schema/__init__.py +0 -0
- sources/configs/schema/project.py +68 -0
- sources/constants.py +801 -0
- sources/diagnostics/__init__.py +0 -0
- sources/diagnostics/fingerprint.py +82 -0
- sources/diagnostics/model.py +146 -0
- sources/engine/__init__.py +0 -0
- sources/engine/api.py +355 -0
- sources/engine/examples.py +157 -0
- sources/engine/outcome.py +114 -0
- sources/engine/plan.py +440 -0
- sources/engine/runner.py +345 -0
- sources/engine/scanner.py +179 -0
- sources/enums.py +838 -0
- sources/errors/__init__.py +0 -0
- sources/errors/exceptions.py +727 -0
- sources/fixers/__init__.py +0 -0
- sources/fixers/base.py +209 -0
- sources/fixers/conflicts.py +129 -0
- sources/fixers/diff.py +73 -0
- sources/fixers/engine.py +434 -0
- sources/fixers/journal.py +290 -0
- sources/fixers/kinds.py +30 -0
- sources/fixers/layout.py +411 -0
- sources/fixers/model.py +151 -0
- sources/fixers/registry.py +54 -0
- sources/fixers/text.py +353 -0
- sources/fixers/verify.py +123 -0
- sources/fixers/writer.py +88 -0
- sources/integrations/__init__.py +0 -0
- sources/integrations/ci/__init__.py +0 -0
- sources/integrations/ci/github.py +183 -0
- sources/integrations/editors/__init__.py +0 -0
- sources/integrations/git/__init__.py +0 -0
- sources/integrations/git/repository.py +176 -0
- sources/integrations/update/__init__.py +0 -0
- sources/integrations/update/installers.py +529 -0
- sources/integrations/update/releases.py +397 -0
- sources/integrations/update/state.py +143 -0
- sources/outputs/__init__.py +0 -0
- sources/outputs/github/__init__.py +0 -0
- sources/outputs/github/renderer.py +135 -0
- sources/outputs/html/__init__.py +0 -0
- sources/outputs/html/renderer.py +694 -0
- sources/outputs/json/__init__.py +0 -0
- sources/outputs/json/renderer.py +154 -0
- sources/outputs/json/report.schema.json +121 -0
- sources/outputs/junit/__init__.py +0 -0
- sources/outputs/junit/renderer.py +151 -0
- sources/outputs/registry.py +135 -0
- sources/outputs/report.py +224 -0
- sources/outputs/sarif/__init__.py +0 -0
- sources/outputs/sarif/renderer.py +182 -0
- sources/outputs/terminal/__init__.py +0 -0
- sources/outputs/terminal/renderer.py +184 -0
- sources/outputs/terminal/style.py +159 -0
- sources/rules/__init__.py +0 -0
- sources/rules/arguments.py +362 -0
- sources/rules/catalog.py +227 -0
- sources/rules/categories/advanced/constant_pointers.ini +46 -0
- sources/rules/categories/advanced/line_break_at_end_of_file.ini +44 -0
- sources/rules/categories/advanced/static.ini +65 -0
- sources/rules/categories/advanced/typing.ini +47 -0
- sources/rules/categories/control_structures/conditional_branching.ini +89 -0
- sources/rules/categories/control_structures/goto.ini +45 -0
- sources/rules/categories/control_structures/ternary_operators.ini +57 -0
- sources/rules/categories/extensions/language_extensions.ini +71 -0
- sources/rules/categories/files_organization/contents_of_the_repository.ini +85 -0
- sources/rules/categories/files_organization/file_coherence.ini +166 -0
- sources/rules/categories/files_organization/file_extension.ini +68 -0
- sources/rules/categories/files_organization/fixtures/program +0 -0
- sources/rules/categories/files_organization/naming_files_and_folders.ini +74 -0
- sources/rules/categories/functions/coherence_of_functions.ini +45 -0
- sources/rules/categories/functions/comments_inside_a_function.ini +45 -0
- sources/rules/categories/functions/functions_without_parameters.ini +39 -0
- sources/rules/categories/functions/naming_functions.ini +79 -0
- sources/rules/categories/functions/number_of_columns.ini +61 -0
- sources/rules/categories/functions/number_of_lines.ini +70 -0
- sources/rules/categories/functions/number_of_parameters.ini +64 -0
- sources/rules/categories/functions/structures_as_parameters.ini +44 -0
- sources/rules/categories/global_scope/constant_values.ini +49 -0
- sources/rules/categories/global_scope/file_header.ini +92 -0
- sources/rules/categories/global_scope/global_variables.ini +53 -0
- sources/rules/categories/global_scope/include.ini +39 -0
- sources/rules/categories/global_scope/indentation_of_preprocessor.ini +62 -0
- sources/rules/categories/global_scope/inline_assembly.ini +43 -0
- sources/rules/categories/global_scope/leading_trailing_lines.ini +58 -0
- sources/rules/categories/global_scope/line_endings.ini +53 -0
- sources/rules/categories/global_scope/separation_of_functions.ini +61 -0
- sources/rules/categories/global_scope/trailing_spaces.ini +45 -0
- sources/rules/categories/header_files/content.ini +104 -0
- sources/rules/categories/header_files/include_guard.ini +47 -0
- sources/rules/categories/header_files/macros.ini +57 -0
- sources/rules/categories/layout_inside_a_function_scope/blank_lines.ini +71 -0
- sources/rules/categories/layout_inside_a_function_scope/code_line_content.ini +112 -0
- sources/rules/categories/layout_inside_a_function_scope/curly_brackets.ini +94 -0
- sources/rules/categories/layout_inside_a_function_scope/indentation.ini +96 -0
- sources/rules/categories/layout_inside_a_function_scope/spaces.ini +113 -0
- sources/rules/categories/layout_inside_a_function_scope/variable_declarations.ini +65 -0
- sources/rules/categories/variables_and_types/naming_identifiers.ini +74 -0
- sources/rules/categories/variables_and_types/pointers.ini +67 -0
- sources/rules/categories/variables_and_types/structures.ini +47 -0
- sources/rules/data/verbs.txt +182 -0
- sources/rules/definition.py +430 -0
- sources/rules/loader.py +925 -0
- sources/rules/paths.py +6 -0
- sources/rules/primitives/__init__.py +0 -0
- sources/rules/primitives/base.py +297 -0
- sources/rules/primitives/braces.py +211 -0
- sources/rules/primitives/directives.py +203 -0
- sources/rules/primitives/indentation.py +376 -0
- sources/rules/primitives/layout.py +199 -0
- sources/rules/primitives/naming.py +277 -0
- sources/rules/primitives/project.py +62 -0
- sources/rules/primitives/registry.py +49 -0
- sources/rules/primitives/repository.py +129 -0
- sources/rules/primitives/review.py +87 -0
- sources/rules/primitives/semantic.py +319 -0
- sources/rules/primitives/spacing.py +210 -0
- sources/rules/primitives/structure.py +586 -0
- sources/rules/primitives/syntax.py +200 -0
- sources/rules/primitives/text.py +408 -0
- sources/rules/primitives/tokens.py +84 -0
- sources/rules/template.py +138 -0
- sources/selftest/__init__.py +0 -0
- sources/selftest/cases.py +292 -0
- sources/services.py +90 -0
- sources/subcommands/__init__.py +0 -0
- sources/subcommands/base.py +45 -0
- sources/subcommands/check/__init__.py +0 -0
- sources/subcommands/check/command.py +45 -0
- sources/subcommands/check/fixing.py +224 -0
- sources/subcommands/check/handler.py +757 -0
- sources/subcommands/info/__init__.py +0 -0
- sources/subcommands/info/command.py +45 -0
- sources/subcommands/info/handler.py +527 -0
- sources/subcommands/registry.py +37 -0
- sources/subcommands/rule/__init__.py +0 -0
- sources/subcommands/rule/command.py +45 -0
- sources/subcommands/rule/handler.py +1067 -0
- sources/subcommands/rule/render.py +273 -0
- sources/subcommands/runner.py +124 -0
- sources/subcommands/test/__init__.py +0 -0
- sources/subcommands/test/command.py +45 -0
- sources/subcommands/test/handler.py +166 -0
- sources/subcommands/test/render.py +219 -0
- sources/subcommands/test/runner.py +430 -0
- sources/subcommands/update/__init__.py +0 -0
- sources/subcommands/update/command.py +45 -0
- sources/subcommands/update/handler.py +408 -0
- sources/utils/__init__.py +0 -0
- sources/utils/build_info.py +188 -0
- sources/utils/git.py +73 -0
- sources/utils/globs.py +98 -0
- sources/utils/logging.py +154 -0
- sources/utils/schema.py +77 -0
- sources/utils/versions.py +87 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
|
|
3
|
+
from jarbin_toolkit_error import FormatType, JErrorValue, JException
|
|
4
|
+
|
|
5
|
+
from sources.enums import ExitCode
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class JccsError(JException):
|
|
9
|
+
"""
|
|
10
|
+
Base class of every error raised by JCCS. Library code raises it, only the
|
|
11
|
+
application entry point turns it into a message and an exit code.
|
|
12
|
+
Rendering is delegated to jarbin-toolkit-error: the entry point picks the style through the
|
|
13
|
+
`format` property (e.g. FormatType.PRETTY for users, FormatType.TRACEBACK for debugging).
|
|
14
|
+
(JException)
|
|
15
|
+
|
|
16
|
+
Attributes
|
|
17
|
+
----------
|
|
18
|
+
exit_code : ExitCode
|
|
19
|
+
Exit code the process must return when this error reaches the entry point.
|
|
20
|
+
message : str
|
|
21
|
+
Full text of the error (description, then the hint on its own line when there is one).
|
|
22
|
+
hint : str | None
|
|
23
|
+
Optional suggestion on how to fix the error.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
exit_code: ExitCode = ExitCode.INTERNAL
|
|
27
|
+
|
|
28
|
+
def __init__(self, message: str, hint: str | None = None, *, format: FormatType = FormatType.TRACEBACK) -> None:
|
|
29
|
+
"""
|
|
30
|
+
Create the error.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
message : str
|
|
35
|
+
Human-readable description of the error.
|
|
36
|
+
hint : str | None
|
|
37
|
+
Optional suggestion on how to fix the error.
|
|
38
|
+
format : FormatType
|
|
39
|
+
jarbin-toolkit-error rendering style used by `str(error)`.
|
|
40
|
+
|
|
41
|
+
Returns
|
|
42
|
+
----------
|
|
43
|
+
None
|
|
44
|
+
Nothing.
|
|
45
|
+
"""
|
|
46
|
+
super().__init__(message if hint is None else f"{message}\n{hint}", format=format)
|
|
47
|
+
self.hint: str | None = hint
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ValueConversionError(JErrorValue):
|
|
51
|
+
"""
|
|
52
|
+
Raised by a flag value converter when a raw command-line string is not acceptable.
|
|
53
|
+
The parser turns it into an InvalidFlagValueError carrying the flag context.
|
|
54
|
+
(JException -> JErrorValue)
|
|
55
|
+
|
|
56
|
+
Attributes
|
|
57
|
+
----------
|
|
58
|
+
reason : str
|
|
59
|
+
Short explanation of why the value was rejected, e.g. "must be >= 1".
|
|
60
|
+
raw : str
|
|
61
|
+
The rejected value as typed by the user.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def __init__(self, reason: str, raw: str) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Create the error.
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
reason : str
|
|
71
|
+
Short explanation of why the value was rejected.
|
|
72
|
+
raw : str
|
|
73
|
+
The rejected value as typed by the user.
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
----------
|
|
77
|
+
None
|
|
78
|
+
Nothing.
|
|
79
|
+
"""
|
|
80
|
+
super().__init__(reason, value=raw)
|
|
81
|
+
self.reason: str = reason
|
|
82
|
+
self.raw: str = raw
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class InternalError(JccsError):
|
|
86
|
+
"""
|
|
87
|
+
Error caused by a bug in JCCS itself, never by the user.
|
|
88
|
+
(JException -> JccsError)
|
|
89
|
+
|
|
90
|
+
Attributes
|
|
91
|
+
----------
|
|
92
|
+
exit_code : ExitCode
|
|
93
|
+
Always ExitCode.INTERNAL.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
exit_code: ExitCode = ExitCode.INTERNAL
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class FlagDefinitionError(InternalError):
|
|
100
|
+
"""
|
|
101
|
+
A flag or command definition is invalid (duplicate name, bad token, unknown reference...).
|
|
102
|
+
Raised when the definitions are built, so it surfaces as soon as the program starts.
|
|
103
|
+
(JException -> JccsError -> InternalError)
|
|
104
|
+
|
|
105
|
+
Attributes
|
|
106
|
+
----------
|
|
107
|
+
exit_code : ExitCode
|
|
108
|
+
Always ExitCode.INTERNAL.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class UsageError(JccsError):
|
|
113
|
+
"""
|
|
114
|
+
The command line given by the user is invalid.
|
|
115
|
+
(JException -> JccsError)
|
|
116
|
+
|
|
117
|
+
Attributes
|
|
118
|
+
----------
|
|
119
|
+
exit_code : ExitCode
|
|
120
|
+
Always ExitCode.USAGE.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
exit_code: ExitCode = ExitCode.USAGE
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _suggestion_hint(suggestions: Sequence[str]) -> str | None:
|
|
127
|
+
"""
|
|
128
|
+
Build a "did you mean" hint from a list of close matches.
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
suggestions : Sequence[str]
|
|
133
|
+
Close matches, best first.
|
|
134
|
+
|
|
135
|
+
Returns
|
|
136
|
+
----------
|
|
137
|
+
str | None
|
|
138
|
+
The hint, or None when there is no suggestion.
|
|
139
|
+
"""
|
|
140
|
+
if not suggestions:
|
|
141
|
+
return None
|
|
142
|
+
return "Did you mean " + " or ".join(f"'{suggestion}'" for suggestion in suggestions) + "?"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class UnknownFlagError(UsageError):
|
|
146
|
+
"""
|
|
147
|
+
A token looks like a flag but no visible flag matches it.
|
|
148
|
+
(JException -> JccsError -> UsageError)
|
|
149
|
+
|
|
150
|
+
Attributes
|
|
151
|
+
----------
|
|
152
|
+
token : str
|
|
153
|
+
The unknown flag as typed by the user.
|
|
154
|
+
command : str
|
|
155
|
+
Name of the command being parsed when the error occurred.
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
def __init__(self, token: str, command: str, suggestions: Sequence[str] = ()) -> None:
|
|
159
|
+
"""
|
|
160
|
+
Create the error.
|
|
161
|
+
|
|
162
|
+
Parameters
|
|
163
|
+
----------
|
|
164
|
+
token : str
|
|
165
|
+
The unknown flag as typed by the user.
|
|
166
|
+
command : str
|
|
167
|
+
Name of the command being parsed when the error occurred.
|
|
168
|
+
suggestions : Sequence[str]
|
|
169
|
+
Close matches among the visible flags.
|
|
170
|
+
|
|
171
|
+
Returns
|
|
172
|
+
----------
|
|
173
|
+
None
|
|
174
|
+
Nothing.
|
|
175
|
+
"""
|
|
176
|
+
super().__init__(f"Unknown flag '{token}' for '{command}'.", _suggestion_hint(suggestions))
|
|
177
|
+
self.token: str = token
|
|
178
|
+
self.command: str = command
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class UnknownCommandError(UsageError):
|
|
182
|
+
"""
|
|
183
|
+
A positional token does not match any subcommand of the current command.
|
|
184
|
+
(JException -> JccsError -> UsageError)
|
|
185
|
+
|
|
186
|
+
Attributes
|
|
187
|
+
----------
|
|
188
|
+
token : str
|
|
189
|
+
The unknown subcommand as typed by the user.
|
|
190
|
+
command : str
|
|
191
|
+
Name of the command being parsed when the error occurred.
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
def __init__(self, token: str, command: str, suggestions: Sequence[str] = ()) -> None:
|
|
195
|
+
"""
|
|
196
|
+
Create the error.
|
|
197
|
+
|
|
198
|
+
Parameters
|
|
199
|
+
----------
|
|
200
|
+
token : str
|
|
201
|
+
The unknown subcommand as typed by the user.
|
|
202
|
+
command : str
|
|
203
|
+
Name of the command being parsed when the error occurred.
|
|
204
|
+
suggestions : Sequence[str]
|
|
205
|
+
Close matches among the available subcommands.
|
|
206
|
+
|
|
207
|
+
Returns
|
|
208
|
+
----------
|
|
209
|
+
None
|
|
210
|
+
Nothing.
|
|
211
|
+
"""
|
|
212
|
+
super().__init__(f"Unknown command '{token}' for '{command}'.", _suggestion_hint(suggestions))
|
|
213
|
+
self.token: str = token
|
|
214
|
+
self.command: str = command
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class UnexpectedArgumentError(UsageError):
|
|
218
|
+
"""
|
|
219
|
+
A positional token was given to a command that takes no positional argument.
|
|
220
|
+
(JException -> JccsError -> UsageError)
|
|
221
|
+
|
|
222
|
+
Attributes
|
|
223
|
+
----------
|
|
224
|
+
token : str
|
|
225
|
+
The unexpected argument.
|
|
226
|
+
command : str
|
|
227
|
+
Name of the command being parsed when the error occurred.
|
|
228
|
+
"""
|
|
229
|
+
|
|
230
|
+
def __init__(self, token: str, command: str) -> None:
|
|
231
|
+
"""
|
|
232
|
+
Create the error.
|
|
233
|
+
|
|
234
|
+
Parameters
|
|
235
|
+
----------
|
|
236
|
+
token : str
|
|
237
|
+
The unexpected argument.
|
|
238
|
+
command : str
|
|
239
|
+
Name of the command being parsed when the error occurred.
|
|
240
|
+
|
|
241
|
+
Returns
|
|
242
|
+
----------
|
|
243
|
+
None
|
|
244
|
+
Nothing.
|
|
245
|
+
"""
|
|
246
|
+
super().__init__(f"Unexpected argument '{token}' for '{command}'.")
|
|
247
|
+
self.token: str = token
|
|
248
|
+
self.command: str = command
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class MissingFlagValueError(UsageError):
|
|
252
|
+
"""
|
|
253
|
+
A flag did not receive the number of values it expects.
|
|
254
|
+
(JException -> JccsError -> UsageError)
|
|
255
|
+
|
|
256
|
+
Attributes
|
|
257
|
+
----------
|
|
258
|
+
token : str
|
|
259
|
+
The flag as typed by the user.
|
|
260
|
+
usage : str
|
|
261
|
+
Usage line of the flag, e.g. "-o, --output <path>".
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
def __init__(self, token: str, usage: str) -> None:
|
|
265
|
+
"""
|
|
266
|
+
Create the error.
|
|
267
|
+
|
|
268
|
+
Parameters
|
|
269
|
+
----------
|
|
270
|
+
token : str
|
|
271
|
+
The flag as typed by the user.
|
|
272
|
+
usage : str
|
|
273
|
+
Usage line of the flag.
|
|
274
|
+
|
|
275
|
+
Returns
|
|
276
|
+
----------
|
|
277
|
+
None
|
|
278
|
+
Nothing.
|
|
279
|
+
"""
|
|
280
|
+
super().__init__(f"Wrong number of values for '{token}'.", f"Usage: {usage}")
|
|
281
|
+
self.token: str = token
|
|
282
|
+
self.usage: str = usage
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
class UnexpectedFlagValueError(UsageError):
|
|
286
|
+
"""
|
|
287
|
+
A value was attached (`--flag=value`) to a flag that takes none.
|
|
288
|
+
(JException -> JccsError -> UsageError)
|
|
289
|
+
|
|
290
|
+
Attributes
|
|
291
|
+
----------
|
|
292
|
+
token : str
|
|
293
|
+
The flag as typed by the user.
|
|
294
|
+
"""
|
|
295
|
+
|
|
296
|
+
def __init__(self, token: str) -> None:
|
|
297
|
+
"""
|
|
298
|
+
Create the error.
|
|
299
|
+
|
|
300
|
+
Parameters
|
|
301
|
+
----------
|
|
302
|
+
token : str
|
|
303
|
+
The flag as typed by the user.
|
|
304
|
+
|
|
305
|
+
Returns
|
|
306
|
+
----------
|
|
307
|
+
None
|
|
308
|
+
Nothing.
|
|
309
|
+
"""
|
|
310
|
+
super().__init__(f"Flag '{token}' does not take a value.")
|
|
311
|
+
self.token: str = token
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
class InvalidFlagValueError(UsageError):
|
|
315
|
+
"""
|
|
316
|
+
A value could not be converted to the type expected by its flag.
|
|
317
|
+
(JException -> JccsError -> UsageError)
|
|
318
|
+
|
|
319
|
+
Attributes
|
|
320
|
+
----------
|
|
321
|
+
token : str
|
|
322
|
+
The flag as typed by the user.
|
|
323
|
+
metavar : str
|
|
324
|
+
Name of the expected value, e.g. "path".
|
|
325
|
+
raw : str
|
|
326
|
+
The value as typed by the user.
|
|
327
|
+
"""
|
|
328
|
+
|
|
329
|
+
def __init__(self, token: str, metavar: str, raw: str, reason: str, choices: Sequence[str] | None = None) -> None:
|
|
330
|
+
"""
|
|
331
|
+
Create the error.
|
|
332
|
+
|
|
333
|
+
Parameters
|
|
334
|
+
----------
|
|
335
|
+
token : str
|
|
336
|
+
The flag as typed by the user.
|
|
337
|
+
metavar : str
|
|
338
|
+
Name of the expected value.
|
|
339
|
+
raw : str
|
|
340
|
+
The value as typed by the user.
|
|
341
|
+
reason : str
|
|
342
|
+
Why the conversion failed.
|
|
343
|
+
choices : Sequence[str] | None
|
|
344
|
+
Accepted values, when the value is an enumeration.
|
|
345
|
+
|
|
346
|
+
Returns
|
|
347
|
+
----------
|
|
348
|
+
None
|
|
349
|
+
Nothing.
|
|
350
|
+
"""
|
|
351
|
+
hint: str | None = None
|
|
352
|
+
if choices:
|
|
353
|
+
hint = "Expected one of: " + ", ".join(choices) + "."
|
|
354
|
+
super().__init__(f"Invalid value '{raw}' for <{metavar}> of '{token}': {reason}", hint)
|
|
355
|
+
self.token: str = token
|
|
356
|
+
self.metavar: str = metavar
|
|
357
|
+
self.raw: str = raw
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
class DuplicateFlagError(UsageError):
|
|
361
|
+
"""
|
|
362
|
+
A flag that may only appear once was given several times.
|
|
363
|
+
(JException -> JccsError -> UsageError)
|
|
364
|
+
|
|
365
|
+
Attributes
|
|
366
|
+
----------
|
|
367
|
+
token : str
|
|
368
|
+
The repeated flag as typed by the user.
|
|
369
|
+
"""
|
|
370
|
+
|
|
371
|
+
def __init__(self, token: str) -> None:
|
|
372
|
+
"""
|
|
373
|
+
Create the error.
|
|
374
|
+
|
|
375
|
+
Parameters
|
|
376
|
+
----------
|
|
377
|
+
token : str
|
|
378
|
+
The repeated flag as typed by the user.
|
|
379
|
+
|
|
380
|
+
Returns
|
|
381
|
+
----------
|
|
382
|
+
None
|
|
383
|
+
Nothing.
|
|
384
|
+
"""
|
|
385
|
+
super().__init__(f"Flag '{token}' can only be given once.")
|
|
386
|
+
self.token: str = token
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
class ConflictingFlagsError(UsageError):
|
|
390
|
+
"""
|
|
391
|
+
Several flags that cannot be combined were given together.
|
|
392
|
+
(JException -> JccsError -> UsageError)
|
|
393
|
+
|
|
394
|
+
Attributes
|
|
395
|
+
----------
|
|
396
|
+
tokens : tuple[str, ...]
|
|
397
|
+
The conflicting flags as typed by the user.
|
|
398
|
+
"""
|
|
399
|
+
|
|
400
|
+
def __init__(self, tokens: Sequence[str]) -> None:
|
|
401
|
+
"""
|
|
402
|
+
Create the error.
|
|
403
|
+
|
|
404
|
+
Parameters
|
|
405
|
+
----------
|
|
406
|
+
tokens : Sequence[str]
|
|
407
|
+
The conflicting flags as typed by the user.
|
|
408
|
+
|
|
409
|
+
Returns
|
|
410
|
+
----------
|
|
411
|
+
None
|
|
412
|
+
Nothing.
|
|
413
|
+
"""
|
|
414
|
+
listed: str = ", ".join(f"'{token}'" for token in tokens)
|
|
415
|
+
super().__init__(f"Flags {listed} cannot be used together.")
|
|
416
|
+
self.tokens: tuple[str, ...] = tuple(tokens)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class MissingRequiredFlagError(UsageError):
|
|
420
|
+
"""
|
|
421
|
+
A flag was given without another flag it depends on.
|
|
422
|
+
(JException -> JccsError -> UsageError)
|
|
423
|
+
|
|
424
|
+
Attributes
|
|
425
|
+
----------
|
|
426
|
+
token : str
|
|
427
|
+
The flag as typed by the user.
|
|
428
|
+
required : str
|
|
429
|
+
Display name of the missing flag.
|
|
430
|
+
"""
|
|
431
|
+
|
|
432
|
+
def __init__(self, token: str, required: str) -> None:
|
|
433
|
+
"""
|
|
434
|
+
Create the error.
|
|
435
|
+
|
|
436
|
+
Parameters
|
|
437
|
+
----------
|
|
438
|
+
token : str
|
|
439
|
+
The flag as typed by the user.
|
|
440
|
+
required : str
|
|
441
|
+
Display name of the missing flag.
|
|
442
|
+
|
|
443
|
+
Returns
|
|
444
|
+
----------
|
|
445
|
+
None
|
|
446
|
+
Nothing.
|
|
447
|
+
"""
|
|
448
|
+
super().__init__(f"Flag '{token}' requires '{required}'.")
|
|
449
|
+
self.token: str = token
|
|
450
|
+
self.required: str = required
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _located(message: str, path: str | None, line: int | None) -> str:
|
|
454
|
+
"""
|
|
455
|
+
Prefix a message with "path:line: " when a location is known.
|
|
456
|
+
|
|
457
|
+
Parameters
|
|
458
|
+
----------
|
|
459
|
+
message : str
|
|
460
|
+
Description of the problem.
|
|
461
|
+
path : str | None
|
|
462
|
+
File the problem was found in.
|
|
463
|
+
line : int | None
|
|
464
|
+
1-based line of the problem in that file.
|
|
465
|
+
|
|
466
|
+
Returns
|
|
467
|
+
----------
|
|
468
|
+
str
|
|
469
|
+
The located message.
|
|
470
|
+
"""
|
|
471
|
+
if path is None:
|
|
472
|
+
return message
|
|
473
|
+
if line is None:
|
|
474
|
+
return f"{path}: {message}"
|
|
475
|
+
return f"{path}:{line}: {message}"
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
class ConfigError(JccsError):
|
|
479
|
+
"""
|
|
480
|
+
A configuration file or a rule definition file is invalid.
|
|
481
|
+
(JException -> JccsError)
|
|
482
|
+
|
|
483
|
+
Attributes
|
|
484
|
+
----------
|
|
485
|
+
exit_code : ExitCode
|
|
486
|
+
Always ExitCode.CONFIG.
|
|
487
|
+
path : str | None
|
|
488
|
+
File the problem was found in.
|
|
489
|
+
line : int | None
|
|
490
|
+
1-based line of the problem in that file.
|
|
491
|
+
"""
|
|
492
|
+
|
|
493
|
+
exit_code: ExitCode = ExitCode.CONFIG
|
|
494
|
+
|
|
495
|
+
def __init__(self, message: str, hint: str | None = None, *, path: str | None = None, line: int | None = None) -> None:
|
|
496
|
+
"""
|
|
497
|
+
Create the error.
|
|
498
|
+
|
|
499
|
+
Parameters
|
|
500
|
+
----------
|
|
501
|
+
message : str
|
|
502
|
+
Description of the problem.
|
|
503
|
+
hint : str | None
|
|
504
|
+
Optional suggestion on how to fix the problem.
|
|
505
|
+
path : str | None
|
|
506
|
+
File the problem was found in.
|
|
507
|
+
line : int | None
|
|
508
|
+
1-based line of the problem in that file.
|
|
509
|
+
|
|
510
|
+
Returns
|
|
511
|
+
----------
|
|
512
|
+
None
|
|
513
|
+
Nothing.
|
|
514
|
+
"""
|
|
515
|
+
super().__init__(_located(message, path, line), hint)
|
|
516
|
+
self.path: str | None = path
|
|
517
|
+
self.line: int | None = line
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
class IniSyntaxError(ConfigError):
|
|
521
|
+
"""
|
|
522
|
+
A rule file breaks the strict INI dialect (duplicate key, stray line, bad code line...).
|
|
523
|
+
(JException -> JccsError -> ConfigError)
|
|
524
|
+
|
|
525
|
+
Attributes
|
|
526
|
+
----------
|
|
527
|
+
exit_code : ExitCode
|
|
528
|
+
Always ExitCode.CONFIG.
|
|
529
|
+
"""
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
class RuleDefinitionError(ConfigError):
|
|
533
|
+
"""
|
|
534
|
+
A rule file is syntactically valid INI but its content is not a valid rule (schema 2).
|
|
535
|
+
(JException -> JccsError -> ConfigError)
|
|
536
|
+
|
|
537
|
+
Attributes
|
|
538
|
+
----------
|
|
539
|
+
exit_code : ExitCode
|
|
540
|
+
Always ExitCode.CONFIG.
|
|
541
|
+
"""
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
class ProjectConfigError(ConfigError):
|
|
545
|
+
"""
|
|
546
|
+
The project configuration (`.JCCS/.jccs.ini`) is invalid.
|
|
547
|
+
(JException -> JccsError -> ConfigError)
|
|
548
|
+
|
|
549
|
+
Attributes
|
|
550
|
+
----------
|
|
551
|
+
exit_code : ExitCode
|
|
552
|
+
Always ExitCode.CONFIG.
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
class UnknownSelectorError(ConfigError):
|
|
557
|
+
"""
|
|
558
|
+
A rule selector matches no known rule, category or check.
|
|
559
|
+
(JException -> JccsError -> ConfigError)
|
|
560
|
+
|
|
561
|
+
Attributes
|
|
562
|
+
----------
|
|
563
|
+
selector : str
|
|
564
|
+
The selector as written by the user.
|
|
565
|
+
"""
|
|
566
|
+
|
|
567
|
+
def __init__(self, selector: str, suggestions: Sequence[str] = (), *, path: str | None = None) -> None:
|
|
568
|
+
"""
|
|
569
|
+
Create the error.
|
|
570
|
+
|
|
571
|
+
Parameters
|
|
572
|
+
----------
|
|
573
|
+
selector : str
|
|
574
|
+
The selector as written by the user.
|
|
575
|
+
suggestions : Sequence[str]
|
|
576
|
+
Close matches among the known selectors.
|
|
577
|
+
path : str | None
|
|
578
|
+
File the selector was found in.
|
|
579
|
+
|
|
580
|
+
Returns
|
|
581
|
+
----------
|
|
582
|
+
None
|
|
583
|
+
Nothing.
|
|
584
|
+
"""
|
|
585
|
+
super().__init__(f"Unknown rule selector '{selector}'.", _suggestion_hint(suggestions), path=path)
|
|
586
|
+
self.selector: str = selector
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
class ProjectEnvironmentError(JccsError):
|
|
590
|
+
"""
|
|
591
|
+
The project cannot be read or its JCCS directory cannot be created (filesystem, git...).
|
|
592
|
+
(JException -> JccsError)
|
|
593
|
+
|
|
594
|
+
Attributes
|
|
595
|
+
----------
|
|
596
|
+
exit_code : ExitCode
|
|
597
|
+
Always ExitCode.ENVIRONMENT.
|
|
598
|
+
"""
|
|
599
|
+
|
|
600
|
+
exit_code: ExitCode = ExitCode.ENVIRONMENT
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
class InvalidOperandError(UsageError):
|
|
604
|
+
"""
|
|
605
|
+
A positional argument could not be converted to the type expected by its command.
|
|
606
|
+
(JException -> JccsError -> UsageError)
|
|
607
|
+
|
|
608
|
+
Attributes
|
|
609
|
+
----------
|
|
610
|
+
metavar : str
|
|
611
|
+
Name of the expected operand, e.g. "path".
|
|
612
|
+
raw : str
|
|
613
|
+
The operand as typed by the user.
|
|
614
|
+
"""
|
|
615
|
+
|
|
616
|
+
def __init__(self, metavar: str, raw: str, reason: str) -> None:
|
|
617
|
+
"""
|
|
618
|
+
Create the error.
|
|
619
|
+
|
|
620
|
+
Parameters
|
|
621
|
+
----------
|
|
622
|
+
metavar : str
|
|
623
|
+
Name of the expected operand.
|
|
624
|
+
raw : str
|
|
625
|
+
The operand as typed by the user.
|
|
626
|
+
reason : str
|
|
627
|
+
Why the conversion failed.
|
|
628
|
+
|
|
629
|
+
Returns
|
|
630
|
+
----------
|
|
631
|
+
None
|
|
632
|
+
Nothing.
|
|
633
|
+
"""
|
|
634
|
+
super().__init__(f"Invalid <{metavar}> argument '{raw}': {reason}")
|
|
635
|
+
self.metavar: str = metavar
|
|
636
|
+
self.raw: str = raw
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
class FeatureUnavailableError(UsageError):
|
|
640
|
+
"""
|
|
641
|
+
A flag or subcommand exists in the specification but is not implemented yet.
|
|
642
|
+
(JException -> JccsError -> UsageError)
|
|
643
|
+
|
|
644
|
+
Attributes
|
|
645
|
+
----------
|
|
646
|
+
feature : str
|
|
647
|
+
The flag or subcommand as typed by the user.
|
|
648
|
+
"""
|
|
649
|
+
|
|
650
|
+
def __init__(self, feature: str, hint: str | None = None) -> None:
|
|
651
|
+
"""
|
|
652
|
+
Create the error.
|
|
653
|
+
|
|
654
|
+
Parameters
|
|
655
|
+
----------
|
|
656
|
+
feature : str
|
|
657
|
+
The flag or subcommand as typed by the user.
|
|
658
|
+
hint : str | None
|
|
659
|
+
Optional suggestion (e.g. a working alternative).
|
|
660
|
+
|
|
661
|
+
Returns
|
|
662
|
+
----------
|
|
663
|
+
None
|
|
664
|
+
Nothing.
|
|
665
|
+
"""
|
|
666
|
+
super().__init__(f"'{feature}' is not available yet in this version of JCCS.", hint)
|
|
667
|
+
self.feature: str = feature
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
class MissingCommandError(UsageError):
|
|
671
|
+
"""
|
|
672
|
+
No subcommand and no global action was given.
|
|
673
|
+
(JException -> JccsError -> UsageError)
|
|
674
|
+
|
|
675
|
+
Attributes
|
|
676
|
+
----------
|
|
677
|
+
usage : str
|
|
678
|
+
Short usage of the program.
|
|
679
|
+
"""
|
|
680
|
+
|
|
681
|
+
def __init__(self, usage: str) -> None:
|
|
682
|
+
"""
|
|
683
|
+
Create the error.
|
|
684
|
+
|
|
685
|
+
Parameters
|
|
686
|
+
----------
|
|
687
|
+
usage : str
|
|
688
|
+
Short usage of the program.
|
|
689
|
+
|
|
690
|
+
Returns
|
|
691
|
+
----------
|
|
692
|
+
None
|
|
693
|
+
Nothing.
|
|
694
|
+
"""
|
|
695
|
+
super().__init__("Missing subcommand.", usage)
|
|
696
|
+
self.usage: str = usage
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
class UnknownRuleError(UsageError):
|
|
700
|
+
"""
|
|
701
|
+
A `<category> <rule>` pair given on the command line names no known rule.
|
|
702
|
+
(JException -> JccsError -> UsageError)
|
|
703
|
+
|
|
704
|
+
Attributes
|
|
705
|
+
----------
|
|
706
|
+
rule_id : str
|
|
707
|
+
The rule ID as typed by the user.
|
|
708
|
+
"""
|
|
709
|
+
|
|
710
|
+
def __init__(self, rule_id: str, suggestions: Sequence[str] = ()) -> None:
|
|
711
|
+
"""
|
|
712
|
+
Create the error.
|
|
713
|
+
|
|
714
|
+
Parameters
|
|
715
|
+
----------
|
|
716
|
+
rule_id : str
|
|
717
|
+
The rule ID as typed by the user.
|
|
718
|
+
suggestions : Sequence[str]
|
|
719
|
+
Close matches among the known rules.
|
|
720
|
+
|
|
721
|
+
Returns
|
|
722
|
+
----------
|
|
723
|
+
None
|
|
724
|
+
Nothing.
|
|
725
|
+
"""
|
|
726
|
+
super().__init__(f"Unknown rule '{rule_id}'.", _suggestion_hint(suggestions))
|
|
727
|
+
self.rule_id: str = rule_id
|