Skip to content

Commit

Permalink
chore(clang): add more linting tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Jun 13, 2020
1 parent 58aef1e commit e8a9636
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 16 deletions.
38 changes: 38 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: jattali
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- 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'
...

26 changes: 19 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ name: CI
on: [push]

jobs:
build:
runs-on: ubuntu-latest

build-gcc:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Build
- name: GCC build
run: |
sudo apt-get update
sudo apt-get install python3-setuptools ninja-build libgtk-3-dev wayland-protocols
sudo apt --yes install libgtk-3-dev libnotify-dev meson ninja-build scdoc
pkg-config --list-all
sudo pip3 install meson
meson build
CC=gcc meson build
ninja -C build
build-clang:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Clang buid
run: |
sudo apt --yes install libgtk-3-dev libnotify-dev meson ninja-build scdoc clang clang-format clang-tidy
CC=clang meson build
ninja -C build
echo "Making sure clang-format is correct..."
git ls-files -- '*.[ch]' | xargs clang-format -Werror -n
echo "Running clang-tidy..."
run-clang-tidy -p build
5 changes: 2 additions & 3 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "clipboard.h"
#include "config.h"
#include "file.h"
#include "notification.h"
#include "paint.h"
#include "pixbuf.h"
#include "render.h"
Expand All @@ -33,14 +32,14 @@ static void update_ui_undo_redo(struct swappy_state *state) {
static void update_ui_stroke_size_widget(struct swappy_state *state) {
GtkButton *button = GTK_BUTTON(state->ui->line_size);
char label[255];
snprintf(label, 255, "%.0lf", state->settings.w);
g_snprintf(label, 255, "%.0lf", state->settings.w);
gtk_button_set_label(button, label);
}

static void update_ui_text_size_widget(struct swappy_state *state) {
GtkButton *button = GTK_BUTTON(state->ui->text_size);
char label[255];
snprintf(label, 255, "%.0lf", state->settings.t);
g_snprintf(label, 255, "%.0lf", state->settings.t);
gtk_button_set_label(button, label);
}

Expand Down
3 changes: 2 additions & 1 deletion src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <unistd.h>

#include "box.h"
#include "wayland.h"

static void randname(char *buf) {
struct timespec ts;
Expand Down Expand Up @@ -153,6 +152,8 @@ bool buffer_init_from_screencopy(struct swappy_state *state) {
size_t n_pending = 0;
struct swappy_output *output;

g_assert(geometry != NULL);

const struct zwlr_screencopy_frame_v1_listener screencopy_frame_listener = {
.buffer = screencopy_frame_handle_buffer,
.flags = screencopy_frame_handle_flags,
Expand Down
2 changes: 1 addition & 1 deletion src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool clipboard_copy_drawing_area_to_selection(struct swappy_state *state) {
}

char message[MAX_PATH];
snprintf(message, MAX_PATH, "Swappshot copied to clipboard\n");
g_snprintf(message, MAX_PATH, "Swappshot copied to clipboard\n");
notification_send("Swappy", message);
g_object_unref(pixbuf);

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define _POSIX_C_SOURCE 2
#define _POSIX_C_SOURCE 200809L

#include "application.h"
#include "config.h"
Expand Down
5 changes: 3 additions & 2 deletions src/pixbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void write_file(GdkPixbuf *pixbuf, char *path) {
char *msg = "Saved Swappshot to: ";
size_t len = strlen(msg) + strlen(path) + 1;
char *message = g_new(char, len);
snprintf(message, len, "%s%s", msg, path);
g_snprintf(message, len, "%s%s", msg, path);
notification_send("Swappy", message);
g_free(message);
}
Expand All @@ -40,7 +40,8 @@ void pixbuf_save_state_to_folder(GdkPixbuf *pixbuf, char *folder) {
c_time_string = ctime(&current_time);
c_time_string[strlen(c_time_string) - 1] = '\0';
char path[MAX_PATH];
snprintf(path, MAX_PATH, "%s/%s %s.png", folder, "Swappshot", c_time_string);
g_snprintf(path, MAX_PATH, "%s/%s %s.png", folder, "Swappshot",
c_time_string);
write_file(pixbuf, path);
}

Expand Down
2 changes: 1 addition & 1 deletion src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void render_text(cairo_t *cr, struct swappy_paint_text text) {

pango_layout_t *layout = pango_cairo_create_layout(crt);
pango_layout_set_text(layout, text.text, -1);
snprintf(pango_font, 255, "%s %d", text.font, (int)text.s);
g_snprintf(pango_font, 255, "%s %d", text.font, (int)text.s);
pango_font_description_t *desc =
pango_font_description_from_string(pango_font);
pango_layout_set_width(layout, pango_units_from_double(w));
Expand Down

0 comments on commit e8a9636

Please sign in to comment.