Skip to content

Commit

Permalink
Add "clang-tidy" integration and fix outstanding issues
Browse files Browse the repository at this point in the history
clang-tidy is a C linter built as part of the LLVM project. You can run
it against ashuffle sources by running:

```
meson -Dtidy_mode=true build
ninja -C build clang-tidy
```
  • Loading branch information
joshkunz committed Sep 15, 2019
1 parent 4855cae commit 15d84da
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
30 changes: 30 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-valist.Uninitialized,-clang-analyzer-security.insecureAPI.*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: josh
CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

17 changes: 16 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,28 @@ low_dep_sources = [

sources = low_dep_sources + high_dep_sources

executable_sources = sources + ['src/main.c']

clientlib = dependency('libmpdclient')

ashuffle = executable(
'ashuffle',
sources + ['src/main.c'],
executable_sources,
dependencies: clientlib,
install: true
)

if get_option('tidy_mode')
clang_tidy = run_target('clang-tidy',
command : ['clang-tidy',
'-p', meson.build_root(),
] + executable_sources,
)
endif

# We only generate tests if we are *not running in tidy mode
if not get_option('tidy_mode')

subdir('t')

test_c_args = [
Expand Down Expand Up @@ -62,3 +75,5 @@ foreach test_name, test_sources : tests
)
test(test_name, test_exe)
endforeach

endif # tidy_mode
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('tidy_mode', type : 'boolean', value : 'false')
7 changes: 3 additions & 4 deletions src/ashuffle.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool ruleset_accepts_uri(struct mpd_connection * mpd,
/* even though we're searching for a single song, libmpdclient
* still acts like we're reading a song list. We read an aditional
* element to convince MPD this is the end of the song list. */
song = mpd_recv_song(mpd);
(void) mpd_recv_song(mpd);
} else {
fprintf(stderr, "Song uri '%s' not found.\n", uri);
}
Expand All @@ -102,11 +102,10 @@ int build_songs_file(struct mpd_connection * mpd, struct list * ruleset,
}

/* if this line has terminating newline attached, set it
* to null and decrement the length (effectively removing
* the newline). */
* to null (effectively removing the newline). */
if (uri[length - 1] == '\n') {
uri[length - 1] = '\0';
length -= 1;
uri[length] = '\0';
}

if ((check && ruleset_accepts_uri(mpd, ruleset, uri)) || (! check)) {
Expand Down
4 changes: 4 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ char * xsprintf(const char * fmt, ...) {
abort();
}

va_end(rest);

return res;
}

Expand All @@ -47,5 +49,7 @@ void die(const char * fmt, ...) {
strcat(fmt_nl, "\n");

vfprintf(stderr, fmt_nl, rest);

va_end(rest);
exit(1);
}

0 comments on commit 15d84da

Please sign in to comment.