Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-134207

qmlformat: Support company-wide coding guidelines

XMLWordPrintable

      qmlformat's output can be customized by:

      • command line arguments
      • .qmlformat.ini next to or in the path of the qml file processed
      • qmlformat.ini file in the user directory

      In order to enforce company (or team) wide coding guidelines we want to provide one single qmlformat.ini file as a single source of truth, that needs to be used by:

      • developers on their local machines
        • using Qt Creator for single files
        • using a script for whole projects
      • CI pipelines on build servers

      The problem is, when called from Qt Creator (e.g. on save) Qt Creator will copy the file to a temp directory, effectively removing it from the project hierarchy. So an ini file checked in with the project will no longer be found.

      An ini file in the user directory, however, will be. But how can we make sure, all users and build servers always use the most recent identical version of the file?

      Our solution was to deploy it with a standalone binary package and make qmlformat look for the ini file right next to the binary if no other ini file was found. This can easily achieved by adding one more case to QQmlToolingSettings::search() function before returning false:

       

       

          ...

          // Use defaults from ini file next to binary
          const QString exePath (QCoreApplication::applicationFilePath());
          if (const QString iniFile (exePath + u"/%1.ini"_s.arg(m_toolName));
              !iniFile.isEmpty()) {
              if (read(iniFile)) {
                  for (const QString &dir : std::as_const(dirs))
                      m_seenDirectories[dir] = iniFile;
                  return true;
      {{        }}}
      {{    }}}

       

          // No INI file found anywhere, record the failure so we won't have to traverse the entire
          // filesystem again
          ...

        For Gerrit Dashboard: QTBUG-134207
        # Subject Branch Project Status CR V

            qtqmlteam Qt Qml Team User
            okapp Oliver Kuss
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change