Skip to content

Commit

Permalink
Add clazy restyler
Browse files Browse the repository at this point in the history
I'm not 100% this is working since I can't get it to do anything without
using `-checks=level2`. The behavior doesn't seem to match the
documentation there, which could be a me problem or not.

In any event, this is not harmful and so is good to ship, now that I was
able to add that `-checks=level2` in only the tests. Maybe an
experienced user can figure this out.
  • Loading branch information
pbrisbin committed Nov 21, 2024
1 parent c9824b9 commit b576a6b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
21 changes: 21 additions & 0 deletions clazy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:22.04
LABEL maintainer="Pat Brisbin [email protected]"
ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN \
apt-get update && \
apt-get -y --no-install-recommends install \
clang \
clang-tools \
clazy \
cmake \
make \
locales \
qt6-base-dev && \
locale-gen en_US.UTF-8 && \
rm -rf /var/lib/apt/lists/*
ENV LANG=en_US.UTF-8
COPY clazy-standlone-apply /usr/local/bin/clazy-standalone-apply
RUN mkdir -p /code
WORKDIR /code
ENTRYPOINT []
CMD ["clazy-standalone-apply", "--help"]
9 changes: 9 additions & 0 deletions clazy/clazy-standlone-apply
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -eou pipefail

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
clazy-standalone --export-fixes="$tmp"/fixes.yaml "$@"
clang-apply-replacements "$tmp"
62 changes: 62 additions & 0 deletions clazy/info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
enabled: true
name: clazy
command:
- clazy-standalone-apply
supports_arg_sep: false
version_cmd: |
apt-cache policy clazy | sed '/^ *Installed: \(.*\)$/!d; s//v\1/'
include:
- "**/*.cpp"
documentation:
- https://github.com/KDE/clazy
metadata:
languages:
- C++
tests:
- name: qstring-allocations
arguments: ["-checks=level2"]
support:
path: CMakeLists.txt
contents: |
cmake_minimum_required(VERSION 3.16)
project(helloworld VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt6 REQUIRED COMPONENTS Core)
add_executable(helloworld
clazy-test-1.cpp
)
target_link_libraries(helloworld PRIVATE Qt6::Core)
contents: |
#include <iostream>
#include <QString>
int main() {
QString str = "hello";
QString result = str.left(1);
std::cout << "Original string: " << str.toStdString() << std::endl;
std::cout << "Substring from index 5 onwards: " << result.toStdString() << std::endl;
return 0;
}
restyled: |
#include <iostream>
#include <QString>
int main() {
QString str = QStringLiteral("hello");
QString result = str.left(1);
std::cout << "Original string: " << str.toStdString() << std::endl;
std::cout << "Substring from index 5 onwards: " << result.toStdString() << std::endl;
return 0;
}

0 comments on commit b576a6b

Please sign in to comment.