Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/lint-policy-in-other-repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
with:
repository: cfengine/masterfiles
path: masterfiles
- name: Checkout documentation
uses: actions/checkout@v4
with:
repository: cfengine/documentation
path: documentation
- name: Checkout modules
uses: actions/checkout@v4
with:
Expand All @@ -44,4 +49,7 @@ jobs:
run: |
uv run cfengine lint --strict no ../masterfiles
uv run cfengine lint --strict no ../modules
# TODO: Add documentation and core when ready
uv run cfengine lint --strict no ../documentation
# TODO: Add core when ready
# TODO: Do all of them together, with strict, when ready;
# uv run cfengine lint ../core ../masterfiles ../documentation ../modules
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lint: venv
uv tool run flake8 src/ --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160
uv tool run pyflakes src/
uv tool run pyright src/
uv run cfengine lint --strict=no ./

install:
pipx install --force --editable .
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "cfengine"
dynamic = ["version"]
description = "Human-oriented CLI for interacting with CFEngine tools"
description = "Human-oriented CLI for interacting with CFEngine policy language, projects, and other CFEngine tools"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.10"
Expand Down
53 changes: 0 additions & 53 deletions src/cfengine_cli/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from tree_sitter import Language, Node, Parser, Tree
from cfbs.validate import validate_config
from cfbs.cfbs_config import CFBSConfig
from cfbs.utils import find
from cfengine_cli.lint_csv import check_csv_file
from cfengine_cli.lint_yml import check_yml_file
from cfengine_cli.utils import UserError
Expand Down Expand Up @@ -1016,58 +1015,6 @@ def _lint(policy_file: PolicyFile, state: State, syntax_data: SyntaxData) -> int
return errors


def _find_policy_files(args: Iterable[str]) -> Iterable[str]:
"""Takes an iterator of paths to files / folders

Returns an iterator of CFEngine policy file paths (strings).
"""
for arg in args:
if os.path.isdir(arg):
while arg.endswith(("/.", "/")):
arg = arg[0:-1]
for result in find(arg, extension=".cf"):
yield result
elif arg.endswith(".cf"):
yield arg


def _find_json_files(args: Iterable[str]) -> Iterable[str]:
"""Takes an iterator of paths to files / folders

Returns an iterator of JSON file paths (strings).
"""
for arg in args:
if os.path.isdir(arg):
for result in find(arg, extension=".json"):
yield result
elif arg.endswith(".json"):
yield arg


def filter_filenames(filenames: Iterable[str], args: list[str]) -> Iterable[str]:
"""Filter filenames to avoid linting cfbs generated files and hidden files.

TODO: We should better respect the user's args if they do:
cfengine lint ./out/masterfies/
cfengine lint ./somepath/.somehidden/policy.cf
"""

for filename in filenames:
if filename in args:
# The filename was actually one of the args, include it regardless:
yield filename
continue
# Skip cfbs generated files by default:
if "/out/" in filename or "/." in filename:
continue
if filename.startswith("out/"):
continue
# Skip
if filename.startswith(".") and not filename.startswith("./"):
continue
yield filename


def _lint_check_args(args: list[str]):
"""Validate user-supplied paths exist, are file/folder, and have a supported extension.

Expand Down
Loading