flexx icon indicating copy to clipboard operation
flexx copied to clipboard

Autoformat code?

Open almarklein opened this issue 7 years ago • 2 comments

We now have flake8 running in CI which will protest if the code is not formatted in the way it likes. This is kinda weird: we automated something, and now we have extra work. I'm joking here, but still ...

Tools like black, yapf, autopep8 allow formatting the code for you. No more fighting about rules, just run and forget.

As a first step I removed all trailing whitespace in all python files.

almarklein avatar Aug 03 '18 13:08 almarklein

I tried running Black. It's appealing because it cannot be configured (no fighting over config). Sadly, it formats code like this:

myprop = flx.Property(42, doc="""
    bladibladibla
    """)

Into this:

myprop = flx.Property(
    42,
    doc="""
    bladibladibla
    """)

And I've seen it do worse with multiline RawJS expressions.

almarklein avatar Aug 03 '18 13:08 almarklein

I tried with yapf, but it behaves rather unpredictable at times:

    children = app.LocalProperty((), doc="""
        The child widgets of this widget. This property is not settable and
        only present in JavaScript.
        """)

    title = event.StringProp(
        '', settable=True, doc="""
        The string title of this widget. This is used to mark
        the widget in e.g. a tab layout or form layout, and is used
        as the app's title if this is the main widget.
        """)
    ...

    css_class = event.StringProp(
        '', settable=True, doc="""
        The extra CSS class name to asign to the DOM element.
        Spaces can be used to delimit multiple names. Note that the
        DOM element already has a css class-name corresponding to
        its class (e.g. 'flx-Widget) and all its superclasses.
        """)

    flex = event.FloatPairProp((0, 0), settable=True, doc="""
        How much space this widget takes (relative to the other
        widgets) when contained in a flexible layout such as HBox,
        HFix, HSplit or FormLayout. A flex of 0 means to take
        the minimum size. Flex is a two-element tuple, but both values
        can be specified at once by specifying a scalar.
        """)

Maybe I should expect this behavoir? For now it annoys me too much...

almarklein avatar Dec 03 '18 14:12 almarklein