Clang Format is consistently doing this:
bool importSomethingIn( const boost::property_tree::ptree& inBoostTree,
int inSomeIndex,
std::shared_ptr<Something>
inSomething,
int x,
int y );
When I want it to do this:
bool importSomethingIn( const boost::property_tree::ptree& inBoostTree,
int inSomeIndex,
std::shared_ptr<Something> inSomething,
int x,
int y );
Note that it is adding a newline and indent before the symbol inSomething. It seems to always be the templated types that cause this behaviour.
How can I stop it from doing this?
Here is my current .clang-format:
BasedOnStyle: LLVM
Language: Cpp
AccessModifierOffset: -4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: true
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
PointerBindsToType: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: true
Standard: Cpp11
TabWidth: 8
UseTab: Never
Edit: I am using the clang format Xcode plugin which I obtained here on github July 2016 (first installed Alcatraz then clang format plugin with Aclatraz). I'm not entirely sure where the clang-format binary is, thus haven't seen the version number for the one that came with the plugin.
However, based on the suggestions below I installed clang-format using Homebrew which gave me version 3.9.0. I then set the Xcode plugin to "use system clang-format" and I got the desired result, so I guess it must have been a bug.
Your case seems fine to me on ubuntu 16.04 with clang-format 3.8
Install clang-format-3.8
sudo apt-get install clang-format-3.8
In ~/.vimrc
map <F3> :pyf /usr/share/vim/addons/syntax/clang-format-3.8.py<cr>
imap <F3> <C-o>:pyf /usr/share/vim/addons/syntax/clang-format-3.8.py<cr>
Use #OP's .clang-format and source code
mkdir ~/test
vim ~/test/.clang-format
vim ~/test/test.cpp
Format test.cpp in vim (using F3), then the result:
bool importSomethingIn( const boost::property_tree::ptree& inBoostTree,
int inSomeIndex,
std::shared_ptr<Something> inSomething,
int x,
int y );
I think it is caused by ColumnLimit. I think it's a bug...I had this problem ones and I solved it by changing this variable. Try to set:
ColumnLimit: 0
Reason
The length of bool importSomethingIn( const boost::property_tree::ptree& inBoostTree, int inSomeIndex, std::shared_ptr<Something>" has 117+-3 chars in dependence of computing invisible chars. is 117+-3 in dependence of computing invisible characters. ColumnLimit: 120 has been set and it is one of possible reasons, I think, it has been cut.
Related
I am trying to change the Pedantic option in clang-analyzer-optin.cplusplus.UninitializedObject by create a .clang-tidy file
optin-cplusplus-uninitializedobject
here is the YAML version of .clang-tidy config-file:
Checks: >
cppcoreguidelines-*,
WarningsAsErrors: "*"
CheckOptions:
- { key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: true }
- { key: clang-analyzer-optin.cplusplus.UninitializedObject.Pedantic, value: true }
when trying to -dump-config option I can see that the clang-analyzer-* check is used:
---
Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,\\n"
WarningsAsErrors: '*'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
modernize-replace-auto-ptr.IncludeStyle: llvm
cppcoreguidelines-no-malloc.Reallocations: '::realloc'
cppcoreguidelines-owning-memory.LegacyResourceConsumers: '::free;::realloc;::freopen;::fclose'
cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues: 'false'
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions: 'false'
cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
cppcoreguidelines-macro-usage.CheckCapsOnly: 'false'
modernize-loop-convert.MaxCopySize: '16'
cppcoreguidelines-pro-bounds-constant-array-index.GslHeader: ''
cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors: 'false'
cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes: ''
cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal: 'false'
google-readability-braces-around-statements.ShortStatementLines: '1'
cppcoreguidelines-pro-type-member-init.IgnoreArrays: 'false'
cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues: '1.0;100.0;'
cppcoreguidelines-macro-usage.IgnoreCommandLineMacros: 'true'
cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle: llvm
cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation: 'false'
cppcoreguidelines-owning-memory.LegacyResourceProducers: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile'
cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion: 'true'
cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth: 'true'
cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues: '1;2;3;4;'
cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables: 'false'
modernize-loop-convert.MinConfidence: reasonable
cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues: 'false'
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: 'false'
google-readability-namespace-comments.ShortNamespaceLines: '10'
google-readability-namespace-comments.SpacesBeforeComments: '2'
cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
cppcoreguidelines-avoid-magic-numbers.IgnoreBitFieldsWidths: 'true'
cppcoreguidelines-no-malloc.Allocations: '::malloc;::calloc'
cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'true'
cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion: 'true'
cppcoreguidelines-prefer-member-initializer.UseAssignment: 'false'
cppcoreguidelines-explicit-virtual-functions.FinalSpelling: final
llvm-qualified-auto.AddConstToQualified: 'false'
modernize-loop-convert.NamingStyle: CamelCase
cppcoreguidelines-pro-type-member-init.UseAssignment: 'false'
cppcoreguidelines-init-variables.MathHeader: '\<math.h\>'
google-readability-function-size.StatementThreshold: '800'
llvm-else-after-return.WarnOnConditionVariables: 'false'
cppcoreguidelines-init-variables.IncludeStyle: llvm
modernize-pass-by-value.IncludeStyle: llvm
cppcoreguidelines-explicit-virtual-functions.OverrideSpelling: override
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: 'true'
modernize-use-nullptr.NullMacros: 'NULL'
cppcoreguidelines-no-malloc.Deallocations: '::free'
cppcoreguidelines-macro-usage.AllowedRegexp: '^DEBUG\_\*'
cppcoreguidelines-narrowing-conversions.PedanticMode: 'false'
llvm-else-after-return.WarnOnUnfixable: 'false'
...
when executing -verify-config:
command-line option '-config': warning: unknown check option 'clang-analyzer-optin.cplusplus.UninitializedObject.Pedantic' [-verify-config]
How to change Pedantic option to true in .clang-tidy file?the description in optin-cplusplus-uninitializedobject is not clear for me
I want to configure clang-format (version 14.0.6) that it leaves single-line while-statement without adding a line break for the trailing semicolon (C++):
For example, clang-format should just leave a "one-liner" as it is:
while (checkWaitCondition() != true);
But unfortunately clang-format adds by default a line break (plus an indentation of 4 spaces):
while (checkWaitCondition() != true)
;
I tried the options AllowShortBlocksOnASingleLine + AllowShortLoopsOnASingleLine, but without any impact...
Does anyone have an idea how I can prevent, that clang-format breaks the semicolon into the next line?
I use this .clang-format configuration file:
BasedOnStyle: WebKit
IndentWidth: 4
Language: Cpp
AlignAfterOpenBracket: Align
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Allman
BreakInheritanceList: BeforeComma
ColumnLimit: 120
Cpp11BracedListStyle: true
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
NamespaceIndentation: All
PenaltyReturnTypeOnItsOwnLine: 1000000
SortIncludes: false
DeriveLineEnding: false
UseCRLF: false
I found the reason, why clang-format ignored the settings for AllowShortBlocksOnASingleLine and AllowShortLoopsOnASingleLine: I had another .clang-format file in a lower directory, which overwrote my test-configuration...
With both flags set to true, the format works as expected, with the following setting in the .clang-format file:
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
Produces the following format:
while (checkWaitCondition() != true) { }
But for my purpose, I want to use the continue statement from now, to improve the readability:
while (checkWaitCondition() != true) { continue; }
I'm not sure if this is a limitation or bug with clang-format (built from source, clang-format version 12.0.0 (git#github.com:llvm/llvm-project.git d4ce062340064c3f73b8f6136c7350a5abe83cac)), but I am unable to disable indentation after extern "C" {.
My current .clang-format:
Language: Cpp
Standard: Latest
UseTab: Never
IndentWidth: 4
AccessModifierOffset: -2
SpaceBeforeParens: Never
ColumnLimit: 80
SpacesBeforeTrailingComments: 1
BreakBeforeBraces: Allman
FixNamespaceComments: true
SortIncludes: true
SortUsingDeclarations: true
IncludeBlocks: Regroup
IndentPPDirectives: AfterHash
IndentCaseLabels: true
IndentExternBlock: NoIndent
NamespaceIndentation: All
AlignTrailingComments: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveBitFields: true
AlignConsecutiveMacros: true
AlignAfterOpenBracket: AlwaysBreak
AllowShortFunctionsOnASingleLine: None
AllowShortBlocksOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortLambdasOnASingleLine: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
PenaltyBreakBeforeFirstCallParameter: 500 # basically always break
# Note: must have my custom build (https://github.com/jasperswallen/llvm-project/tree/pointeralignment-right) to properly enable these options
BreakBeforeConceptDeclarations: true
PointerAlignment: Right
This example file is the "formatted" result:
#ifdef __cplusplus
extern "C"
{
#endif
void example(void);
#ifdef __cplusplus
}
#endif
but I want something like:
#ifdef __cplusplus
extern "C"
{
#endif
void example(void);
#ifdef __cplusplus
}
#endif
It seems like IndentExternBlock: NoIndent should be the correct option to force this, but it's still indenting even with that set.
Is it possible that BreakBeforeBraces: Allman is overriding this setting? I assumed that IndentExternBlock would override braces unless set to AfterExternBlock.
This is a bug 37272, but there is just a little chance that it will be fixed because this option (IndentExternBlock) was forced by expand preset function. Please review the following problematic commit.
We can see that llvm developers broke config inheritance and nobody cares about a year. It means that we have to fix config inheritance in a way that won't depend on llvm developers. Please review the following solution:
scripts/clang/config-format/config-source.yml
Language: Cpp
BreakBeforeBraces: Allman
scripts/clang/config-format/config-updates.yml
BraceWrapping:
AfterExternBlock: false
BreakBeforeBraces: Custom
IndentExternBlock: false
scripts/clang/config-format/update.sh
#!/bin/bash
set -e
DIR=$(dirname "${BASH_SOURCE[0]}")
cd "$DIR"
SOURCE="config-source.yml"
UPDATES="config-updates.yml"
DESTINATION="../../../.clang-format"
echo "# This file has been auto generated, please don't edit directly." \
> "$DESTINATION"
SOURCE_STYLE=$(yq -cs ".[0]" < "$SOURCE")
clang-format -style="$SOURCE_STYLE" --dump-config | \
yq -sy ".[0] * .[1]" - "$UPDATES" >> "$DESTINATION"
Please install yq. After running ./scripts/clang/config-format/update.sh you will receive proper .clang-config for your requirements.
I am writing my thesis in R Markdown and knitting either an an HTML or word document and i want to indent only the first line in each paragraph. Is there a way to do it?
I've tried 'indent' true' in the YAML but it did not work
here is the YAML header:
bibliography: references.bib
output:
html_document:
code_folding: show
toc: true
theme: journal
fig_caption: true
df_print: paged
number_sections: true
indent: true
word_document:
toc: true
indent: true
link-citations: true
csl: nature.csl
biblio-style: nature
I am reading through the documentation on karma and istanbul to set up code coverage. I am not sure what I am missing. I included everything that I have used to figure this step out so I apologize if it is long winded.
I tried the to run the start script inside of my npm package but got the error message
Error: Cannot find module 'c:\HA\VSTS\Applications\HA.Web.Main\spec\support\jasmine.json'
-https://karma-runner.github.io/0.8/config/coverage.html
-https://www.npmjs.com/package/istanbul#getting-started
This seems like it should be a fairly straightforward process.
Inside of my karma.conf file I have karma-coverage
plugins: {
karma-coverage
]
I set up a coverage reporter object
coverageReporter: {
// disable code compaction when using instrumenter * do not want ot minify output
instrumenterOptions: {
istanbul: { noCompact: true }
},
type: 'html',
dir: 'coverage/'
},
Inside of the preprocessor I listed the files that I wanted to be covered
preprocessor: [
"../Scripts/src/modules/**/*.js": ['coverage']
]
The documenation makes note of the jasmine on windows and identifies the need for a scripts object to use cross platform.
"scripts": {
"test": "istanbul cover node_modules/jasmine/bin/jasmine.js"
},
I have jasmine in my node modules so that should not be an issue.
I ran to further identify what could be the issue.
istanbul help config
But to be honest I do not now what to look for inside of some of these objects
verbose: false
instrumentation:
root: .
extensions:
- .js
default-excludes: true
excludes: []
embed-source: false
variable: __coverage__
compact: true
preserve-comments: false
complete-copy: false
save-baseline: false
baseline-file: ./coverage/coverage-baseline.json
include-all-sources: false
include-pid: false
es-modules: false
reporting:
print: summary
reports:
- lcov
dir: ./coverage
watermarks:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
report-config:
clover: {file: clover.xml}
cobertura: {file: cobertura-coverage.xml}
json: {file: coverage-final.json}
json-summary: {file: coverage-summary.json}
lcovonly: {file: lcov.info}
teamcity: {file: null, blockName: Code Coverage Summary}
text: {file: null, maxCols: 0}
text-lcov: {file: lcov.info}
text-summary: {file: null}
hooks:
hook-run-in-context: false
post-require-hook: null
handle-sigint: false
check:
global:
statements: 0
lines: 0
branches: 0
functions: 0
excludes: []
each:
statements: 0
lines: 0
branches: 0
functions: 0
excludes: []
You need to call jasmine init to generate that file. If you installed jasmine locally you need to call:
node_modules/jasmine/bin/jasmine.js init