Skip to content

Commit 0bc9586

Browse files
committed
Merge branch 'main' of https://github.com/MarketSquare/robotframework-tidy into fix/extra_new_line
2 parents 13a6196 + a45cfdd commit 0bc9586

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

robotidy/cli.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@
1818

1919

2020
INCLUDE_EXT = ('.robot', '.resource')
21+
HELP_MSG = f"""
22+
Version: {__version__}
23+
24+
Robotidy is a tool for formatting Robot Framework source code.
25+
See examples at the end of this help message too see how you can use Robotidy.
26+
For more documentation check README section at https://github.com/MarketSquare/robotframework-tidy
27+
"""
28+
EPILOG = """
29+
Examples:
30+
# Format `path/to/src.robot` file
31+
$ robotidy path/to/src.robot
32+
33+
# Format every Robot Framework file inside `dir_name` directory
34+
$ robotidy dir_name
35+
36+
# List available transformers:
37+
$ robotidy --list-transformers
38+
39+
# Display transformer documentation
40+
$ robotidy --describe-transformer <TRANSFORMER_NAME>
41+
42+
# Format `src.robot` file using `SplitTooLongLine` transformer only
43+
$ robotidy --transform SplitTooLongLine src.robot
44+
45+
# Format `src.robot` file using `SplitTooLongLine` transformer only and configured line length 140
46+
$ robotidy --transform SplitTooLongLine:line_length=140 src.robot
47+
48+
"""
49+
50+
51+
class RawHelp(click.Command):
52+
def format_help_text(self, ctx, formatter):
53+
if self.help:
54+
formatter.write_paragraph()
55+
for line in self.help.split('\n'):
56+
formatter.write_text(line)
57+
58+
def format_epilog(self, ctx, formatter):
59+
if self.epilog:
60+
formatter.write_paragraph()
61+
for line in self.epilog.split('\n'):
62+
formatter.write_text(line)
2163

2264

2365
class TransformType(click.ParamType):
@@ -142,7 +184,7 @@ def get_paths(src: Tuple[str, ...]):
142184
return sources
143185

144186

145-
@click.command()
187+
@click.command(cls=RawHelp, help=HELP_MSG, epilog=EPILOG)
146188
@click.option(
147189
'--transform',
148190
type=TransformType(),

robotidy/transformers/SplitTooLongLine.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,41 @@
22
ModelTransformer,
33
Token
44
)
5+
from robotidy.decorators import check_start_end_line
56

67

78
EOL = Token(Token.EOL)
89
CONTINUATION = Token(Token.CONTINUATION)
910

1011

1112
class SplitTooLongLine(ModelTransformer):
13+
"""
14+
Split too long lines.
15+
If any line in keyword call exceeds given length limit (configurable using ``line_length``, 120 by default) it will be
16+
split::
17+
18+
Keyword With Longer Name ${arg1} ${arg2} ${arg3} # let's assume that arg2 is at 120 char
19+
20+
To::
21+
22+
Keyword With Longer Name ${arg1}
23+
... ${arg2} ${arg3}
24+
25+
Using ``split_on_every_arg`` flag (``False`` by default), you can force the formatter to put every argument in a new line::
26+
27+
Keyword With Longer Name
28+
... ${arg1}
29+
... ${arg2}
30+
... ${arg3}
31+
32+
Supports global formatting params: ``space_count``, ``--startline`` and ``--endline``.
33+
"""
1234
def __init__(self, line_length: int = 120, split_on_every_arg: bool = False):
1335
super().__init__()
1436
self.line_length = line_length
1537
self.split_on_every_arg = split_on_every_arg
1638

39+
@check_start_end_line
1740
def visit_KeywordCall(self, node): # noqa
1841
if all(line[-1].end_col_offset < self.line_length for line in node.lines):
1942
return node

robotidy/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.1'
1+
__version__ = '1.0.0'

0 commit comments

Comments
 (0)