Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-29380

QML Auto-Indent for lambdas is different from functions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • Qt Creator 10.0.2
    • Quick / QML Support
    • None

    Description

      Auto-Indentation (Ctrl+I) formats code blocks with lambdas differently than for functions, making much deeper indentations. When lambdas are nested, with longer variable names in complex code, the readability of the code drops dramatically, as everything important shifts to the right. You can see the difference in formatting with this simple example:

      import QtQuick
      
      Rectangle {
          id: root
      
          property var callback1: function () { //Functions
              let i = 0;
              i++;
              Qt.callLater(function () {
                  let j = 0;
                  j++;
                  [1, 2, 3].foreach(function (element) {
                      let k = 0;
                      k++;
                      console.debug(element);
                  });
              });
          }
          property var callback2: () => { //Lambdas
                                      let i = 0;
                                      i++;
                                      Qt.callLater(() => {
                                                       let j = 0;
                                                       j++;
                                                       [1, 2, 3].foreach((element) => {
                                                                             let k = 0;
                                                                             k++;
                                                                             console.debug(element);
                                                                         });
                                                   });
                                  }
      
          onWidthChanged: function () { //Functions
              let i = 0;
              i++;
              Qt.callLater(function () {
                  let j = 0;
                  j++;
                  [1, 2, 3].foreach(function (element) {
                      let k = 0;
                      k++;
                      console.debug(element);
                  });
              });
          }
          onHeightChanged: () => { //Lambdas
                               let i = 0;
                               i++;
                               Qt.callLater(() => {
                                                let j = 0;
                                                j++;
                                                [1, 2, 3].foreach((element) => {
                                                                      let k = 0;
                                                                      k++;
                                                                      console.debug(element);
                                                                  });
                                            });
                           }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            permotion88 Karol Polak
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes