cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
958 stars 105 forks source link

Feature Request: detect list after colon #186

Open AlexanderLanin opened 4 years ago

AlexanderLanin commented 4 years ago

In order for a list to be detected it currently has to be preceded by an empty line. This is often quite unnatural and it feels like this should not be required - at least when the preceding line ends in a colon. Example:

set(CLANG_GCC_WARNINGS
    -Wall
    -Wextra
    -Wnon-virtual-dtor
    -Wcast-align
    -Wunused
    -Woverloaded-virtual
    -Wpedantic
    -Wdouble-promotion
    # To be enabled in the future:
    #
    # * -Wshadow
    # * -Wold-style-cast
    # * -Wconversion
    # * -Wsign-conversion
    # * -Wnull-dereference
    # * -Wformat=2
)
cheshirekow commented 4 years ago

I agree that it is (just a bit) unnatural, but it is consistent with restructuredText and it is unambiguous.

# Here is a comment that involves some math where (foo)
# * (bar + baz)  is one formula and another formula is x
# * (y + z). 

Is the above a single paragraph? Or a paragraph and a list?

I do hope to figure out some good rules in the future to help infer when a bullet char is a list indicator versus some paragraph text, but I haven't found a good set of rules yet. Some Markdown implementations for instance do not require the newline, but some do. Maybe it would be worthwhile to investigate what those parsers do to distinguish.

Possibly your request is reasonable. After a colon we interpret it as a list. I'll think about it some more.

AlexanderLanin commented 4 years ago

I currently have the colon + list use case 3-5 times in a very small project with only 2 dozen cpp files in ccache/ccache#573. So it feels quite standard to me.

cheshirekow commented 4 years ago

colon + list use case 3-5 times in a very small project ... So it feels quite standard to me.

Um... I think you and I understand the word "standard" a bit differently.

One thing that concerns me is that colon is syntax in restructured text so there might be likely to introduce false positives in a "colon newline bullet-char" pattern match.

My most recent thought was something like "n or more consistent bullet-char indentations" but I haven't had time to investigate the validity of that kind of pattern.