-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2211 from awgymer/lint-system-exit
Lint check for `System.exit` calls
- Loading branch information
Showing
6 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# system_exit | ||
|
||
```{eval-rst} | ||
.. automethod:: nf_core.lint.PipelineLint.system_exit | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def system_exit(self): | ||
"""Check for System.exit calls in groovy/nextflow code | ||
Calls to System.exit(1) should be replaced by throwing errors | ||
This lint test looks for all calls to `System.exit` | ||
in any file with the `.nf` or `.groovy` extension | ||
""" | ||
passed = [] | ||
warned = [] | ||
|
||
root_dir = Path(self.wf_path) | ||
|
||
# Get all groovy and nf files | ||
groovy_files = [f for f in root_dir.rglob("*.groovy")] | ||
nf_files = [f for f in root_dir.rglob("*.nf")] | ||
to_check = nf_files + groovy_files | ||
|
||
for file in to_check: | ||
try: | ||
with file.open() as fh: | ||
for i, l in enumerate(fh.readlines(), start=1): | ||
if "System.exit" in l and not "System.exit(0)" in l: | ||
warned.append(f"`System.exit` in {file.name}: _{l.strip()}_ [line {i}]") | ||
except FileNotFoundError: | ||
log.debug(f"Could not open file {file.name} in system_exit lint test") | ||
|
||
if len(warned) == 0: | ||
passed.append("No `System.exit` calls found") | ||
|
||
return {"passed": passed, "warned": warned} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters