|
39 | 39 | from tree_sitter import Language, Node, Parser, Tree |
40 | 40 | from cfbs.validate import validate_config |
41 | 41 | from cfbs.cfbs_config import CFBSConfig |
42 | | -from cfbs.utils import find |
43 | 42 | from cfengine_cli.lint_csv import check_csv_file |
44 | 43 | from cfengine_cli.lint_yml import check_yml_file |
45 | 44 | from cfengine_cli.utils import UserError |
@@ -1016,58 +1015,6 @@ def _lint(policy_file: PolicyFile, state: State, syntax_data: SyntaxData) -> int |
1016 | 1015 | return errors |
1017 | 1016 |
|
1018 | 1017 |
|
1019 | | -def _find_policy_files(args: Iterable[str]) -> Iterable[str]: |
1020 | | - """Takes an iterator of paths to files / folders |
1021 | | -
|
1022 | | - Returns an iterator of CFEngine policy file paths (strings). |
1023 | | - """ |
1024 | | - for arg in args: |
1025 | | - if os.path.isdir(arg): |
1026 | | - while arg.endswith(("/.", "/")): |
1027 | | - arg = arg[0:-1] |
1028 | | - for result in find(arg, extension=".cf"): |
1029 | | - yield result |
1030 | | - elif arg.endswith(".cf"): |
1031 | | - yield arg |
1032 | | - |
1033 | | - |
1034 | | -def _find_json_files(args: Iterable[str]) -> Iterable[str]: |
1035 | | - """Takes an iterator of paths to files / folders |
1036 | | -
|
1037 | | - Returns an iterator of JSON file paths (strings). |
1038 | | - """ |
1039 | | - for arg in args: |
1040 | | - if os.path.isdir(arg): |
1041 | | - for result in find(arg, extension=".json"): |
1042 | | - yield result |
1043 | | - elif arg.endswith(".json"): |
1044 | | - yield arg |
1045 | | - |
1046 | | - |
1047 | | -def filter_filenames(filenames: Iterable[str], args: list[str]) -> Iterable[str]: |
1048 | | - """Filter filenames to avoid linting cfbs generated files and hidden files. |
1049 | | -
|
1050 | | - TODO: We should better respect the user's args if they do: |
1051 | | - cfengine lint ./out/masterfies/ |
1052 | | - cfengine lint ./somepath/.somehidden/policy.cf |
1053 | | - """ |
1054 | | - |
1055 | | - for filename in filenames: |
1056 | | - if filename in args: |
1057 | | - # The filename was actually one of the args, include it regardless: |
1058 | | - yield filename |
1059 | | - continue |
1060 | | - # Skip cfbs generated files by default: |
1061 | | - if "/out/" in filename or "/." in filename: |
1062 | | - continue |
1063 | | - if filename.startswith("out/"): |
1064 | | - continue |
1065 | | - # Skip |
1066 | | - if filename.startswith(".") and not filename.startswith("./"): |
1067 | | - continue |
1068 | | - yield filename |
1069 | | - |
1070 | | - |
1071 | 1018 | def _lint_check_args(args: list[str]): |
1072 | 1019 | """Validate user-supplied paths exist, are file/folder, and have a supported extension. |
1073 | 1020 |
|
|
0 commit comments