Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.clang-format: Set column limit to 80 #2486

Closed
wants to merge 1 commit into from

Conversation

Holzhaus
Copy link
Member

@Holzhaus Holzhaus commented Feb 4, 2020

Right now, running clang-format or git clang-format will unwrap lines
and make them longer than 80 chars, even if the developer inserted
linebreaks manually.

Right now, running clang-format or git clang-format will unwrap lines
and make them longer than 80 chars, even if the developer inserted
linebreaks manually.
@uklotzde
Copy link
Contributor

uklotzde commented Feb 4, 2020

We had long discussions if we should define a limit or not. As a workaround line breaks can be preserved by placing arguments on separate lines.

If we decide to set a limit the comment becomes obsolete and should be removed.

@daschuer
Copy link
Member

daschuer commented Feb 5, 2020

I am fine with the current solution, allow lines until scrolling with GitHub.

Manually break < 80 in a way clang does not unbreak it.

Unfortunately clang format leaks two independent parameters for this.

@Holzhaus
Copy link
Member Author

Holzhaus commented Feb 5, 2020

Right now, the situation is really bad, because I have code that fits our coding style and running clang-format breaks it. This is probably the worst case scenario for an auto-formatter.

I don't really know what's the best way forward, but I see 4 options here:

  1. We set the clang-format column limit to 80/100/120/whatever
  2. We remove the "break long lines" rule from our code style and don't tell people to break long lines in GitHub reviews anymore
  3. We remove clang-format from the pre-commit config and stop recommending people to run it
  4. We find another C++ formatter that keeps (possibily superfluous) manual line breaks

@daschuer
Copy link
Member

daschuer commented Feb 5, 2020

Please point me to the code. There should be a way not to break our coding style and clang-format is happy.

@Holzhaus
Copy link
Member Author

Holzhaus commented Feb 5, 2020

Exhibit A

https://github.com/mixxxdj/mixxx/pull/2480/files#diff-8cdef3b229490e40d04ea2c72abe3d62R346-R347

Diff after running clang-format:

-QString parseCrate(const QSqlDatabase& database, QString databasePath,
-                   QString crateFilePath, const QMap<QString, int>& trackIdMap) {
+QString parseCrate(const QSqlDatabase& database, QString databasePath, QString crateFilePath, const QMap<QString, int>& trackIdMap) {

Exhibit B

https://github.com/mixxxdj/mixxx/pull/2480/files#diff-8cdef3b229490e40d04ea2c72abe3d62R486-R501

-            "INSERT INTO " + kSeratoLibraryTable + " ("
-            + LIBRARYTABLE_TITLE + ", "
-            + LIBRARYTABLE_ARTIST + ", "
-            + LIBRARYTABLE_ALBUM + ", "
-            + LIBRARYTABLE_GENRE + ", "
-            + LIBRARYTABLE_COMMENT + ", "
-            + LIBRARYTABLE_GROUPING + ", "
-            + LIBRARYTABLE_YEAR + ", "
-            + LIBRARYTABLE_DURATION + ", "
-            + LIBRARYTABLE_BITRATE + ", "
-            + LIBRARYTABLE_SAMPLERATE + ", "
-            + LIBRARYTABLE_BPM + ", "
-            + LIBRARYTABLE_KEY + ", "
-            + LIBRARYTABLE_LOCATION + ", "
-            + LIBRARYTABLE_BPM_LOCK + ", "
-            + LIBRARYTABLE_DATETIMEADDED + ", "
+            "INSERT INTO " + kSeratoLibraryTable + " (" + LIBRARYTABLE_TITLE + ", " + LIBRARYTABLE_ARTIST + ", " + LIBRARYTABLE_ALBUM + ", " + LIBRARYTABLE_GENRE + ", " + LIBRARYTABLE_COMMENT + ", " + LIBRARYTABLE_GROUPING + ", " + LIBRARYTABLE_YEAR + ", " + LIBRARYTABLE_DURATION + ", " + LIBRARYTABLE_BITRATE + ", " + LIBRARYTABLE_SAMPLERATE + ", " + LIBRARYTABLE_BPM + ", " + LIBRARYTABLE_KEY + ", " + LIBRARYTABLE_LOCATION + ", " + LIBRARYTABLE_BPM_LOCK + ", " + LIBRARYTABLE_DATETIMEADDED +
+            ", "

Exhibit C

See #2480 (comment)

-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_ARTIST]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ARTIST);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_TITLE]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TITLE);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_ALBUM]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ALBUM);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_ALBUMARTIST]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_YEAR]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_YEAR);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_GENRE]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_GENRE);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_COMPOSER]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COMPOSER);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_GROUPING]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_GROUPING);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_TRACKNUMBER]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TRACKNUMBER);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_FILETYPE]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_FILETYPE);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_NATIVELOCATION]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_NATIVELOCATION);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_COMMENT]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COMMENT);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_DURATION]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DURATION);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_BITRATE]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BITRATE);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_BPM]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_REPLAYGAIN]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_DATETIMEADDED]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_TIMESPLAYED]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_RATING]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_RATING);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_KEY]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_PREVIEW]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_COVERART]
-        = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART);
-    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_POSITION]
-        = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_ARTIST] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ARTIST);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_TITLE] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TITLE);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_ALBUM] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ALBUM);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_ALBUMARTIST] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_YEAR] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_YEAR);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_GENRE] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_GENRE);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_COMPOSER] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COMPOSER);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_GROUPING] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_GROUPING);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_TRACKNUMBER] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TRACKNUMBER);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_FILETYPE] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_FILETYPE);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_NATIVELOCATION] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_NATIVELOCATION);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_COMMENT] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COMMENT);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_DURATION] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DURATION);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_BITRATE] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BITRATE);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_BPM] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_REPLAYGAIN] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_DATETIMEADDED] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_TIMESPLAYED] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_RATING] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_RATING);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_KEY] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_PREVIEW] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_COVERART] = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART);
+    m_columnIndexBySortColumnId[TrackModel::SortColumnId::SORTCOLUMN_POSITION] = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION);

@daschuer
Copy link
Member

daschuer commented Feb 5, 2020

The trick is

@daschuer
Copy link
Member

daschuer commented Feb 5, 2020

I think we need to update the style guide.

@daschuer
Copy link
Member

daschuer commented Feb 5, 2020

@Holzhaus
Copy link
Member Author

Holzhaus commented Feb 5, 2020

Thanks.

From https://www.mixxx.org/wiki/doku.php/coding_guidelines#line_widths :

Use double indent (8-spaces) for broken lines or align with the opening “(” in the line above for hanging indents.

I guess hanging indents are not possible with clang-format?

@uklotzde
Copy link
Contributor

uklotzde commented Feb 5, 2020

Thanks.

From https://www.mixxx.org/wiki/doku.php/coding_guidelines#line_widths :

Use double indent (8-spaces) for broken lines or align with the opening “(” in the line above for hanging indents.

I guess hanging indents are not possible with clang-format?

No. I deleted the redundant and incorrect sentence.

@daschuer
Copy link
Member

daschuer commented Feb 9, 2020

So we can close this?

@Holzhaus
Copy link
Member Author

Holzhaus commented Feb 9, 2020

Yup. If more issues arise we need to adapt the wiki and make sure it doesn't conflict with clang-format.

@Holzhaus Holzhaus closed this Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants