Git Product home page Git Product logo

Comments (3)

nojaf avatar nojaf commented on May 26, 2024 1

Feel free to investigate how much fun that would be πŸ˜‰

from fantomas.

nojaf avatar nojaf commented on May 26, 2024

So, the style guide settled on formatting multiline conditions like:

// βœ”οΈ OK, but better to refactor, see below
if
    complexExpression a b && env.IsDevelopment()
    || someFunctionToCall
        aVeryLongParameterNameOne
        aVeryLongParameterNameTwo
        aVeryLongParameterNameThree 
then
        e1
    else
        e2

// βœ”οΈThe same applies to nested `elif` or `else if` expressions
if a then
    b
elif
    someLongFunctionCall
        argumentOne
        argumentTwo
        argumentThree
        argumentFour
then
    c
else if
    someOtherLongFunctionCall
        argumentOne
        argumentTwo
        argumentThree
        argumentFour
then
    d

// whatnot between the else and the if forces this behaviour.

It rings a bell that putting anything between the else if can very easily lead to invalid code, so I believe we deliberately moved the comment.

From a technical point of view, we view your entire if expression as one node, and not the parent if/else node where the else expression is a if/then expression.

from fantomas.

majocha avatar majocha commented on May 26, 2024

I think it would be more logical to assign the comment to the else if node rather than to the condition, i. e. this:

if bar then
    a <- 1
else
    // elif comment
    if
        // baz comment
        baz 
    then
        quux <- 3

should not format to:

if bar then
    a <- 1
else if
    // elif comment
    // baz comment
    baz
then
    quux <- 3

but instead:

if bar then
    a <- 1
// elif comment
else if
    // baz comment
    baz
then
    quux <- 3

fantomas-online repro

from fantomas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.