Skip to content

Commit 71bc662

Browse files
committed
Fixed #24 - incorrect default file filter for formatter
1 parent de33245 commit 71bc662

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/tctools/common.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Tool(ABC):
2020

2121
LOGGER_NAME: Optional[str] = None
2222

23+
# Default value for file filter argument:
24+
FILTER_DEFAULT: List[str]
25+
2326
def __init__(self, *args):
2427
"""Pass e.g. ``sys.args[1:]`` (skipping the script part of the arguments).
2528
@@ -109,7 +112,7 @@ def set_arguments(cls, parser):
109112
"--filter",
110113
help="Target files only with these patterns",
111114
nargs="+",
112-
default=["*.tsproj", "*.xti", "*.plcproj"],
115+
default=cls.FILTER_DEFAULT,
113116
)
114117

115118
return parser

src/tctools/format/format_class.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class Formatter(TcTool):
9393

9494
LOGGER_NAME = "formatter"
9595

96+
FILTER_DEFAULT = ["*.TcPOU", "*.TcGVL", "*.TcDUT"]
97+
9698
_RULE_CLASSES: List[Type[FormattingRule]] = []
9799

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

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

139141
self.logger.info(f"Re-saved {self.files_resaved} path(s)")

src/tctools/xml_sort/xml_sort_class.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Dict
2+
from typing import Dict, List
33

44
from lxml import etree
55

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

1515
LOGGER_NAME = "xml_sorter"
1616

17+
FILTER_DEFAULT: List[str] = ["*.tsproj", "*.xti", "*.plcproj"]
18+
1719
def __init__(self, *args):
1820
super().__init__(*args)
1921

tests/test_formatter.py

+26
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,32 @@ def test_check(plc_code, caplog):
158158
assert code_new == 0
159159

160160

161+
def test_check_recursive(plc_code, caplog):
162+
"""Test `check` flag for formatter, on a folder"""
163+
project_folder = plc_code / "TwinCAT Project1"
164+
config = project_folder / ".editorconfig"
165+
config.write_text(
166+
"""root = true
167+
[*.TcPOU]
168+
indent_style = space
169+
indent_size = 4
170+
"""
171+
)
172+
formatter = Formatter(str(project_folder), "--check", "-r", "-l", "DEBUG")
173+
code = formatter.run()
174+
175+
for expected_file in [
176+
"FB_Example.TcPOU",
177+
"FB_Full.TcPOU",
178+
"MAIN.TcPOU",
179+
"GVL_Version.TcGVL",
180+
"ST_Example.TcDUT",
181+
]:
182+
assert any(expected_file in msg for msg in caplog.messages)
183+
184+
assert code != 0
185+
186+
161187
def test_reformat_empty_config(plc_code):
162188
"""Test reformatting with no or empty `editorconfig`.
163189

0 commit comments

Comments
 (0)