Re: [PATCH 4/4] scripts/cvt_style.pl: Tool to reformat sources in various ways

From: Nick Desaulniers
Date: Wed Oct 09 2019 - 18:38:27 EST


On Sat, Oct 5, 2019 at 9:47 AM Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> Trivial tool to reformat source code in various ways.
>
> This is an old tool that was recently updated to convert /* fallthrough */
> style comments to the new pseudo-keyword fallthrough;
>
> Typical command line use is:
> $ perl scripts/cvt_style --convert=fallthrough <file list>

It would be cool to include the treewide onliner from your cover sheet
in this commit message, as I find myself flipping between that and
this, otherwise the recommended onliner will be lost to LKML (instead
of being lost to git log). Or in the usage comment at the top of the
script.

>
> Available conversions:
> all
> printk_to_pr_level
> printk_KERN_DEBUG_to_pr_debug
> dev_printk_to_dev_level
> dev_printk_KERN_DEBUG_to_dev_dbg
> sdev_printk_to_sdev_level
> sdev_printk_KERN_DEBUG_to_sdev_dbg
> coalesce_formats
> cuddle_open_brace
> cuddle_else

I think some of these could use examples of what they do. I can't read
perl (as we've previously established :P) and I'm not sure what it
means to cuddle open braces or elses, though they do sound nice.

> deparenthesize_returns
> space_after_KERN_level
> space_after_if_while_for_switch
> space_after_for_semicolons
> space_after_comma
> space_before_pointer
> space_around_trigraph
> leading_spaces_to_tabs
> coalesce_semicolons
> remove_trailing_whitespace
> remove_whitespace_before_quoted_newline
> remove_whitespace_before_trailing_semicolon
> remove_whitespace_before_bracket
> remove_parenthesis_whitespace
> remove_single_statement_braces
> remove_whitespace_after_cast
> hoist_assigns_from_if
> convert_c99_comments
> remove_private_data_casts
> remove_static_initializations_to_0
> remove_true_false_comparisons
> remove_NULL_comparisons
> remove_trailing_if_semicolons

To Miguel's comment about clang-format, it looks like you can do:

Use -style="{key: value, ...}" to set specific
parameters, e.g.:
-style="{BasedOnStyle: llvm, IndentWidth: 8}"

via: https://clang.llvm.org/docs/ClangFormat.html
which might make some nice one liners for some of these.


> network_comments
> remove_switchforwhileif_semicolons
> detab_else_return
> remove_while_while
> fallthrough
> Additional conversions which may not work well:
> (enable individually or with --convert=all --broken)
> move_labels_to_column_1
> space_around_logical_tests
> space_around_assign
> space_around_arithmetic
> CamelCase_to_camel_case

s/camel_case/snake_case/

I'll give the script a run later this week and report back if I can
find any errors in the resulting build, as in the previous patch
series. Thanks for the work on this.
--
Thanks,
~Nick Desaulniers