# Buggy code
def stats(self):
    """Return a stats dictionary of this result."""
    all_stats = dict(files=0, clean=0, unclean=0, violations=0)
    for path in self.paths:
        all_stats = self.sum_dicts(path.stats(), all_stats)
    all_stats["avg per file"] = all_stats["violations"] * 1.0 / all_stats["files"]
    all_stats["unclean rate"] = all_stats["unclean"] * 1.0 / all_stats["files"]
    all_stats["clean files"] = all_stats["clean"]
    all_stats["unclean files"] = all_stats["unclean"]
    all_stats["exit code"] = 65 if all_stats["violations"] > 0 else 0
    all_stats["status"] = "FAIL" if all_stats["violations"] > 0 else "PASS"
    return all_stats


# Traceback (ZeroDivisionError)
Traceback (most recent call last):

File "/usr/local/pyenv/versions/lib-3.7.3/bin/sqlfluff", line 11, in <module>

load_entry_point('sqlfluff==0.3.1', 'console_scripts', 'sqlfluff')()

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/click/core.py", line 829, in __call__

return self.main(*args, **kwargs)

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/click/core.py", line 782, in main

rv = self.invoke(ctx)

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/click/core.py", line 1259, in invoke

return _process_result(sub_ctx.command.invoke(sub_ctx))

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/click/core.py", line 1066, in invoke

return ctx.invoke(self.callback, **ctx.params)

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/click/core.py", line 610, in invoke

return callback(*args, **kwargs)

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/sqlfluff/cli/commands.py", line 150, in lint

lnt.log(format_linting_result_footer(result, verbose=verbose))

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/sqlfluff/cli/formatters.py", line 146, in format_linting_result_footer

text_buffer.write(format_linting_stats(result, verbose=verbose))

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/sqlfluff/cli/formatters.py", line 106, in format_linting_stats

all_stats = result.stats()

File "/usr/local/pyenv/versions/3.7.3/envs/lib-3.7.3/lib/python3.7/site-packages/sqlfluff/linter.py", line 381, in stats

all_stats['avg per file'] = all_stats['violations'] * 1.0 / all_stats['files']

ZeroDivisionError: float division by zero

# Fixed code
def stats(self):
    """Return a stats dictionary of this result."""
    all_stats = dict(files=0, clean=0, unclean=0, violations=0)
    for path in self.paths:
        all_stats = self.sum_dicts(path.stats(), all_stats)
    if all_stats["files"] > 0:
        all_stats["avg per file"] = all_stats["violations"] * 1.0 / all_stats["files"]
        all_stats["unclean rate"] = all_stats["unclean"] * 1.0 / all_stats["files"]
    else:
        all_stats["avg per file"] = 0
        all_stats["unclean rate"] = 0
    all_stats["clean files"] = all_stats["clean"]
    all_stats["unclean files"] = all_stats["unclean"]
    all_stats["exit code"] = 65 if all_stats["violations"] > 0 else 0
    all_stats["status"] = "FAIL" if all_stats["violations"] > 0 else "PASS"
    return all_stats