Skip to content

Commit 33b6ce7

Browse files
committed
Swift: update formatting to clang-format 17.0.6
Also, added a format check in `swift.yml`.
1 parent 01b8950 commit 33b6ce7

File tree

9 files changed

+28
-27
lines changed

9 files changed

+28
-27
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

.github/workflows/swift.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ jobs:
7373
steps:
7474
- uses: actions/checkout@v4
7575
- uses: ./swift/actions/run-integration-tests
76+
clang-format:
77+
if : ${{ github.event_name == 'pull_request' }}
78+
runs-on: ubuntu-latest
79+
steps:
80+
- uses: actions/checkout@v4
81+
- uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
82+
name: Check that python code is properly formatted
83+
with:
84+
extra_args: clang-format --all-files
7685
codegen:
7786
if : ${{ github.event_name == 'pull_request' }}
7887
runs-on: ubuntu-latest
@@ -82,12 +91,12 @@ jobs:
8291
- uses: actions/setup-python@v4
8392
with:
8493
python-version-file: 'swift/.python-version'
85-
- uses: pre-commit/action@v3.0.0
94+
- uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
8695
name: Check that python code is properly formatted
8796
with:
8897
extra_args: autopep8 --all-files
8998
- uses: ./.github/actions/fetch-codeql
90-
- uses: pre-commit/action@v3.0.0
99+
- uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
91100
name: Check that QL generated code was checked in
92101
with:
93102
extra_args: swift-codegen --all-files

.pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ repos:
1010
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch
1111

1212
- repo: https://github.com/pre-commit/mirrors-clang-format
13-
rev: v13.0.1
13+
rev: v17.0.6
1414
hooks:
1515
- id: clang-format
16-
files: ^swift/.*\.(h|c|cpp)$
1716

1817
- repo: https://github.com/pre-commit/mirrors-autopep8
1918
rev: v1.6.0

swift/extractor/infra/SwiftDispatcher.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ class SwiftDispatcher {
338338
virtual void visit(const swift::MacroRoleAttr* attr) = 0;
339339

340340
template <typename T>
341-
requires(!std::derived_from<T, swift::TypeRepr>) void visit(const T* e, swift::Type) { visit(e); }
341+
requires(!std::derived_from<T, swift::TypeRepr>)
342+
void visit(const T* e, swift::Type) {
343+
visit(e);
344+
}
342345

343346
const swift::SourceManager& sourceManager;
344347
SwiftExtractorState& state;

swift/extractor/infra/SwiftLocationExtractor.h

+6-17
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,25 @@ class TrapDomain;
1717

1818
namespace detail {
1919
template <typename T>
20-
concept HasSourceRange = requires(T e) {
21-
e.getSourceRange();
22-
};
20+
concept HasSourceRange = requires(T e) { e.getSourceRange(); };
2321

2422
template <typename T>
2523
concept HasStartAndEndLoc = requires(T e) {
2624
e.getStartLoc();
2725
e.getEndLoc();
28-
}
29-
&&!(HasSourceRange<T>);
26+
} && !(HasSourceRange<T>);
3027

3128
template <typename T>
3229
concept HasLAndRParenLoc = requires(T e) {
3330
e.getLParenLoc();
3431
e.getRParenLoc();
35-
}
36-
&&!(HasSourceRange<T>)&&!(HasStartAndEndLoc<T>);
32+
} && !(HasSourceRange<T>)&&!(HasStartAndEndLoc<T>);
3733

3834
template <typename T>
39-
concept HasOneLoc = requires(T e) {
40-
e.getLoc();
41-
}
42-
&&!(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
35+
concept HasOneLoc = requires(T e) { e.getLoc(); } && !(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
4336

4437
template <typename T>
45-
concept HasOneLocField = requires(T e) {
46-
e.Loc;
47-
};
38+
concept HasOneLocField = requires(T e) { e.Loc; };
4839

4940
swift::SourceRange getSourceRange(const HasSourceRange auto& locatable) {
5041
return locatable.getSourceRange();
@@ -89,9 +80,7 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
8980
} // namespace detail
9081

9182
template <typename E>
92-
concept IsLocatable = requires(E e) {
93-
detail::getSourceRange(e);
94-
};
83+
concept IsLocatable = requires(E e) { detail::getSourceRange(e); };
9584

9685
class SwiftLocationExtractor {
9786
public:

swift/extractor/translators/PatternTranslator.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace codeql {
44

55
codeql::NamedPattern PatternTranslator::translateNamedPattern(const swift::NamedPattern& pattern) {
6-
76
auto entry = createPatternEntry(pattern);
87
entry.var_decl = dispatcher.fetchLabel(pattern.getDecl());
98
return entry;

swift/extractor/trap/TrapLabel.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class TrapLabel : public UntypedTrapLabel {
8383
static TrapLabel unsafeCreateFromUntyped(UntypedTrapLabel label) { return TrapLabel{label.id_}; }
8484

8585
template <typename SourceTag>
86-
requires std::derived_from<SourceTag, Tag> TrapLabel(const TrapLabel<SourceTag>& other)
87-
: UntypedTrapLabel(other) {}
86+
requires std::derived_from<SourceTag, Tag>
87+
TrapLabel(const TrapLabel<SourceTag>& other) : UntypedTrapLabel(other) {}
8888
};
8989

9090
// wrapper class to allow directly assigning a vector of TrapLabel<A> to a vector of
@@ -96,7 +96,7 @@ struct TrapLabelVectorWrapper {
9696
std::vector<TrapLabel<TagParam>> data;
9797

9898
template <typename DestinationTag>
99-
requires std::derived_from<Tag, DestinationTag>
99+
requires std::derived_from<Tag, DestinationTag>
100100
operator std::vector<TrapLabel<DestinationTag>>() && {
101101
// reinterpret_cast is safe because TrapLabel instances differ only on the type, not the
102102
// underlying data

swift/integration-tests/.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

swift/logging/SwiftLogging.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \
6464
do { \
6565
auto _now = ::binlog::clockNow(); \
66-
const ::codeql::Diagnostic& _id = ID; \
66+
const ::codeql::Diagnostic& _id = ID; \
6767
::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \
6868
fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \
6969
LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \

0 commit comments

Comments
 (0)