Skip to content

Commit

Permalink
Merge pull request #79 from dmuhs/feat/rglob-blacklist
Browse files Browse the repository at this point in the history
Feat/rglob blacklist
  • Loading branch information
dmuhs committed Feb 15, 2020
2 parents 9eda6c2 + 093b461 commit 751c7ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
23 changes: 13 additions & 10 deletions mythx_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

DEFAULT_HTML_TEMPLATE = Path(__file__).parent / "templates/default.html"
DEFAULT_MD_TEMPLATE = Path(__file__).parent / "templates/default.md"
RGLOB_BLACKLIST = ["node_modules"]
LOGGER = logging.getLogger("mythx-cli")
logging.basicConfig(level=logging.WARNING)

Expand Down Expand Up @@ -301,7 +302,7 @@ def find_solidity_files(project_dir: str) -> Optional[List[str]]:
if not artifact_files:
return None

return artifact_files
return [af for af in artifact_files if all((b not in af for b in RGLOB_BLACKLIST))]


def walk_solidity_files(
Expand Down Expand Up @@ -334,9 +335,7 @@ def walk_solidity_files(


@cli.command()
@click.argument(
"target", default=None, nargs=-1, required=False
) # allow multiple targets
@click.argument("target", default=None, nargs=-1, required=False)
@click.option(
"--async/--wait", # TODO: make default on full
"async_flag",
Expand Down Expand Up @@ -778,7 +777,9 @@ def get_analysis_info(
default=None,
)
@click.option("--aesthetic", is_flag=True, default=False, hidden=True)
@click.option("--markdown", is_flag=True, default=False, help="Render the report as Markdown")
@click.option(
"--markdown", is_flag=True, default=False, help="Render the report as Markdown"
)
@click.option(
"--min-severity",
type=click.STRING,
Expand Down Expand Up @@ -835,10 +836,10 @@ def render(
template_name = default_template.name

env_kwargs = {
"trim_blocks": True,
"lstrip_blocks": True,
"keep_trailing_newline": True,
}
"trim_blocks": True,
"lstrip_blocks": True,
"keep_trailing_newline": True,
}
if not markdown:
env_kwargs = {
"trim_blocks": True,
Expand All @@ -848,7 +849,9 @@ def render(
if aesthetic:
template_name = "aesthetic.html"

env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dirs), **env_kwargs)
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dirs), **env_kwargs
)
template = env.get_template(template_name)

issues_list: List[
Expand Down
19 changes: 19 additions & 0 deletions tests/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,25 @@ def test_solidity_analyze_multiple_with_group():
assert result.exit_code == 0


def test_solidity_analyze_recursive_blacklist():
runner = CliRunner()
with mock_context(), runner.isolated_filesystem():
# initialize sample solidity file
with open("outdated.sol", "w+") as conf_f:
conf_f.write(SOLIDITY_CODE)

os.mkdir("./node_modules")
with open("./node_modules/outdated2.sol", "w+") as conf_f:
# should be ignored
conf_f.write(SOLIDITY_CODE)

result = runner.invoke(
cli, ["--debug", "--yes", "analyze", "--create-group", "."]
)
assert result.output == ISSUES_TABLE
assert result.exit_code == 0


def test_solidity_analyze_missing_version():
runner = CliRunner()
with mock_context(), runner.isolated_filesystem():
Expand Down

0 comments on commit 751c7ea

Please sign in to comment.