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

Add Werror and dry-run flags for clang-format #5908

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions xmake/plugins/format/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,23 @@ function main()
table.insert(argv, "--style=" .. option.get("style"))
end

-- inplace flag
table.insert(argv, "-i")
if option.get("dry-run") then
-- do not make any changes, just show the files that would be formatted
table.insert(argv, "--dry-run")
else
-- inplace flag
table.insert(argv, "-i")
end

-- changes formatting warnings to errors
if option.get("error") then
table.insert(argv, "--Werror")
end

-- print verbose information
if option.get("verbose") then
table.insert(argv, "--verbose")
end

local targetname
local group_pattern = option.get("group")
Expand Down
39 changes: 21 additions & 18 deletions xmake/plugins/format/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@ task("format")
usage = "xmake format [options] [arguments]",
description = "Format the current project.",
options = {
{'s', "style", "kv", nil, "Set the path of .clang-format file, a coding style",
values = {"LLVM", "Google", "Chromium", "Mozilla", "WebKit"}},
{nil, "create", "k", nil, "Create a .clang-format file from a coding style"},
{'a', "all", "k", nil, "Format all targets."},
{'g', "group", "kv", nil, "Format all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake format -g test",
" xmake format -g test_*",
" xmake format --group=benchmark/*"},
{'f', "files", "kv", nil, "Build the given source files.",
"e.g.",
" - xmake format --files=src/main.c",
" - xmake format --files='src/*.c' [target]",
" - xmake format --files='src/**.c|excluded_file.c",
" - xmake format --files='src/main.c" .. path.envsep() .. "src/test.c'" },
{},
{nil, "target", "v", nil, "The target name. It will format all default targets if this parameter is not specified."
, values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end }
{'s', "style", "kv", nil, "Set the path of .clang-format file, a coding style",
values = {"LLVM", "Google", "Chromium", "Mozilla", "WebKit"}},
{nil, "create", "k", nil, "Create a .clang-format file from a coding style"},
{'n', "dry-run", "k", nil, "Do not make any changes, just show the files that would be formatted."},
{'e', "error", "k", nil, "If set, changes formatting warnings to errors."},
{'v', "verbose", "k", nil, "Print verbose information."},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verbose is builtin option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well noted, fixed.

{'a', "all", "k", nil, "Format all targets."},
{'g', "group", "kv", nil, "Format all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake format -g test",
" xmake format -g test_*",
" xmake format --group=benchmark/*"},
{'f', "files", "kv", nil, "Build the given source files.",
"e.g.",
" - xmake format --files=src/main.c",
" - xmake format --files='src/*.c' [target]",
" - xmake format --files='src/**.c|excluded_file.c",
" - xmake format --files='src/main.c" .. path.envsep() .. "src/test.c'" },
{},
{nil, "target", "v", nil, "The target name. It will format all default targets if this parameter is not specified."
, values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end }
}
}

Expand Down