chore(clang): add more linting tasks

This commit is contained in:
Jeremy Attali 2020-06-13 18:55:39 -04:00
parent 58aef1ef37
commit e8a96364dc
8 changed files with 67 additions and 16 deletions

38
.clang-tidy Normal file
View File

@ -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'
...

View File

@ -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

View File

@ -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"
@ -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);
}

View File

@ -7,7 +7,6 @@
#include <unistd.h>
#include "box.h"
#include "wayland.h"
static void randname(char *buf) {
struct timespec ts;
@ -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,

View File

@ -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);

View File

@ -1,4 +1,4 @@
#define _POSIX_C_SOURCE 2
#define _POSIX_C_SOURCE 200809L
#include "application.h"
#include "config.h"

View File

@ -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);
}
@ -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);
}

View File

@ -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));