|
1 | 1 | import sys |
2 | 2 | import os |
3 | 3 | import re |
4 | | -import itertools |
5 | 4 | import json |
6 | 5 | from cfengine_cli.profile import profile_cfengine, generate_callstack |
7 | 6 | from cfengine_cli.dev import dispatch_dev_subcommand |
8 | | -from cfengine_cli.lint import lint_cfbs_json, lint_json, lint_policy_file |
| 7 | +from cfengine_cli.lint import lint_single_arg, lint_folder |
9 | 8 | from cfengine_cli.shell import user_command |
10 | 9 | from cfengine_cli.paths import bin |
11 | 10 | from cfengine_cli.version import cfengine_cli_version_string |
@@ -95,47 +94,15 @@ def format(names, line_length) -> int: |
95 | 94 | return 0 |
96 | 95 |
|
97 | 96 |
|
98 | | -def _lint_folder(folder): |
99 | | - errors = 0 |
100 | | - while folder.endswith(("/.", "/")): |
101 | | - folder = folder[0:-1] |
102 | | - for filename in itertools.chain( |
103 | | - find(folder, extension=".json"), find(folder, extension=".cf") |
104 | | - ): |
105 | | - if filename.startswith(("./.", "./out/", folder + "/.", folder + "/out/")): |
106 | | - continue |
107 | | - if filename.startswith(".") and not filename.startswith("./"): |
108 | | - continue |
109 | | - errors += _lint_single_file(filename) |
110 | | - return errors |
111 | | - |
112 | | - |
113 | | -def _lint_single_file(file): |
114 | | - assert os.path.isfile(file) |
115 | | - if file.endswith("/cfbs.json"): |
116 | | - return lint_cfbs_json(file) |
117 | | - if file.endswith(".json"): |
118 | | - return lint_json(file) |
119 | | - assert file.endswith(".cf") |
120 | | - return lint_policy_file(file) |
121 | | - |
122 | | - |
123 | | -def _lint_single_arg(arg): |
124 | | - if os.path.isdir(arg): |
125 | | - return _lint_folder(arg) |
126 | | - assert os.path.isfile(arg) |
127 | | - return _lint_single_file(arg) |
128 | | - |
129 | | - |
130 | 97 | def _lint(files) -> int: |
131 | 98 |
|
132 | 99 | if not files: |
133 | | - return _lint_folder(".") |
| 100 | + return lint_folder(".") |
134 | 101 |
|
135 | 102 | errors = 0 |
136 | 103 |
|
137 | 104 | for file in files: |
138 | | - errors += _lint_single_arg(file) |
| 105 | + errors += lint_single_arg(file) |
139 | 106 |
|
140 | 107 | return errors |
141 | 108 |
|
|
0 commit comments