Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sonar Issues #7

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --action_env=BAZEL_CXXOPTS="-std=c++2a:-Werror"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://img.shields.io/github/license/gvatsal60/Bazel_Cpp_Template)
[![build status](https://github.com/gvatsal60/Bazel_Cpp_Template/actions/workflows/readme-checker.yaml/badge.svg)](https://github.com/gvatsal60/Bazel_Cpp_Template/actions/workflows/readme-checker.yaml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/gvatsal60/Bazel_Cpp_Template/master.svg)](https://results.pre-commit.ci/latest/github/gvatsal60/Bazel_Cpp_Template/HEAD)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gvatsal60_Bazel_Cpp_Template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=gvatsal60_Bazel_Cpp_Template)
![GitHub pull-requests](https://img.shields.io/github/issues-pr/gvatsal60/Bazel_Cpp_Template)
![GitHub Issues](https://img.shields.io/github/issues/gvatsal60/Bazel_Cpp_Template)
![GitHub forks](https://img.shields.io/github/forks/gvatsal60/Bazel_Cpp_Template)
Expand Down
2 changes: 2 additions & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ RUN apt-get update \
build-essential \
ca-certificates \
curl \
gdb \
git \
valgrind \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
17 changes: 14 additions & 3 deletions project/lib/src/hello-time.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#include "hello-time.h"
#include <ctime>
#include <chrono>
#include <iomanip>
#include <iostream>

void print_localtime() {
std::time_t result = std::time(nullptr);
std::cout << std::asctime(std::localtime(&result));
const auto now = std::chrono::system_clock::now();
std::time_t result = std::chrono::system_clock::to_time_t(now);

// Convert to local time using std::localtime_r
struct std::tm tm;
if (localtime_r(&result, &tm) == nullptr) {
std::cerr << "Error: localtime_r failed!" << std::endl;
return;
}

// Print formatted time using std::put_time
std::cout << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") << std::endl;
}
43 changes: 43 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This is the SonarQube project key. This is a unique identifier for the project.
sonar.projectKey=Bazel_Cpp_Template

# This is the name of the project that will appear in the SonarQube dashboard.
sonar.projectName=Bazel_Cpp_Template

# This is the version of the project (usually your project version, e.g., 1.0, 2.0, etc.)
sonar.projectVersion=1.0

# The location of header files. By default, SonarQube looks for C++ header files in the `src` folder.
# You can modify this if your headers are in a different folder (e.g., `include`).
sonar.cxx.includeDirectories=inc

# Set the C++ compiler to use. SonarQube will use this to identify the compiler settings.
# Ensure that the compiler flags (e.g., -std=c++11) are appropriately set for your project.
sonar.cxx.compiler=g++ # or g++

# The location of the build output files (e.g., compiled binaries, object files).
# For instance, if you're using CMake, this might be the directory where CMake puts its build artifacts.
sonar.cxx.buildDir=bazel-bin

# Path to the `compile_commands.json` file generated by CMake or other build systems.
# Set this to the path where `compile_commands.json` is located. Usually, this is inside your build directory.
sonar.cfamily.compile-commands=compile_commands.json

# The location of the .git directory. This is used for version control information.
# If you use a different VCS, you can specify it here (e.g., svn).
sonar.scm.provider=git
sonar.scm.revision=refs/heads/main # adjust for your default branch

# Optional: Set up exclusion for files or directories you don't want to analyze.
# For example, excluding all test files:
sonar.exclusions=**/test/**

# The location of the test source files (for unit tests, integration tests, etc.).
# Specify the directory containing your test source code.
sonar.tests=tests

# Optional: Set the encoding of the source files.
sonar.sourceEncoding=UTF-8

# Optional: Enable additional analysis for C++ code (static code analysis).
sonar.cxx.clangTidy.enabled=true # enable Clang-Tidy for additional linting