Skip to content

Commit

Permalink
Close #62
Browse files Browse the repository at this point in the history
  • Loading branch information
grst committed Nov 29, 2024
1 parent 6de46a8 commit ee5bc6e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ and this project adheres to [Semantic Versioning][].
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [Unreleased]
## v0.10.1

### Fixes

- Take comments into account when linting for `DSO001`

### Template updates

- Do not ignore gitignore files in output/report directories of template ([#63](https://github.com/Boehringer-Ingelheim/dso/pull/63))
- Do not ignore the `.gitignore` files in output/report directories of template ([#63](https://github.com/Boehringer-Ingelheim/dso/pull/63))

## v0.10.0

Expand Down
9 changes: 9 additions & 0 deletions src/dso/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def check(cls, file):
# .parent to remove the dvc.yaml filename
stage_path_expected = str(stage_path_expected.parent.relative_to(root_path))
content = file.read_text()

# remove comments
# TODO there are still edge cases, e.g. a `#` within a string doesn't initiate a comment
# However this is hard/impossible (?) to solve with a regular expression alone, we'd need a proper
# R parse to address all edge cases. See also https://github.com/Boehringer-Ingelheim/dso/issues/66
pattern_is_comment = re.compile(r"#.*$")
content = "\n".join([re.sub(pattern_is_comment, "", line) for line in content.split("\n")])

# detect pattern
pattern = r"[\s\S]*?(dso::)?read_params\s*\(([\s\S]*?)(\s*,.*)?\)"
res = re.findall(pattern, content, flags=re.MULTILINE)
if len(res) == 0:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ class MockQuartoRule(QuartoRule):
""",
LintError,
),
(
"""\
params = read_params("quarto_stage")
# params = read_params("quarto_stage")
""",
None,
),
# TODO no good way to cover that with regex alone, see https://github.com/Boehringer-Ingelheim/dso/issues/66
# (
# """\
# params = read_params("quarto_stage")
# print(" foo # no comment"); params = read_params("quarto_stage")
# """,
# LintError,
# ),
(
"""\
params = read_params("wrong_path")
Expand Down

0 comments on commit ee5bc6e

Please sign in to comment.