uncrustify
uncrustify copied to clipboard
Bad code alignment with multiple parenthesis
Using Uncrustify-0.78.1_f
, with the default configuration.
Consider the following code:
int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
m_euler.TransformationMatrixGet()( 1, 2 ),
m_euler.TransformationMatrixGet()( 2, 2 ) );
const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );
return 1;
}
The last 2 lines before the return is not well aligned. However:
int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
const CTMatrix4d& transformationMatrix = m_euler.TransformationMatrixGet();
const CTUnitDird normal( transformationMatrix( 0, 2 ),
transformationMatrix( 1, 2 ),
transformationMatrix( 2, 2 ) );
const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );
return 1;
}
This works as expected. Uncrustify seems to get confused because of the ()( … )
syntax.
I maybe have a similar issue related to this with multiple consecutive parentheses/calls.
I'm using cxxopts
for command line option parsing.
The syntax for adding/defining options is like this:
int main(int argc, char** argv)
{
// ...
cxxopts::Options options{argv[0], "Description"};
options.add_options()
("a,optionA", "Option A Help Description")
("b,optionB", "Option B Help Description")
("c,optionC", "Option C Help Description")
("d,optionD", "Option D Help Description");
// ...
}
When using uncrustify it will be formatted like this even though i'd like to have it formatted like above:
int main(int argc, char** argv)
{
// ...
cxxopts::Options options{argv[0], "Description"};
options.add_options()
("a,optionA", "Option A Help Description")
("b,optionB", "Option B Help Description")
("c,optionC", "Option C Help Description")
("d,optionD", "Option D Help Description");
// ...
}
I didn't find any option for consecutive parentheses and their indentation. Maybe this is related, if not i'm sorry. It can be my configuration though, even if i don't know which one it could be.
Version: Uncrustify-0.78.1-82-e5d093335
Cheers, Jan
Sorry, I cannot reproduce. Using the cfg-file:
indent_columns = 4
indent_with_tabs = 0
with the command:
uncrustify -v
uncrustify -c pemessier.cfg -f pemessier.cpp
I get: Uncrustify_d-0.78.1-92-8f96659fe-dirty and the output file has no change.
I run under Linux. Why the difference?
When running uncrustify with the snippet from @pemessier i get another different result:
int CPtCloudDataSWL::ASCIIReadNbPts(const size_t nbPtsToRead_)
{
const CTUnitDird normal(m_euler.TransformationMatrixGet()(0, 2),
m_euler.TransformationMatrixGet()(1, 2),
m_euler.TransformationMatrixGet()(2, 2));
const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_; // see this additional indentation
m_ptNormals.insert(m_ptNormals.end(), nbPtsAdded, CTDirToF(normal)); // and this one ..
return 1;
}
I'm using tabs only and with the parameters you mentioned like the following:
indent_columns = 8
indent_with_tabs = 2
On Linux, version Uncrustify-0.78.1-82-e5d093335
.
My configuration file: uncrustify.txt
int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ ) { const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ), m_euler.TransformationMatrixGet()( 1, 2 ), m_euler.TransformationMatrixGet()( 2, 2 ) );
const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_; m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) ); return 1;
}
Sorry my initial example was bad. This is the expected (no change) output that can be used as input:
int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
m_euler.TransformationMatrixGet()( 1, 2 ),
m_euler.TransformationMatrixGet()( 2, 2 ) );
const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );
return 1;
}
The assignment lines are left-indented by 4 spaces.
On Windows, running uncrustify.exe -c - pemessier.cpp
produces the incorrect result;
int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
m_euler.TransformationMatrixGet()( 1, 2 ),
m_euler.TransformationMatrixGet()( 2, 2 ) );
const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );
return 1;
}