Files
vern-nvim/lua/vern-nvim/templates/cpp.lua
T

138 lines
4.1 KiB
Lua

return {
--[[ =====================================================================
TEMPLATE: MAIN (Entrypoint)
File: main.cpp
Target: src/main.cpp
===================================================================== --]]
main = vim.trim([=[
#include <iostream>
int
main()
{
std::string str = "Hello World";
std::cout << str << "\n";
return 0;
}
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: CLANG-FORMAT (Code formatter)
File: .clang-format
Target: .clang-format
===================================================================== --]]
format = vim.trim([=[
---
BasedOnStyle: Google
Standard: Latest
UseTab: Always
TabWidth: 8
IndentWidth: 8
BreakBeforeBraces: Allman
SpaceBeforeCpp11BracedList: true
SeparateDefinitionBlocks: Always
Cpp11BracedListStyle: false
BreakAfterReturnType: TopLevel
ReflowComments: Always
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
IndentAccessModifiers: false # Indent access specifiers by one level
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
IndentGotoLabels: InnerIndent
DerivePointerAlignment: false
PointerAlignment: Left
IndentPPDirectives: AfterHash
SortIncludes: CaseSensitive
IncludeBlocks: Preserve
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: CMAKELISTS (Spec / Build Manifest)
File: CMakeLists.txt
Target: CMakeLists.txt
===================================================================== --]]
CmakeLists = vim.trim([=[
cmake_minimum_required(VERSION 3.16)
project(__PROJECT_NAME__ LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(LIB_SOURCES
# Add your other types here as you implement them:
# src/example1.cpp
# src/example2.cpp
)
if(LIB_SOURCES)
add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES})
target_include_directories(__PROJECT_NAME__
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
endif()
add_executable(__PROJECT_NAME___bin src/main.cpp)
set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__")
if(TARGET __PROJECT_NAME__)
target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__)
endif()
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: HEADER (Standalone File)
File: {name}.hpp
Target: include/{project_name}/{name}.hpp
===================================================================== --]]
header = vim.trim([=[
#ifndef __PROJECT_NAME___HPP
#define __PROJECT_NAME___HPP
// Code
#endif /* __PROJECT_NAME___HPP */
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: SOURCE (Standalone File)
File: {name}.cpp
Target: src/{name}.cpp
===================================================================== --]]
source = vim.trim([=[
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: CLANG_TIDY (LINTER)
File: .clang-tidy
Target: .clang-tidy
===================================================================== --]]
linter = vim.trim([=[
Checks: >
-*,
clang-analyzer-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
performance-*,
security-*
readability-redundant-declaration
readability-misleading-indentation
readability-implicit-bool-conversion
misc-misplaced-const,
misc-include-cleaner
-bugprone-narrowing-conversions,
-readability-identifier-length
CheckOptions:
readability-identifier-naming.VariableCase: lower_case
readability-identifier-naming.FunctionCase: lower_case
readability-identifier-naming.StructCase: lower_case
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.EnumConstantCase: UPPER_CASE
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
]=]) .. "\n",
}