Skip to content

Commit

Permalink
refactor: upgrade to clang-format 18
Browse files Browse the repository at this point in the history
We use clang-format 9, which is quite outdated. Double the version to
clang-format 18.

clang-format 18 was released a few months ago. It ships in Ubuntu 24.04
which is the latest LTS release of Ubuntu. clang-format 18 is available
in Homebrew, and there are pre-built Windows binaries on LLVM's GitHub
releases page [1].

[1] https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.8
  • Loading branch information
strager committed Aug 21, 2024
1 parent 6b4539f commit 7c6fee6
Show file tree
Hide file tree
Showing 30 changed files with 105 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,12 @@ std::string vnode_event_flags_to_string(std::uint32_t flags) {
const char name[13];
};
static constexpr Flag_Entry known_flags[] = {
{NOTE_ATTRIB, "NOTE_ATTRIB"},
{NOTE_DELETE, "NOTE_DELETE"},
{NOTE_EXTEND, "NOTE_EXTEND"},
{NOTE_LINK, "NOTE_LINK"},
{NOTE_RENAME, "NOTE_RENAME"},
{NOTE_REVOKE, "NOTE_REVOKE"},
{NOTE_WRITE, "NOTE_WRITE"},
{NOTE_ATTRIB, "NOTE_ATTRIB"}, {NOTE_DELETE, "NOTE_DELETE"},
{NOTE_EXTEND, "NOTE_EXTEND"}, {NOTE_LINK, "NOTE_LINK"},
{NOTE_RENAME, "NOTE_RENAME"}, {NOTE_REVOKE, "NOTE_REVOKE"},
{NOTE_WRITE, "NOTE_WRITE"},
#if defined(__APPLE__)
{NOTE_FUNLOCK, "NOTE_FUNLOCK"},
{NOTE_FUNLOCK, "NOTE_FUNLOCK"},
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/container/fixed-vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Fixed_Vector : private Fixed_Vector_Base<T, max_size> {
T &push_back(T &&value) { return this->emplace_back(std::move(value)); }

template <class... Args>
T &emplace_back(Args &&... args) {
T &emplace_back(Args &&...args) {
QLJS_ASSERT(this->size() < max_size);
T *slot = &this->storage_slots()[this->size_];
#if QLJS_HAVE_SANITIZER_ASAN_INTERFACE_H
Expand Down
12 changes: 6 additions & 6 deletions src/quick-lint-js/container/linked-bump-allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Linked_Bump_Allocator::Disable_Guard::~Disable_Guard() {
#endif
}

Linked_Bump_Allocator::Disable_Guard::Disable_Guard([
[maybe_unused]] Linked_Bump_Allocator* alloc)
Linked_Bump_Allocator::Disable_Guard::Disable_Guard(
[[maybe_unused]] Linked_Bump_Allocator* alloc)
#if QLJS_DEBUG_BUMP_ALLOCATOR
: alloc_(alloc)
#endif
Expand Down Expand Up @@ -137,10 +137,10 @@ bool Linked_Bump_Allocator::do_try_grow_in_place(void* array,
bool have_enough_space =
(alignment_padding + size) <= this->remaining_bytes_in_current_chunk();
if (!have_enough_space) [[unlikely]] {
this->append_chunk(maximum(size, this->default_chunk_size), align);
result = this->next_allocation_;
QLJS_ASSERT(is_aligned(result, align));
}
this->append_chunk(maximum(size, this->default_chunk_size), align);
result = this->next_allocation_;
QLJS_ASSERT(is_aligned(result, align));
}

this->next_allocation_ = result + size;
this->did_allocate_bytes(result, size);
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/container/vector-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Instrumented_Vector {
}

template <class... Args>
QLJS_FORCE_INLINE value_type &emplace_back(Args &&... args) {
QLJS_FORCE_INLINE value_type &emplace_back(Args &&...args) {
this->data_.emplace_back(std::forward<Args>(args)...);
this->add_instrumentation_entry(Vector_Instrumentation::Event::append);
return this->data_.back();
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/container/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Raw_Vector {
T &push_back(T &&value) { return this->emplace_back(std::move(value)); }

template <class... Args>
T &emplace_back(Args &&... args) {
T &emplace_back(Args &&...args) {
if (this->capacity_end_ == this->data_end_) {
this->reserve_grow_by_at_least(1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/debug/find-debug-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ Span<Found_Debug_Server> find_debug_servers(Monotonic_Allocator* allocator) {
#endif

#if !QLJS_CAN_FIND_DEBUG_SERVERS
Span<Found_Debug_Server> find_debug_servers([
[maybe_unused]] Monotonic_Allocator* allocator) {
Span<Found_Debug_Server> find_debug_servers(
[[maybe_unused]] Monotonic_Allocator* allocator) {
#warning "--debug-apps is not supported on this platform"
return Span<Found_Debug_Server>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/debug/mongoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Mongoose_Mgr {

template <auto member_function_pointer>
mg_event_handler_t mongoose_callback() {
using Self = typename Member_Function_Pointer_Traits<decltype(
member_function_pointer)>::Class_Type;
using Self = typename Member_Function_Pointer_Traits<
decltype(member_function_pointer)>::Class_Type;
return [](::mg_connection *c, int ev, void *ev_data, void *fn_data) -> void {
(static_cast<Self *>(fn_data)->*member_function_pointer)(c, ev, ev_data);
};
Expand Down
48 changes: 24 additions & 24 deletions src/quick-lint-js/diag/diagnostic-types-2.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,10 @@ struct Diag_Duplicated_Cases_In_Switch_Statement {

struct Diag_Fallthrough_Without_Comment_In_Switch {
[[qljs::diag("E0427", Diagnostic_Severity::warning)]] //
[
[qljs::message("missing 'break;' or '// fallthrough' comment between "
"statement and 'case'",
ARG(end_of_case))]] //
[[qljs::message(
"missing 'break;' or '// fallthrough' comment between "
"statement and 'case'",
ARG(end_of_case))]] //
Source_Code_Span end_of_case;
};

Expand Down Expand Up @@ -2281,10 +2281,10 @@ struct Diag_TypeScript_Delete_Cannot_Delete_Variables {

struct Diag_TypeScript_Definite_Assignment_Assertion_In_Ambient_Context {
[[qljs::diag("E0445", Diagnostic_Severity::error)]] //
[
[qljs::message("'!' (definite assignment assertion) is not allowed on "
"'declare' variables",
ARG(definite_assignment_assertion))]] //
[[qljs::message(
"'!' (definite assignment assertion) is not allowed on "
"'declare' variables",
ARG(definite_assignment_assertion))]] //
[[qljs::message("'declare' here",
ARG(declare_keyword))]] //
Source_Code_Span definite_assignment_assertion;
Expand All @@ -2309,10 +2309,10 @@ struct Diag_TypeScript_Definite_Assignment_Assertion_On_Const {

struct Diag_TypeScript_Definite_Assignment_Assertion_With_Initializer {
[[qljs::diag("E0442", Diagnostic_Severity::error)]] //
[
[qljs::message("'!' (definite assignment assertion) cannot be used with "
"an initial value",
ARG(definite_assignment_assertion))]] //
[[qljs::message(
"'!' (definite assignment assertion) cannot be used with "
"an initial value",
ARG(definite_assignment_assertion))]] //
[[qljs::message("initial value was given here",
ARG(equal))]] //
Source_Code_Span definite_assignment_assertion;
Expand All @@ -2321,10 +2321,10 @@ struct Diag_TypeScript_Definite_Assignment_Assertion_With_Initializer {

struct Diag_TypeScript_Definite_Assignment_Assertion_Without_Type_Annotation {
[[qljs::diag("E0443", Diagnostic_Severity::error)]] //
[
[qljs::message("type annotation is required when using '!' (definite "
"assignment assertion)",
ARG(definite_assignment_assertion))]] //
[[qljs::message(
"type annotation is required when using '!' (definite "
"assignment assertion)",
ARG(definite_assignment_assertion))]] //
Source_Code_Span definite_assignment_assertion;
};

Expand Down Expand Up @@ -2586,10 +2586,10 @@ struct Diag_TypeScript_Declare_Field_Not_Allowed_In_JavaScript {

struct Diag_TypeScript_Declare_Field_Cannot_Use_Private_Identifier {
[[qljs::diag("E0416", Diagnostic_Severity::error)]] //
[
[qljs::message("private identifiers are not allowed for 'declare' "
"fields; use 'private' instead",
ARG(private_identifier_hash))]] //
[[qljs::message(
"private identifiers are not allowed for 'declare' "
"fields; use 'private' instead",
ARG(private_identifier_hash))]] //
[[qljs::message("'declare' here", ARG(declare_keyword))]] //
Source_Code_Span private_identifier_hash;
Source_Code_Span declare_keyword;
Expand Down Expand Up @@ -3621,10 +3621,10 @@ struct Diag_TypeScript_Namespace_Alias_Cannot_Use_Import_Type {

struct Diag_Confusing_Let_Call {
[[qljs::diag("E0720", Diagnostic_Severity::warning)]] //
[
[qljs::message("function 'let' call may be confused for destructuring; "
"remove parentheses to declare a variable",
ARG(let_function_call))]] //
[[qljs::message(
"function 'let' call may be confused for destructuring; "
"remove parentheses to declare a variable",
ARG(let_function_call))]] //
Source_Code_Span let_function_call;
};

Expand Down
6 changes: 3 additions & 3 deletions src/quick-lint-js/fe/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Expression_Arena {
is_winkable_v<std::remove_reference_t<T>>;

template <class Expression, class... Args>
Expression *make_expression(Args &&... args);
Expression *make_expression(Args &&...args);

template <class T>
Array_Ptr<T> make_array(Vector<T> &&);
Expand All @@ -184,7 +184,7 @@ class Expression_Arena {

private:
template <class T, class... Args>
T *allocate(Args &&... args) {
T *allocate(Args &&...args) {
static_assert(is_allocatable<T>);
return this->allocator_.new_object<T>(std::forward<Args>(args)...);
}
Expand Down Expand Up @@ -329,7 +329,7 @@ Derived expression_cast(const Expression &p) {
}

template <class Expression, class... Args>
Expression *Expression_Arena::make_expression(Args &&... args) {
Expression *Expression_Arena::make_expression(Args &&...args) {
Expression *result(this->allocate<Expression>(std::forward<Args>(args)...));
static_assert(is_allocatable<Expression>);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/keyword-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
QLJS_KEYWORD(public) \
QLJS_KEYWORD(readonly) \
QLJS_KEYWORD(require) \
QLJS_KEYWORD(return ) \
QLJS_KEYWORD(return) \
QLJS_KEYWORD(satisfies) \
QLJS_KEYWORD(set) \
QLJS_KEYWORD(static) \
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ bool Lexer::is_identifier_byte(Char8 byte) {
switch (static_cast<std::uint8_t>(byte)) {
QLJS_CASE_DECIMAL_DIGIT:
QLJS_CASE_IDENTIFIER_START:
// clang-format off
// clang-format off
/* 0xc0 */ /* 0xc1 */ case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7:
case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf:
case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/parse-class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ std::optional<Identifier> Parser::parse_class_and_optional_name() {
case Token_Type::identifier:
case Token_Type::kw_yield:
// TODO(#707): Disallow classes named 'yield' in generator function.
class_name : {
class_name: {
if (this->peek().type == Token_Type::kw_let) {
this->diags_.add(Diag_Cannot_Declare_Class_Named_Let{
.name = this->peek().identifier_name().span()});
Expand Down
22 changes: 11 additions & 11 deletions src/quick-lint-js/fe/parse-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,10 @@ Expression* Parser::parse_primary_expression(Parse_Visitor_Base& v,
Expression* ast =
type == Token_Type::kw_delete
? this->make_expression<Expression::Delete>(child, operator_span)
: type == Token_Type::kw_typeof
? this->make_expression<Expression::Typeof>(child,
operator_span)
: this->make_expression<Expression::Unary_Operator>(
child, operator_span);
: type == Token_Type::kw_typeof
? this->make_expression<Expression::Typeof>(child, operator_span)
: this->make_expression<Expression::Unary_Operator>(child,
operator_span);
return ast;
}

Expand Down Expand Up @@ -1683,7 +1682,7 @@ Expression* Parser::parse_expression_remainder(Parse_Visitor_Base& v,
// x += y
// x[y] &&= z
QLJS_CASE_COMPOUND_ASSIGNMENT_OPERATOR:
QLJS_CASE_CONDITIONAL_ASSIGNMENT_OPERATOR : {
QLJS_CASE_CONDITIONAL_ASSIGNMENT_OPERATOR: {
if (!prec.math_or_logical_or_assignment) {
break;
}
Expand Down Expand Up @@ -3016,7 +3015,7 @@ Expression* Parser::parse_object_literal(Parse_Visitor_Base& v) {
break;
}

QLJS_CASE_RESERVED_KEYWORD_EXCEPT_AWAIT_AND_YIELD : {
QLJS_CASE_RESERVED_KEYWORD_EXCEPT_AWAIT_AND_YIELD: {
Expression* value =
this->make_expression<Expression::Missing>(key_token.span());
this->diags_.add(Diag_Missing_Value_For_Object_Literal_Entry{
Expand Down Expand Up @@ -3990,10 +3989,11 @@ Expression* Parser::parse_jsx_element_or_fragment(Parse_Visitor_Base& v,
.opening_tag_name =
tag_namespace
? Source_Code_Span(tag_namespace->span().begin(), tag_end)
: !tag_members.empty()
? Source_Code_Span(tag_members.front().span().begin(),
tag_end)
: tag ? tag->span() : Source_Code_Span::unit(tag_end),
: !tag_members.empty()
? Source_Code_Span(tag_members.front().span().begin(),
tag_end)
: tag ? tag->span()
: Source_Code_Span::unit(tag_end),
.closing_tag_name =
closing_tag_begin <= closing_tag_end
? Source_Code_Span(closing_tag_begin, closing_tag_end)
Expand Down
5 changes: 2 additions & 3 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5012,8 +5012,7 @@ void Parser::parse_and_visit_named_exports(
goto named_export;

named_export:
QLJS_CASE_CONTEXTUAL_KEYWORD_EXCEPT_ASYNC_AND_GET_AND_SET_AND_STATIC_AND_TYPE
:
QLJS_CASE_CONTEXTUAL_KEYWORD_EXCEPT_ASYNC_AND_GET_AND_SET_AND_STATIC_AND_TYPE:
case Token_Type::identifier:
case Token_Type::kw_async:
case Token_Type::kw_get:
Expand Down Expand Up @@ -5701,7 +5700,7 @@ void Parser::parse_and_visit_let_bindings(

// let switch = 3; // Invalid.
// let if (x) {} // Invalid.
QLJS_CASE_RESERVED_KEYWORD_EXCEPT_AWAIT_AND_YIELD : {
QLJS_CASE_RESERVED_KEYWORD_EXCEPT_AWAIT_AND_YIELD: {
Source_Code_Span keyword_span = this->peek().span();
Lexer_Transaction transaction = this->lexer_.begin_transaction();
this->skip();
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ class Parser {

private:
template <class New_Expression, class... Args>
Expression *make_expression(Args &&... args) {
Expression *make_expression(Args &&...args) {
return this->expressions_.make_expression<New_Expression>(
std::forward<Args>(args)...);
}
Expand Down
7 changes: 3 additions & 4 deletions src/quick-lint-js/fe/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@
case ::quick_lint_js::Token_Type::kw_of: \
case ::quick_lint_js::Token_Type::kw_satisfies

#define QLJS_CASE_CONTEXTUAL_KEYWORD_EXCEPT_ASYNC_AND_GET_AND_SET \
QLJS_CASE_CONTEXTUAL_KEYWORD_EXCEPT_ASYNC_AND_GET_AND_SET_AND_STATIC_AND_TYPE \
: \
case ::quick_lint_js::Token_Type::kw_static: \
#define QLJS_CASE_CONTEXTUAL_KEYWORD_EXCEPT_ASYNC_AND_GET_AND_SET \
QLJS_CASE_CONTEXTUAL_KEYWORD_EXCEPT_ASYNC_AND_GET_AND_SET_AND_STATIC_AND_TYPE: \
case ::quick_lint_js::Token_Type::kw_static: \
case ::quick_lint_js::Token_Type::kw_type

// Keywords which are sometimes treated as identifiers; i.e. identifiers which
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/variable-analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ void Variable_Analyzer::propagate_variable_uses_to_parent_scope(
bool consume_arguments) {
// Found_Variable_Type is either Declared_Variable* or
// std::optional<Global_Declared_Variable>.
using Found_Variable_Type = typename std::decay_t<decltype(
Parent_Scope::declared_variables)>::Found_Variable_Type;
using Found_Variable_Type = typename std::decay_t<
decltype(Parent_Scope::declared_variables)>::Found_Variable_Type;

constexpr bool parent_scope_is_global_scope =
std::is_same_v<Parent_Scope, Global_Scope>;
Expand Down
8 changes: 4 additions & 4 deletions src/quick-lint-js/io/file-canonical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,12 @@ class Path_Canonicalizer_Base {
// Extra components and trailing slashes are not allowed for regular
// files, FIFOs, etc.
if (!path_to_process_.empty()) {
return failed_result(Canonicalizing_Path_IO_Error {
.canonicalizing_path = canonical_,
return failed_result(Canonicalizing_Path_IO_Error{
.canonicalizing_path = canonical_,
#if QLJS_HAVE_UNISTD_H
.io_error = POSIX_File_IO_Error{ENOTDIR},
.io_error = POSIX_File_IO_Error{ENOTDIR},
#elif QLJS_HAVE_WINDOWS_H
.io_error = Windows_File_IO_Error{ERROR_DIRECTORY},
.io_error = Windows_File_IO_Error{ERROR_DIRECTORY},
#else
#error "Unsupported platform"
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/quick-lint-js/io/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@ void create_windows_junction_or_exit(const char *path, const char *target) {
/*hTemplateFile=*/nullptr));

std::size_t reparse_data_data_size =
offsetof(
decltype(
std::declval<::REPARSE_DATA_BUFFER>().MountPointReparseBuffer),
PathBuffer) +
offsetof(decltype(std::declval<::REPARSE_DATA_BUFFER>()
.MountPointReparseBuffer),
PathBuffer) +
// SubsituteName. +1 for null terminator.
(wtarget->size() + 1) * sizeof(wchar_t) +
// PrintName. Empty string with null terminator.
Expand Down
Loading

0 comments on commit 7c6fee6

Please sign in to comment.