Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #24 - incorrect default file filter for formatter #25

Merged
merged 1 commit into from
Nov 19, 2024
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
5 changes: 4 additions & 1 deletion src/tctools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Tool(ABC):

LOGGER_NAME: Optional[str] = None

# Default value for file filter argument:
FILTER_DEFAULT: List[str]

def __init__(self, *args):
"""Pass e.g. ``sys.args[1:]`` (skipping the script part of the arguments).

Expand Down Expand Up @@ -109,7 +112,7 @@ def set_arguments(cls, parser):
"--filter",
help="Target files only with these patterns",
nargs="+",
default=["*.tsproj", "*.xti", "*.plcproj"],
default=cls.FILTER_DEFAULT,
)

return parser
Expand Down
4 changes: 3 additions & 1 deletion src/tctools/format/format_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class Formatter(TcTool):

LOGGER_NAME = "formatter"

FILTER_DEFAULT = ["*.TcPOU", "*.TcGVL", "*.TcDUT"]

_RULE_CLASSES: List[Type[FormattingRule]] = []

def __init__(self, *args):
Expand Down Expand Up @@ -133,7 +135,7 @@ def run(self) -> int:
self.logger.info("No changes to be made in checked files!")
return 0

self.logger.info(f"{self.files_to_alter} path(s) can be re-sorted")
self.logger.info(f"{self.files_to_alter} path(s) should altered")
return 1

self.logger.info(f"Re-saved {self.files_resaved} path(s)")
Expand Down
4 changes: 3 additions & 1 deletion src/tctools/xml_sort/xml_sort_class.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Dict
from typing import Dict, List

from lxml import etree

Expand All @@ -14,6 +14,8 @@ class XmlSorter(TcTool):

LOGGER_NAME = "xml_sorter"

FILTER_DEFAULT: List[str] = ["*.tsproj", "*.xti", "*.plcproj"]

def __init__(self, *args):
super().__init__(*args)

Expand Down
26 changes: 26 additions & 0 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,32 @@ def test_check(plc_code, caplog):
assert code_new == 0


def test_check_recursive(plc_code, caplog):
"""Test `check` flag for formatter, on a folder"""
project_folder = plc_code / "TwinCAT Project1"
config = project_folder / ".editorconfig"
config.write_text(
"""root = true
[*.TcPOU]
indent_style = space
indent_size = 4
"""
)
formatter = Formatter(str(project_folder), "--check", "-r", "-l", "DEBUG")
code = formatter.run()

for expected_file in [
"FB_Example.TcPOU",
"FB_Full.TcPOU",
"MAIN.TcPOU",
"GVL_Version.TcGVL",
"ST_Example.TcDUT",
]:
assert any(expected_file in msg for msg in caplog.messages)

assert code != 0


def test_reformat_empty_config(plc_code):
"""Test reformatting with no or empty `editorconfig`.

Expand Down
Loading