add nix .clang-format

This commit is contained in:
do butterflies cry? 2026-04-02 23:39:14 +10:00
parent 0a4cfcce7d
commit 91ccc02af2
Signed by: cry
GPG key ID: F68745A836CA0412
2 changed files with 135 additions and 0 deletions

39
.clang-format Normal file
View file

@ -0,0 +1,39 @@
#-* This file was taken directly from the official Nix repository
#-* hosted on GitHub, such that Nixide upholds the style guidelines.
#-* REF: https://github.com/NixOS/nix.git
BasedOnStyle: LLVM
IndentWidth: 4
BreakBeforeBraces: Custom
BraceWrapping:
AfterStruct: true
AfterClass: true
AfterFunction: true
AfterUnion: true
SplitEmptyRecord: false
PointerAlignment: Middle
FixNamespaceComments: true
SortIncludes: Never
#IndentPPDirectives: BeforeHash
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlines: Left
ColumnLimit: 120
BreakStringLiterals: false
BitFieldColonSpacing: None
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: Yes
BinPackParameters: false
BreakConstructorInitializers: BeforeComma
EmptyLineAfterAccessModifier: Leave # change to always/never later?
EmptyLineBeforeAccessModifier: Leave
#PackConstructorInitializers: BinPack
BreakBeforeBinaryOperators: NonAssignment
AlwaysBreakBeforeMultilineStrings: true
IndentPPDirectives: AfterHash
PPIndentWidth: 2
BinPackArguments: false
BreakBeforeTernaryOperators: true
SeparateDefinitionBlocks: Always

96
.clang-tidy Normal file
View file

@ -0,0 +1,96 @@
#-* This file was taken directly from the official Nix repository
#-* hosted on GitHub, such that Nixide upholds the style guidelines.
#-* REF: https://github.com/NixOS/nix.git
UseColor: true
Checks:
- -*
- bugprone-*
# Too many warnings
- -bugprone-assignment-in-if-condition
# Too many warnings
- -bugprone-narrowing-conversions
# Kind of nonsense
- -bugprone-easily-swappable-parameters
# Too many warnings for now
- -bugprone-implicit-widening-of-multiplication-result
# Exception handling patterns in Nix
- -bugprone-empty-catch
# Many warnings
- -bugprone-unchecked-optional-access
# Many warnings, questionable lint
- -bugprone-branch-clone
# Extremely noisy before clang 19: https://github.com/llvm/llvm-project/issues/93959
- -bugprone-multi-level-implicit-pointer-conversion
# We don't compile out our asserts
- -bugprone-assert-side-effect
# TODO: figure out if this warning is useful
- -bugprone-exception-escape
# We use pointers to aggregates intentionally; void * would look weird
- -bugprone-sizeof-expression
#
# Checks disabled to pass on current codebase (can be progressively enabled):
#
# 11 warnings - optional value conversions in various places
- -bugprone-optional-value-conversion
# 4 warnings - switches without default cases
- -bugprone-switch-missing-default-case
# 4 warnings - string_view::data() usage patterns
- -bugprone-suspicious-stringview-data-usage
# 4 warnings - .cc files included in other files (intentional pattern)
- -bugprone-suspicious-include
# 2 warnings - unused return values (AllowCastToVoid helps but some remain)
- -bugprone-unused-return-value
# 2 warnings - unused local RAII-style variables
- -bugprone-unused-local-non-trivial-variable
# 2 warnings - returning const& from parameter
- -bugprone-return-const-ref-from-parameter
# 1 warning - unsafe C functions (e.g., getenv)
- -bugprone-unsafe-functions
# 1 warning - signed char misuse
- -bugprone-signed-char-misuse
# 1 warning - calling parent virtual instead of override
- -bugprone-parent-virtual-call
# 1 warning - null termination issues
- -bugprone-not-null-terminated-result
# 1 warning - macro parentheses
- -bugprone-macro-parentheses
# 1 warning - increment/decrement in conditions
- -bugprone-inc-dec-in-conditions
# 2 warnings - std::move on forwarding reference (auto&&) in ranges lambdas
- -bugprone-move-forwarding-reference
# 2 warnings - coroutine pattern: co_await await(std::move(waitees)) then reuse.
# Relies on moved-from containers being empty (holds for libstdc++/libc++).
- -bugprone-use-after-move
# 2 warnings - sorts Value* by ->string_view(), not by pointer value (false positive)
- -bugprone-nondeterministic-pointer-iteration-order
# 9 warnings - intentional std::bit_cast/memcpy on Value* arrays (evaluator hot path)
- -bugprone-bitwise-pointer-cast
# 1 warning (header) - value.hh mkFailed: GC alloc in noexcept. Boehm's
# gc_cleanup::operator new isn't marked noexcept but aborts on OOM rather
# than throws; std::terminate here is the intended behavior anyway.
- -bugprone-unhandled-exception-at-new
# 1 warning (header) - fmt.hh Magenta<T>::operator<<: generic colorizer
# template; fires when T=unsigned char but that instantiation is correct.
- -bugprone-unintended-char-ostream-output
#
# Non-bugprone checks (also disabled to pass on current codebase):
#
# 4 warnings - exceptions not derived from std::exception
# All thrown exceptions must derive from std::exception
# - hicpp-exception-baseclass
# 88 warnings - C-style casts should be explicit about intent
# - cppcoreguidelines-pro-type-cstyle-cast
# 11 warnings - coroutine lambdas with captures (intentional pattern in async goal/store code)
# - cppcoreguidelines-avoid-capturing-lambda-coroutines
# Custom nix checks (when added)
- nix-*
CheckOptions:
# __asan_default_options: ASAN runtime configuration function (see nix-meson-build-support/common/asan-options/)
# __wrap___assert_fail: Linker-wrapped assert handler for better stack traces (see nix-meson-build-support/common/assert-fail/)
# _SingleDerivedPathRaw, _DerivedPathRaw: Internal type aliases in derived-path.hh (leading underscore pattern)
# _SingleBuiltPathRaw, _BuiltPathRaw: Internal type aliases in built-path.hh (leading underscore pattern)
bugprone-reserved-identifier.AllowedIdentifiers: '__asan_default_options;__wrap___assert_fail;_SingleDerivedPathRaw;_DerivedPathRaw;_SingleBuiltPathRaw;_BuiltPathRaw'
# Allow explicitly discarding return values with (void) cast
bugprone-unused-return-value.AllowCastToVoid: true