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,70 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = functions/number_of_lines
|
|
4
|
+
title = Number of lines
|
|
5
|
+
summary = The body of a function is as short as possible and does not exceed 20 lines.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = major
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-F4
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[argument:max_lines]
|
|
17
|
+
type = int
|
|
18
|
+
default = 20
|
|
19
|
+
min = 1
|
|
20
|
+
description = Maximum number of lines of a function body (lines between its braces).
|
|
21
|
+
|
|
22
|
+
[check:body_lines]
|
|
23
|
+
kind = node_metric
|
|
24
|
+
target = function_definition
|
|
25
|
+
measure = body_lines
|
|
26
|
+
max = @max_lines
|
|
27
|
+
report = once_per_node
|
|
28
|
+
message = {code}: the body of '{name}' is {value} lines long (max {limit})
|
|
29
|
+
|
|
30
|
+
[example:good_1]
|
|
31
|
+
kind = good
|
|
32
|
+
|
|
33
|
+
[example:good_1:file:short.c]
|
|
34
|
+
code =
|
|
35
|
+
|int main(void)
|
|
36
|
+
|{
|
|
37
|
+
| printf("hello, world\\n");
|
|
38
|
+
| return 0;
|
|
39
|
+
|}
|
|
40
|
+
|
|
41
|
+
[example:bad_1]
|
|
42
|
+
kind = bad
|
|
43
|
+
expect = 1:1:body_lines
|
|
44
|
+
|
|
45
|
+
[example:bad_1:file:long.c]
|
|
46
|
+
code =
|
|
47
|
+
|void count_up(void)
|
|
48
|
+
|{
|
|
49
|
+
| my_put_nbr(1);
|
|
50
|
+
| my_put_nbr(2);
|
|
51
|
+
| my_put_nbr(3);
|
|
52
|
+
| my_put_nbr(4);
|
|
53
|
+
| my_put_nbr(5);
|
|
54
|
+
| my_put_nbr(6);
|
|
55
|
+
| my_put_nbr(7);
|
|
56
|
+
| my_put_nbr(8);
|
|
57
|
+
| my_put_nbr(9);
|
|
58
|
+
| my_put_nbr(10);
|
|
59
|
+
| my_put_nbr(11);
|
|
60
|
+
| my_put_nbr(12);
|
|
61
|
+
| my_put_nbr(13);
|
|
62
|
+
| my_put_nbr(14);
|
|
63
|
+
| my_put_nbr(15);
|
|
64
|
+
| my_put_nbr(16);
|
|
65
|
+
| my_put_nbr(17);
|
|
66
|
+
| my_put_nbr(18);
|
|
67
|
+
| my_put_nbr(19);
|
|
68
|
+
| my_put_nbr(20);
|
|
69
|
+
| my_put_nbr(21);
|
|
70
|
+
|}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = functions/number_of_parameters
|
|
4
|
+
title = Number of parameters
|
|
5
|
+
summary = A function has no more than 4 parameters; variadic functions are allowed but do not circumvent this limit.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = major
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-F5
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
manual_part = Variadic functions used to circumvent the limit.
|
|
16
|
+
|
|
17
|
+
[argument:max_parameters]
|
|
18
|
+
type = int
|
|
19
|
+
default = 4
|
|
20
|
+
min = 0
|
|
21
|
+
description = Maximum number of parameters.
|
|
22
|
+
|
|
23
|
+
[check:parameters]
|
|
24
|
+
kind = node_metric
|
|
25
|
+
target = function_declarator
|
|
26
|
+
measure = named_parameters
|
|
27
|
+
max = @max_parameters
|
|
28
|
+
message = {code}: '{name}' has {value} parameters (max {limit})
|
|
29
|
+
|
|
30
|
+
[check:variadic_bypass]
|
|
31
|
+
kind = manual_review
|
|
32
|
+
target = function_declarator
|
|
33
|
+
variadic_only = true
|
|
34
|
+
detection = manual
|
|
35
|
+
severity = info
|
|
36
|
+
question = Is the variadic function '{name}' used to circumvent the limit of parameters?
|
|
37
|
+
|
|
38
|
+
[example:good_1]
|
|
39
|
+
kind = good
|
|
40
|
+
|
|
41
|
+
[example:good_1:file:ok.c]
|
|
42
|
+
code =
|
|
43
|
+
|int add(int a, int b, int c, int d)
|
|
44
|
+
|{
|
|
45
|
+
| return a + b + c + d;
|
|
46
|
+
|}
|
|
47
|
+
|
|
48
|
+
[example:bad_1]
|
|
49
|
+
kind = bad
|
|
50
|
+
expect =
|
|
51
|
+
1:5:parameters
|
|
52
|
+
3:5:parameters
|
|
53
|
+
8:5:variadic_bypass
|
|
54
|
+
|
|
55
|
+
[example:bad_1:file:bad.c]
|
|
56
|
+
code =
|
|
57
|
+
|int add(int a, int b, int c, int d, int e);
|
|
58
|
+
|
|
|
59
|
+
|int add(int a, int b, int c, int d, int e)
|
|
60
|
+
|{
|
|
61
|
+
| return a + b + c + d + e;
|
|
62
|
+
|}
|
|
63
|
+
|
|
|
64
|
+
|int sum_all(int count, ...);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = functions/structures_as_parameters
|
|
4
|
+
title = Structures as parameters
|
|
5
|
+
summary = Structures are passed to functions using a pointer, not by copy.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = major
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-F7
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:by_copy]
|
|
17
|
+
kind = node_forbid
|
|
18
|
+
node = parameter
|
|
19
|
+
pattern.fields = record_by_copy=true
|
|
20
|
+
message = {code}: structure passed by copy, use a pointer
|
|
21
|
+
|
|
22
|
+
[example:good_1]
|
|
23
|
+
kind = good
|
|
24
|
+
|
|
25
|
+
[example:good_1:file:ok.h]
|
|
26
|
+
code =
|
|
27
|
+
|typedef struct board_s board_t;
|
|
28
|
+
|void make_some_coffee(struct my_struct *board, int i);
|
|
29
|
+
|void play(board_t const *board);
|
|
30
|
+
|
|
31
|
+
[example:bad_1]
|
|
32
|
+
kind = bad
|
|
33
|
+
expect =
|
|
34
|
+
bad.h:5:23:by_copy
|
|
35
|
+
bad.h:6:11:by_copy
|
|
36
|
+
|
|
37
|
+
[example:bad_1:file:bad.h]
|
|
38
|
+
code =
|
|
39
|
+
|typedef struct board_s {
|
|
40
|
+
| int size;
|
|
41
|
+
|} board_t;
|
|
42
|
+
|
|
|
43
|
+
|void make_some_poison(struct my_struct board, int i);
|
|
44
|
+
|void play(board_t board);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/constant_values
|
|
4
|
+
title = Constant values
|
|
5
|
+
summary = Non-trivial constant values are defined either as a global constant or as a macro.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = minor
|
|
8
|
+
detection = heuristic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G9
|
|
13
|
+
version = 8
|
|
14
|
+
banana = none
|
|
15
|
+
manual_part = Whether a value is trivial.
|
|
16
|
+
|
|
17
|
+
[argument:trivial_values]
|
|
18
|
+
type = list
|
|
19
|
+
default = 0, 1, -1, 2
|
|
20
|
+
description = Number values considered trivial.
|
|
21
|
+
|
|
22
|
+
[check:magic_number]
|
|
23
|
+
kind = literal_usage
|
|
24
|
+
allowed = @trivial_values
|
|
25
|
+
severity = info
|
|
26
|
+
message = {code}: '{value}' should be defined as a global constant or a macro
|
|
27
|
+
|
|
28
|
+
[example:good_1]
|
|
29
|
+
kind = good
|
|
30
|
+
|
|
31
|
+
[example:good_1:file:ok.c]
|
|
32
|
+
code =
|
|
33
|
+
|static const int ANSWER = 42;
|
|
34
|
+
|
|
|
35
|
+
|int get_next(int value)
|
|
36
|
+
|{
|
|
37
|
+
| return value + ANSWER + 1;
|
|
38
|
+
|}
|
|
39
|
+
|
|
40
|
+
[example:bad_1]
|
|
41
|
+
kind = bad
|
|
42
|
+
expect = 3:20:magic_number
|
|
43
|
+
|
|
44
|
+
[example:bad_1:file:bad.c]
|
|
45
|
+
code =
|
|
46
|
+
|int get_next(int value)
|
|
47
|
+
|{
|
|
48
|
+
| return value + 42;
|
|
49
|
+
|}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/file_header
|
|
4
|
+
title = File header
|
|
5
|
+
summary = C files and Makefiles always start with the standard header of the school, with a description of the file.
|
|
6
|
+
applies_to = c, h, make
|
|
7
|
+
severity = minor
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G1
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:c_header]
|
|
17
|
+
kind = text_regex
|
|
18
|
+
on = text
|
|
19
|
+
mode = require
|
|
20
|
+
anchor = file_start
|
|
21
|
+
where.file_kind = c, h
|
|
22
|
+
pattern = \A/\*\n\*\* EPITECH PROJECT, \d{4}\n\*\* \S.*\n\*\* File description:\n(?:\*\* .*\S.*\n)+\*/(?:\n|\Z)
|
|
23
|
+
message = {code}: missing or invalid standard header
|
|
24
|
+
|
|
25
|
+
[check:makefile_header]
|
|
26
|
+
kind = text_regex
|
|
27
|
+
on = text
|
|
28
|
+
mode = require
|
|
29
|
+
anchor = file_start
|
|
30
|
+
where.file_kind = make
|
|
31
|
+
pattern = \A##\n## EPITECH PROJECT, \d{4}\n## \S.*\n## File description:\n(?:## .*\S.*\n)+##(?:\n|\Z)
|
|
32
|
+
message = {code}: missing or invalid standard header
|
|
33
|
+
|
|
34
|
+
[example:good_1]
|
|
35
|
+
kind = good
|
|
36
|
+
|
|
37
|
+
[example:good_1:file:main.c]
|
|
38
|
+
code =
|
|
39
|
+
|/*
|
|
40
|
+
|** EPITECH PROJECT, 2026
|
|
41
|
+
|** my_project
|
|
42
|
+
|** File description:
|
|
43
|
+
|** Entry point of the program.
|
|
44
|
+
|** It only returns 0.
|
|
45
|
+
|*/
|
|
46
|
+
|
|
|
47
|
+
|int main(void)
|
|
48
|
+
|{
|
|
49
|
+
| return 0;
|
|
50
|
+
|}
|
|
51
|
+
|
|
52
|
+
[example:good_1:file:Makefile]
|
|
53
|
+
code =
|
|
54
|
+
|##
|
|
55
|
+
|## EPITECH PROJECT, 2026
|
|
56
|
+
|## my_project
|
|
57
|
+
|## File description:
|
|
58
|
+
|## Builds the program.
|
|
59
|
+
|##
|
|
60
|
+
|
|
|
61
|
+
|all:
|
|
62
|
+
|\tcc main.c
|
|
63
|
+
|
|
64
|
+
[example:bad_1]
|
|
65
|
+
kind = bad
|
|
66
|
+
expect =
|
|
67
|
+
main.c:1:1:c_header
|
|
68
|
+
Makefile:1:1:makefile_header
|
|
69
|
+
old.h:1:1:c_header
|
|
70
|
+
|
|
71
|
+
[example:bad_1:file:main.c]
|
|
72
|
+
code =
|
|
73
|
+
|int main(void)
|
|
74
|
+
|{
|
|
75
|
+
| return 0;
|
|
76
|
+
|}
|
|
77
|
+
|
|
78
|
+
[example:bad_1:file:Makefile]
|
|
79
|
+
code =
|
|
80
|
+
|##
|
|
81
|
+
|## EPITECH PROJECT, 2026
|
|
82
|
+
|## my_project
|
|
83
|
+
|##
|
|
84
|
+
|
|
85
|
+
[example:bad_1:file:old.h]
|
|
86
|
+
code =
|
|
87
|
+
|/*
|
|
88
|
+
|** EPITECH PROJECT, 26
|
|
89
|
+
|** my_project
|
|
90
|
+
|** File description:
|
|
91
|
+
|** Header.
|
|
92
|
+
|*/
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/global_variables
|
|
4
|
+
title = Global variables
|
|
5
|
+
summary = Only global constants are used: a global (or static) variable is constant if and only if it is marked with the const keyword.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = major
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G4
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:mutable_global]
|
|
17
|
+
kind = global_mutability
|
|
18
|
+
include_static_locals = true
|
|
19
|
+
message = {code}: '{name}' is a global variable, not a constant
|
|
20
|
+
|
|
21
|
+
[example:good_1]
|
|
22
|
+
kind = good
|
|
23
|
+
|
|
24
|
+
[example:good_1:file:ok.c]
|
|
25
|
+
code =
|
|
26
|
+
|const float GOLDEN_RATIO = 1.61803398875;
|
|
27
|
+
|static char const *const NAMES[] = {"a", "b"};
|
|
28
|
+
|
|
|
29
|
+
|int get_count(void)
|
|
30
|
+
|{
|
|
31
|
+
| int count = 0;
|
|
32
|
+
|
|
|
33
|
+
| return count;
|
|
34
|
+
|}
|
|
35
|
+
|
|
36
|
+
[example:bad_1]
|
|
37
|
+
kind = bad
|
|
38
|
+
expect =
|
|
39
|
+
1:5:mutable_global
|
|
40
|
+
2:20:mutable_global
|
|
41
|
+
6:16:mutable_global
|
|
42
|
+
|
|
43
|
+
[example:bad_1:file:bad.c]
|
|
44
|
+
code =
|
|
45
|
+
|int uptime = 0;
|
|
46
|
+
|static char const *names[] = {"a", "b"};
|
|
47
|
+
|
|
|
48
|
+
|int get_calls(void)
|
|
49
|
+
|{
|
|
50
|
+
| static int calls = 0;
|
|
51
|
+
|
|
|
52
|
+
| return calls;
|
|
53
|
+
|}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/include
|
|
4
|
+
title = include
|
|
5
|
+
summary = include directives only include C header (.h) files.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = major
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G5
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:header_only]
|
|
17
|
+
kind = directive
|
|
18
|
+
names = include
|
|
19
|
+
operand_pattern = ^(?:<[^>]*\.h>|"[^"]*\.h")$
|
|
20
|
+
message = {code}: '{value}' is not a C header file
|
|
21
|
+
|
|
22
|
+
[example:good_1]
|
|
23
|
+
kind = good
|
|
24
|
+
|
|
25
|
+
[example:good_1:file:ok.c]
|
|
26
|
+
code =
|
|
27
|
+
|#include <stdlib.h>
|
|
28
|
+
|#include "my.h"
|
|
29
|
+
|
|
30
|
+
[example:bad_1]
|
|
31
|
+
kind = bad
|
|
32
|
+
expect =
|
|
33
|
+
1:1:header_only
|
|
34
|
+
2:1:header_only
|
|
35
|
+
|
|
36
|
+
[example:bad_1:file:bad.c]
|
|
37
|
+
code =
|
|
38
|
+
|#include "tools.c"
|
|
39
|
+
|#include <vector>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/indentation_of_preprocessor
|
|
4
|
+
title = Indentation of preprocessor directives
|
|
5
|
+
summary = Preprocessor directives are indented according to their level of indirection, with groups of 4 spaces and no tabulation, independently of the other code.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = minor
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G3
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[argument:indent_unit]
|
|
17
|
+
type = int
|
|
18
|
+
default = 4
|
|
19
|
+
min = 1
|
|
20
|
+
description = Number of spaces per indentation level (same as C-L2).
|
|
21
|
+
|
|
22
|
+
[check:directive_indent]
|
|
23
|
+
kind = indentation
|
|
24
|
+
mode = preprocessor
|
|
25
|
+
unit = @indent_unit
|
|
26
|
+
message = {code}: #{name} is indented by {value} space(s) (expected {limit})
|
|
27
|
+
fix = safe
|
|
28
|
+
fix.kind = indent_directive
|
|
29
|
+
|
|
30
|
+
[example:good_1]
|
|
31
|
+
kind = good
|
|
32
|
+
|
|
33
|
+
[example:good_1:file:arch.h]
|
|
34
|
+
code =
|
|
35
|
+
|#ifndef WIN32
|
|
36
|
+
| #include <stdbool.h>
|
|
37
|
+
| #if defined(__i386__) || defined(__x86_64__)
|
|
38
|
+
|const size_t PAGE_SIZE = 4096;
|
|
39
|
+
| #else
|
|
40
|
+
| #error "Unknown architecture"
|
|
41
|
+
| #endif
|
|
42
|
+
|
|
|
43
|
+
|struct coords {
|
|
44
|
+
| int x;
|
|
45
|
+
| int y;
|
|
46
|
+
|};
|
|
47
|
+
|#endif
|
|
48
|
+
|
|
49
|
+
[example:bad_1]
|
|
50
|
+
kind = bad
|
|
51
|
+
expect =
|
|
52
|
+
2:1:directive_indent
|
|
53
|
+
3:1:directive_indent
|
|
54
|
+
4:1:directive_indent
|
|
55
|
+
|
|
56
|
+
[example:bad_1:file:bad.h]
|
|
57
|
+
code =
|
|
58
|
+
|#ifndef BAD_H_
|
|
59
|
+
|#define BAD_H_
|
|
60
|
+
| #include <stdlib.h>
|
|
61
|
+
|\t#include <unistd.h>
|
|
62
|
+
|#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/inline_assembly
|
|
4
|
+
title = Inline assembly
|
|
5
|
+
summary = Inline assembly is never used: programming in C is done in C.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = fatal
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G10
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:asm]
|
|
17
|
+
kind = token_forbid
|
|
18
|
+
values = asm, __asm__, __asm
|
|
19
|
+
message = {code}: inline assembly ('{name}')
|
|
20
|
+
|
|
21
|
+
[example:good_1]
|
|
22
|
+
kind = good
|
|
23
|
+
|
|
24
|
+
[example:good_1:file:ok.c]
|
|
25
|
+
code =
|
|
26
|
+
|int get_zero(void)
|
|
27
|
+
|{
|
|
28
|
+
| return 0;
|
|
29
|
+
|}
|
|
30
|
+
|
|
31
|
+
[example:bad_1]
|
|
32
|
+
kind = bad
|
|
33
|
+
expect =
|
|
34
|
+
3:5:asm
|
|
35
|
+
4:5:asm
|
|
36
|
+
|
|
37
|
+
[example:bad_1:file:bad.c]
|
|
38
|
+
code =
|
|
39
|
+
|void halt(void)
|
|
40
|
+
|{
|
|
41
|
+
| asm("hlt");
|
|
42
|
+
| __asm__ volatile ("nop");
|
|
43
|
+
|}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/leading_trailing_lines
|
|
4
|
+
title = Leading/trailing lines
|
|
5
|
+
summary = No leading empty line is present, and no more than 1 trailing empty line.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = minor
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G8
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:leading]
|
|
17
|
+
kind = blank_lines
|
|
18
|
+
region = file_start
|
|
19
|
+
max = 0
|
|
20
|
+
message = {code}: {value} leading empty line(s)
|
|
21
|
+
fix = safe
|
|
22
|
+
fix.kind = remove_leading_blank_lines
|
|
23
|
+
|
|
24
|
+
[check:trailing]
|
|
25
|
+
kind = blank_lines
|
|
26
|
+
region = file_end
|
|
27
|
+
max = 1
|
|
28
|
+
report = once_per_file
|
|
29
|
+
message = {code}: {value} trailing empty lines (max {limit})
|
|
30
|
+
fix = safe
|
|
31
|
+
fix.kind = trim_trailing_blank_lines
|
|
32
|
+
|
|
33
|
+
[example:good_1]
|
|
34
|
+
kind = good
|
|
35
|
+
|
|
36
|
+
[example:good_1:file:ok.c]
|
|
37
|
+
code =
|
|
38
|
+
|int main(void)
|
|
39
|
+
|{
|
|
40
|
+
| return 0;
|
|
41
|
+
|}
|
|
42
|
+
|
|
|
43
|
+
|
|
44
|
+
[example:bad_1]
|
|
45
|
+
kind = bad
|
|
46
|
+
expect =
|
|
47
|
+
1:1:leading
|
|
48
|
+
7:1:trailing
|
|
49
|
+
|
|
50
|
+
[example:bad_1:file:bad.c]
|
|
51
|
+
code =
|
|
52
|
+
|
|
|
53
|
+
|int main(void)
|
|
54
|
+
|{
|
|
55
|
+
| return 0;
|
|
56
|
+
|}
|
|
57
|
+
|
|
|
58
|
+
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/line_endings
|
|
4
|
+
title = Line endings
|
|
5
|
+
summary = Line endings are in UNIX style (\n) and never end with a backslash; \r is not used anywhere in the files.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = minor
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G6
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:carriage_return]
|
|
17
|
+
kind = text_regex
|
|
18
|
+
on = bytes
|
|
19
|
+
pattern = \r
|
|
20
|
+
message = {code}: \r character
|
|
21
|
+
fix = safe
|
|
22
|
+
fix.kind = normalize_line_endings
|
|
23
|
+
|
|
24
|
+
[check:backslash_end]
|
|
25
|
+
kind = text_regex
|
|
26
|
+
on = line
|
|
27
|
+
pattern = \\$
|
|
28
|
+
message = {code}: line ends with a backslash
|
|
29
|
+
|
|
30
|
+
[example:good_1]
|
|
31
|
+
kind = good
|
|
32
|
+
|
|
33
|
+
[example:good_1:file:ok.c]
|
|
34
|
+
code =
|
|
35
|
+
|int main(void)
|
|
36
|
+
|{
|
|
37
|
+
| return 0;
|
|
38
|
+
|}
|
|
39
|
+
|
|
40
|
+
[example:bad_1]
|
|
41
|
+
kind = bad
|
|
42
|
+
expect =
|
|
43
|
+
1:15:carriage_return
|
|
44
|
+
5:23:backslash_end
|
|
45
|
+
|
|
46
|
+
[example:bad_1:file:bad.c]
|
|
47
|
+
code =
|
|
48
|
+
|int main(void)\r
|
|
49
|
+
|{
|
|
50
|
+
| return 0;
|
|
51
|
+
|}
|
|
52
|
+
|#define ADD(a, b) a + \\
|
|
53
|
+
| b
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[rule]
|
|
2
|
+
schema = 2
|
|
3
|
+
id = global_scope/separation_of_functions
|
|
4
|
+
title = Separation of functions
|
|
5
|
+
summary = Inside a source file, function implementations are separated by one and only one empty line.
|
|
6
|
+
applies_to = c, h
|
|
7
|
+
severity = minor
|
|
8
|
+
detection = automatic
|
|
9
|
+
status = stable
|
|
10
|
+
|
|
11
|
+
[epitech]
|
|
12
|
+
ref = C-G2
|
|
13
|
+
version = 8
|
|
14
|
+
banana = full
|
|
15
|
+
|
|
16
|
+
[check:between_functions]
|
|
17
|
+
kind = blank_lines
|
|
18
|
+
region = between:function_definition
|
|
19
|
+
exact = 1
|
|
20
|
+
message = {code}: {value} empty line(s) before '{name}' (expected exactly {limit})
|
|
21
|
+
fix = safe
|
|
22
|
+
fix.kind = separate_functions
|
|
23
|
+
|
|
24
|
+
[example:good_1]
|
|
25
|
+
kind = good
|
|
26
|
+
|
|
27
|
+
[example:good_1:file:ok.c]
|
|
28
|
+
code =
|
|
29
|
+
|int get_one(void)
|
|
30
|
+
|{
|
|
31
|
+
| return 1;
|
|
32
|
+
|}
|
|
33
|
+
|
|
|
34
|
+
|/* Returns two. */
|
|
35
|
+
|int get_two(void)
|
|
36
|
+
|{
|
|
37
|
+
| return 2;
|
|
38
|
+
|}
|
|
39
|
+
|
|
40
|
+
[example:bad_1]
|
|
41
|
+
kind = bad
|
|
42
|
+
expect =
|
|
43
|
+
5:1:between_functions
|
|
44
|
+
11:1:between_functions
|
|
45
|
+
|
|
46
|
+
[example:bad_1:file:bad.c]
|
|
47
|
+
code =
|
|
48
|
+
|int get_one(void)
|
|
49
|
+
|{
|
|
50
|
+
| return 1;
|
|
51
|
+
|}
|
|
52
|
+
|int get_two(void)
|
|
53
|
+
|{
|
|
54
|
+
| return 2;
|
|
55
|
+
|}
|
|
56
|
+
|
|
|
57
|
+
|
|
|
58
|
+
|int get_three(void)
|
|
59
|
+
|{
|
|
60
|
+
| return 3;
|
|
61
|
+
|}
|