Skip to content

Commit

Permalink
Merge pull request #96 from bwrsandman/empty-config
Browse files Browse the repository at this point in the history
Allow not setting config file
  • Loading branch information
ZedThree authored Oct 11, 2023
2 parents 6f3fc9a + 4a703b6 commit e3c07fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ at once, so `clang-tidy-review` will only attempt to post the first
- `clang_tidy_checks`: List of checks
- default: `'-*,performance-*,readability-*,bugprone-*,clang-analyzer-*,cppcoreguidelines-*,mpi-*,misc-*'`
- `config_file`: Path to clang-tidy config file, replaces `clang_tidy_checks`
- default: `.clang-tidy` if it already exists, otherwise ''
- default: '' which will use `clang_tidy_checks` if there are any, else closest `.clang-tidy` to each file
- `include`: Comma-separated list of files or patterns to include
- default: `"*.[ch],*.[ch]xx,*.[ch]pp,*.[ch]++,*.cc,*.hh"`
- `exclude`: Comma-separated list of files or patterns to exclude
Expand Down
12 changes: 3 additions & 9 deletions post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,10 @@ def config_file_or_checks(
):
version = clang_tidy_version(clang_tidy_binary)

# If config_file is set, use that
if config_file == "":
if pathlib.Path(".clang-tidy").exists():
config_file = ".clang-tidy"
elif not pathlib.Path(config_file).exists():
print(f"WARNING: Could not find specified config file '{config_file}'")
config_file = ""

if not config_file:
return f"--checks={clang_tidy_checks}"
if clang_tidy_checks:
return f"--checks={clang_tidy_checks}"
return ""

if version >= 12:
return f'--config-file="{config_file}"'
Expand Down
31 changes: 18 additions & 13 deletions tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,26 +399,31 @@ def test_config_file(monkeypatch, tmp_path):
# Mock out the actual call so this test doesn't depend on a
# particular version of clang-tidy being installed
monkeypatch.setattr(
ctr.subprocess, "run", lambda *args, **kwargs: MockClangTidyVersionProcess(12)
ctr.subprocess, "run", lambda *args, **kwargs: MockClangTidyVersionProcess(15)
)

config_file = tmp_path / ".clang-tidy"
config_file.touch()

flag = ctr.config_file_or_checks("not-clang-tidy", "readability", str(config_file))
# If you set clang_tidy_checks to something and config_file to something, config_file is sent to clang-tidy.
flag = ctr.config_file_or_checks(
"not-clang-tidy", clang_tidy_checks="readability", config_file=str(config_file)
)
assert flag == f'--config-file="{config_file}"'

os.chdir(tmp_path)
flag = ctr.config_file_or_checks("not-clang-tidy", "readability", "")
assert flag == '--config-file=".clang-tidy"'

monkeypatch.setattr(
ctr.subprocess, "run", lambda *args, **kwargs: MockClangTidyVersionProcess(11)
# If you set clang_tidy_checks and config_file to an empty string, neither are sent to the clang-tidy.
flag = ctr.config_file_or_checks(
"not-clang-tidy", clang_tidy_checks="", config_file=""
)
flag = ctr.config_file_or_checks("not-clang-tidy", "readability", "")
assert flag == "--config"
assert flag == f""

config_file.unlink()
# If you get config_file to something, config_file is sent to clang-tidy.
flag = ctr.config_file_or_checks(
"not-clang-tidy", clang_tidy_checks="", config_file=str(config_file)
)
assert flag == f'--config-file="{config_file}"'

flag = ctr.config_file_or_checks("not-clang-tidy", "readability", "")
# If you get clang_tidy_checks to something and config_file to nothing, clang_tidy_checks is sent to clang-tidy.
flag = ctr.config_file_or_checks(
"not-clang-tidy", clang_tidy_checks="readability", config_file=""
)
assert flag == "--checks=readability"

0 comments on commit e3c07fc

Please sign in to comment.