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

Add linting and formatting #166

Merged
2 commits merged into from
Mar 8, 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
34 changes: 34 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
BasedOnStyle: LLVM
IndentWidth: 4

Language: Cpp

# Yes: int *a;
# No: int* a;
# Absolutely not: int * a;
DerivePointerAlignment: false
PointerAlignment: Right

# East const
# Yes: int const a;
# No: const int a;
QualifierAlignment: Right

# If parameters do not fit on one line, do this:
# void func(
# int a,
# int b
# )
AlignAfterOpenBracket: BlockIndent
BinPackArguments: false
BinPackParameters: false
ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false
PenaltyReturnTypeOnItsOwnLine: 1000

# Attach braces to surrounding context, except on functions.
BreakBeforeBraces: Linux

AllowShortLoopsOnASingleLine: true

BitFieldColonSpacing: Before
96 changes: 96 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Checks: [
bugprone*,

cert*,

cppcoreguidelines*,
# Need globals to communicate with interrupts
-cppcoreguidelines-avoid-non-const-global-variables,
# Covered by readability-magic-numbers
-cppcoreguidelines-avoid-magic-numbers,
# We use global aggregates to dispatch extern registers.
# This cannot cause order-of-initialization problems because
# registers are guaranteed to be initialized at reset.
-cppcoreguidelines-interfaces-global-init,

google*,

hicpp*,
# Bad warning: https://stackoverflow.com/questions/50399090/use-of-a-signed-integer-operand-with-a-binary-bitwise-operator-when-using-un
-hicpp-signed-bitwise,

llvm*,
# We use a different include guard style
-llvm-header-guard,

misc*,

modernize*,

performance*,

readability*,
]

CheckOptions:
- key: bugprone-easily-swappable-parameters.ModelImplicitConversions
value: false
- key: readability-function-cognitive-complexity.Threshold
value: '10'
- key: readability-function-size.LineThreshold
value: '80'

- key: readability-identifier-length.MinimumParameterNameLength
value: '1'
- key: readability-identifier-length.IgnoredVariableNames
value: '^dt|pu$'

- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: 'true'
- key: readability-magic-numbers.IgnoredIntegerValues
value: '15;255;4095;65535;'

# Empty loops should look like this: while (condition) continue;
- key: readability-braces-around-statements.ShortStatementLines
value: '1'
- key: hicpp-braces-around-statements.ShortStatementLines
value: '1'

- key: readability-identifier-naming.EnumCase
value: 'CamelCase'
- key: readability-identifier-naming.FunctionCase
value: 'lower_case'
# Public functions have capitalized prefix
- key: readability-identifier-naming.GlobalFunctionCase
value: 'aNy_CasE'
# Interrupt service routines
- key: readability-identifier-naming.GlobalFunctionIgnoredRegexp
value: '_[A-Z0-9]+Interrupt'
- key: readability-identifier-naming.VariableCase
value: 'lower_case'
# Register names
- key: readability-identifier-naming.VariableIgnoredRegexp
value: '[A-Z][A-Z0-9]+(bits)?'
- key: readability-identifier-naming.StructCase
value: 'CamelCase'
- key: readability-identifier-naming.TypedefCase
value: 'CamelCase'
- key: readability-identifier-naming.TypedefIgnoredRegexp
value: '[A-Z]+_[a-zA-Z0-9]+'
- key: readability-identifier-naming.EnumIgnoredRegexp
value: '[A-Z]+_[a-zA-Z0-9]+'
- key: readability-identifier-naming.StructIgnoredRegexp
value: '[A-Z]+_[a-zA-Z0-9]+'
- key: readability-identifier-naming.UnionIgnoredRegexp
value: '[A-Z]+_[a-zA-Z0-9]+'
- key: readability-identifier-naming.UnionCase
value: 'CamelCase'
- key: readability-identifier-naming.GlobalConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.GlobalConstantPrefix
value: 'g_'
- key: readability-identifier-naming.MacroDefinitionCase
value: 'UPPER_CASE'

FormatStyle: file
SystemHeaders: false
Loading
Loading