Skip to content

Commit

Permalink
Merge pull request #6459 from wxtim/lint.6456.fewer_line_continuations
Browse files Browse the repository at this point in the history
Lint: Tell users that backslashes are no longer necessary after => & |
  • Loading branch information
wxtim authored Nov 22, 2024
2 parents 791c0ce + d844dfd commit ee20614
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes.d/6459.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`cylc lint` now checks for unnecessary continuation characters in the graph section.
14 changes: 13 additions & 1 deletion cylc/flow/scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,13 @@ def list_wrapper(line: str, check: Callable) -> Optional[Dict[str, str]]:
'S013': {
'short': 'Items should be indented in 4 space blocks.',
FUNCTION: check_indentation
}
},
'S014': {
'short': (
'`=>` implies line continuation without `\\`'
),
FUNCTION: re.compile(r'=>\s*\\').findall
},
}
# Subset of deprecations which are tricky (impossible?) to scrape from the
# upgrader.
Expand Down Expand Up @@ -715,6 +721,12 @@ def list_wrapper(line: str, check: Callable) -> Optional[Dict[str, str]]:
FUNCTION: functools.partial(
list_wrapper, check=CHECK_FOR_OLD_VARS.findall),
},
'U017': {
'short': (
'`&` and `|` imply line continuation without `\\`'
),
FUNCTION: re.compile(r'[&|]\s*\\').findall
},
}
ALL_RULESETS = ['728', 'style', 'all']
EXTRA_TOML_VALIDATION = {
Expand Down
21 changes: 16 additions & 5 deletions tests/unit/scripts/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
STYLE_CHECKS = parse_checks(['style'])
UPG_CHECKS = parse_checks(['728'])

TEST_FILE = """
TEST_FILE = '''
[visualization]
[cylc]
Expand Down Expand Up @@ -97,7 +97,13 @@
hold after point = 20220101T0000Z
[[dependencies]]
[[[R1]]]
graph = MyFaM:finish-all => remote => !mash_theme
graph = """
MyFaM:finish-all => remote => !mash_theme
a & \\
b => c
c | \\
d => e
"""
[runtime]
[[root]]
Expand Down Expand Up @@ -154,10 +160,10 @@
host = `rose host-select thingy`
%include foo.cylc
"""
'''


LINT_TEST_FILE = """
LINT_TEST_FILE = '''
\t[scheduler]
[scheduler]
Expand All @@ -167,6 +173,11 @@
{% foo %}
{{foo}}
# {{quix}}
R1 = """
foo & \\
bar => \\
baz
"""
[runtime]
[[this_is_ok]]
Expand All @@ -180,7 +191,7 @@
platform = $(some-script foo)
[[baz]]
platform = `no backticks`
""" + (
''' + (
'\nscript = the quick brown fox jumps over the lazy dog until it becomes '
'clear that this line is longer than the default 130 character limit.'
)
Expand Down

0 comments on commit ee20614

Please sign in to comment.