[go: up one dir, main page]

Skip to content

clang-format: modify rules to reduce false-positives

This series is in response to an email thread 1 around the usage of '.clang-format' and its effectiveness.

The goal of the series is to improve the usage of 'clang-format' in the repository. To do this we:

  1. Reduce the number of false positives. Majority of which is due to line-wrapping. We remove the 'ColumnLimit' from 'clang-format'. This removes the responsibility of line-wrapping from 'clang-format' and puts it into the hands of the user.
  2. Add a 120 character limit to the '.editorconfig' to ensure that editors wrap lines beyond that.
  3. Add a rule to 'meson' to run 'git clang-format' by running 'meson compile style'.
  4. Make the 'RemoveBracesLLVM' permanent by moving it to '.clang-format'.

With this, running git clang-format for the last 25 commits in master, seems to produce much less false positives.

diff --git a/builtin/diff.c b/builtin/diff.c index c6231edce4..246b81caa2 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -30,14 +30,13 @@ #define DIFF_NO_INDEX_IMPLICIT 2

static const char builtin_diff_usage\[\] = -"git diff \[\] \[\] \[...\]\\n" -" or: git diff \[\] --cached \[--merge-base\] \[\] \[...\]\\n" -" or: git diff \[\] \[--merge-base\] \[...\] \[...\]\\n" -" or: git diff \[\] ... \[...\]\\n" -" or: git diff \[\] \\n" -" or: git diff \[\] --no-index \[...\]" -"\\n" -COMMON_DIFF_OPTIONS_HELP;

+ "git diff \[\] \[\] \[...\]\\n"
+ " or: git diff \[\] --cached \[--merge-base\] \[\] \[...\]\\n"
+ " or: git diff \[\] \[--merge-base\] \[...\] \[...\]\\n"
+ " or: git diff \[\] ... \[...\]\\n"
+ " or: git diff \[\] \\n"
+ " or: git diff \[\] --no-index \[...\]"
+ "\\n" COMMON_DIFF_OPTIONS_HELP;

static const char \*blob_path(struct object_array_entry \*entry) { diff --git a/builtin/stash.c b/builtin/stash.c index 7cd3ad8aa4..90e441a6e5 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1802,7 +1802,8 @@ static int push_stash(int argc, const char \*\*argv, const char \*prefix,

\`\`\`
  argc = parse_options(argc, argv, prefix, options,
		       push_assumed ? git_stash_usage :
\`\`\`

- 		     git_stash_push_usage, flags);


+ 				    git_stash_push_usage,
+ 		     flags);
    force_assume |= patch_mode;

   }

diff --git a/bundle-uri.c b/bundle-uri.c index c9d65aa0ce..89f59aafe8 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -123,7 +123,7 @@ void print_bundle_list(FILE \*fp, struct bundle_list \*list) for (i = 0; i \< BUNDLE_HEURISTIC__COUNT; i++) { if (heuristics\[i\].heuristic == list-\>heuristic) { fprintf(fp, "\\theuristic = %s\\n",

- 		       heuristics\[list-\>heuristic\].name);


+ 			heuristics\[list-\>heuristic\].name);
  		  break;
  	  }
    }

diff --git a/diff-no-index.c b/diff-no-index.c index 4aeeb98cfa..a3892a9ccc 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -325,7 +325,7 @@ static int fixup_paths(const char \*\*path, struct strbuf \*replacement) return 0; }

\-static const char \* const diff_no_index_usage\[\] = { +static const char \*const diff_no_index_usage\[\] = { N\_("git diff --no-index \[\] \[...\]"), NULL }; diff --git a/pathspec.h b/pathspec.h index 5e3a6f1fe7..601b9ca201 100644 --- a/pathspec.h +++ b/pathspec.h @@ -80,7 +80,7 @@ struct pathspec { \* For git diff --no-index, indicate that we are operating without \* a repository or index. \*/ -#define PATHSPEC_NO_REPOSITORY (1\<\<7) +#define PATHSPEC_NO_REPOSITORY (1 \<\< 7)

/\*\* \* Given command line arguments and a prefix, convert the input to

While now I'm tempted to mark the 'check-style' CI job as required. I think we should do that in the future.

--- b4-submit-tracking --- { "series": { "revision": 1, "change-id": "20250625-525-make-clang-format-more-robust-968126c991b9", "prefixes": [] } }

Merge request reports

Loading