Skip to content

Commit 2175116

Browse files
authored
Merge pull request #287 from wravery/sonar-lint
Export compile commands and fix some SonarLint warnings
2 parents 786c0a4 + 4f3934c commit 2175116

File tree

128 files changed

+2748
-2451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2748
-2451
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ cmake_policy(SET CMP0091 NEW)
99
# Do not set default MSVC warning flags: https://cmake.org/cmake/help/latest/policy/CMP0092.html
1010
cmake_policy(SET CMP0092 NEW)
1111

12+
# Export compile commands for other tools, e.g. SonarLint.
13+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14+
1215
# Default to the last updated version from version.txt.
1316
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.txt" VERSION_FILE)
1417
file(READ "${VERSION_FILE}" LATEST_VERSION)

doc/awaitable.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ specifically a type-erased `graphql::service::await_async` class in
88
[GraphQLService.h](../include/graphqlservice/GraphQLService.h):
99
```cpp
1010
// Type-erased awaitable.
11-
class [[nodiscard]] await_async final
11+
class [[nodiscard("unnecessary construction")]] await_async final
1212
{
1313
private:
14-
struct [[nodiscard]] Concept
14+
struct [[nodiscard("unnecessary construction")]] Concept
1515
{
1616
virtual ~Concept() = default;
1717

18-
[[nodiscard]] virtual bool await_ready() const = 0;
18+
[[nodiscard("unexpected call")]] virtual bool await_ready() const = 0;
1919
virtual void await_suspend(coro::coroutine_handle<> h) const = 0;
2020
virtual void await_resume() const = 0;
2121
};
@@ -71,22 +71,22 @@ Many APIs which used to return some sort of `std::future` now return an alias fo
7171
`graphql::internal::Awaitable<...>`. This template is defined in [Awaitable.h](../include/graphqlservice/internal/Awaitable.h):
7272
```cpp
7373
template <typename T>
74-
class [[nodiscard]] Awaitable
74+
class [[nodiscard("unnecessary construction")]] Awaitable
7575
{
7676
public:
7777
Awaitable(std::future<T> value)
7878
: _value { std::move(value) }
7979
{
8080
}
8181

82-
[[nodiscard]] T get()
82+
[[nodiscard("unnecessary construction")]] T get()
8383
{
8484
return _value.get();
8585
}
8686

8787
struct promise_type
8888
{
89-
[[nodiscard]] Awaitable get_return_object() noexcept
89+
[[nodiscard("unnecessary construction")]] Awaitable get_return_object() noexcept
9090
{
9191
return { _promise.get_future() };
9292
}
@@ -105,7 +105,7 @@ public:
105105

106106
};
107107

108-
[[nodiscard]] constexpr bool await_ready() const noexcept
108+
[[nodiscard("unexpected call")]] constexpr bool await_ready() const noexcept
109109
{
110110
return true;
111111
}
@@ -115,7 +115,7 @@ public:
115115
h.resume();
116116
}
117117

118-
[[nodiscard]] T await_resume()
118+
[[nodiscard("unnecessary construction")]] T await_resume()
119119
{
120120
return _value.get();
121121
}

doc/fieldparams.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The `graphql::service::FieldParams` struct is declared in [GraphQLService.h](../
2121
```cpp
2222
// Pass a common bundle of parameters to all of the generated Object::getField accessors in a
2323
// SelectionSet
24-
struct [[nodiscard]] SelectionSetParams
24+
struct [[nodiscard("unnecessary construction")]] SelectionSetParams
2525
{
2626
// Context for this selection set.
2727
const ResolverContext resolverContext;
@@ -46,7 +46,7 @@ struct [[nodiscard]] SelectionSetParams
4646
};
4747

4848
// Pass a common bundle of parameters to all of the generated Object::getField accessors.
49-
struct [[nodiscard]] FieldParams : SelectionSetParams
49+
struct [[nodiscard("unnecessary construction")]] FieldParams : SelectionSetParams
5050
{
5151
GRAPHQLSERVICE_EXPORT explicit FieldParams(
5252
SelectionSetParams&& selectionSetParams, Directives directives);
@@ -64,7 +64,7 @@ The `SelectionSetParams::resolverContext` enum member informs the `getField`
6464
accessors about what type of operation is being resolved:
6565
```cpp
6666
// Resolvers may be called in multiple different Operation contexts.
67-
enum class [[nodiscard]] ResolverContext {
67+
enum class [[nodiscard("unnecessary construction")]] ResolverContext {
6868
// Resolving a Query operation.
6969
Query,
7070

@@ -94,7 +94,7 @@ The `SelectionSetParams::state` member is a reference to the
9494
// any per-request state that you want to maintain throughout the request (e.g. optimizing or
9595
// batching backend requests), you can inherit from RequestState and pass it to Request::resolve to
9696
// correlate the asynchronous/recursive callbacks and accumulate state in it.
97-
struct [[nodiscard]] RequestState : std::enable_shared_from_this<RequestState>
97+
struct [[nodiscard("unnecessary construction")]] RequestState : std::enable_shared_from_this<RequestState>
9898
{
9999
virtual ~RequestState() = default;
100100
};

doc/json.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ to some other output mechanism, without building a single string buffer for the
4646
document in memory. For example, you might use this to write directly to a buffered IPC pipe
4747
or network connection:
4848
```cpp
49-
class [[nodiscard]] Writer final
49+
class [[nodiscard("unnecessary construction")]] Writer final
5050
{
5151
private:
5252
struct Concept

doc/responses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ represented in GraphQL, as of the
1010
[October 2021 spec](https://spec.graphql.org/October2021/#sec-Serialization-Format):
1111

1212
```c++
13-
enum class [[nodiscard]] Type : std::uint8_t {
13+
enum class [[nodiscard("unnecessary conversion")]] Type : std::uint8_t {
1414
Map, // JSON Object
1515
List, // JSON Array
1616
String, // JSON String

doc/subscriptions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ the subscriptions to those listeners.
1313
Subscriptions are created by calling the `Request::subscribe` method in
1414
[GraphQLService.h](../include/graphqlservice/GraphQLService.h):
1515
```cpp
16-
GRAPHQLSERVICE_EXPORT [[nodiscard]] AwaitableSubscribe subscribe(RequestSubscribeParams params);
16+
GRAPHQLSERVICE_EXPORT [[nodiscard("leaked subscription")]] AwaitableSubscribe subscribe(RequestSubscribeParams params);
1717
```
1818
1919
You need to fill in a `RequestSubscribeParams` struct with the subscription event
2020
callback, the [parsed](./parsing.md) `query` and any other relevant operation parameters:
2121
```cpp
22-
struct [[nodiscard]] RequestSubscribeParams
22+
struct [[nodiscard("unnecessary construction")]] RequestSubscribeParams
2323
{
2424
// Callback which receives the event data.
2525
SubscriptionCallback callback;
@@ -64,13 +64,13 @@ The `internal::Awaitable<T>` template is described in [awaitable.md](./awaitable
6464
Subscriptions are removed by calling the `Request::unsubscribe` method in
6565
[GraphQLService.h](../include/graphqlservice/GraphQLService.h):
6666
```cpp
67-
GRAPHQLSERVICE_EXPORT [[nodiscard]] AwaitableUnsubscribe unsubscribe(RequestUnsubscribeParams params);
67+
GRAPHQLSERVICE_EXPORT [[nodiscard("potentially leaked subscription")]] AwaitableUnsubscribe unsubscribe(RequestUnsubscribeParams params);
6868
```
6969
7070
You need to fill in a `RequestUnsubscribeParams` struct with the `SubscriptionKey`
7171
returned by `Request::subscribe` in `AwaitableSubscribe`:
7272
```cpp
73-
struct [[nodiscard]] RequestUnsubscribeParams
73+
struct [[nodiscard("unnecessary construction")]] RequestUnsubscribeParams
7474
{
7575
// Key returned by a previous call to subscribe.
7676
SubscriptionKey key;
@@ -117,7 +117,7 @@ The `Request::deliver` method determines which subscriptions should receive
117117
an event based on several factors, which makes the `RequestDeliverParams` struct
118118
more complicated:
119119
```cpp
120-
struct [[nodiscard]] RequestDeliverParams
120+
struct [[nodiscard("unnecessary construction")]] RequestDeliverParams
121121
{
122122
// Deliver to subscriptions on this field.
123123
std::string_view field;
@@ -155,7 +155,7 @@ using SubscriptionArguments = std::map<std::string_view, response::Value>;
155155
using SubscriptionArgumentFilterCallback = std::function<bool(response::MapType::const_reference)>;
156156
using SubscriptionDirectiveFilterCallback = std::function<bool(Directives::const_reference)>;
157157

158-
struct [[nodiscard]] SubscriptionFilter
158+
struct [[nodiscard("unnecessary construction")]] SubscriptionFilter
159159
{
160160
// Optional field argument filter, which can either be a set of required arguments, or a
161161
// callback which returns true if the arguments match custom criteria.
@@ -186,6 +186,6 @@ that, there's a public `Request::findOperationDefinition` method which returns
186186
the operation type as a `std::string_view` along with a pointer to the AST node
187187
for the selected operation in the parsed query:
188188
```cpp
189-
GRAPHQLSERVICE_EXPORT [[nodiscard]] std::pair<std::string_view, const peg::ast_node*>
189+
GRAPHQLSERVICE_EXPORT [[nodiscard("unnecessary call")]] std::pair<std::string_view, const peg::ast_node*>
190190
findOperationDefinition(peg::ast& query, std::string_view operationName) const;
191191
```

include/ClientGenerator.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,57 @@
1111

1212
namespace graphql::generator::client {
1313

14-
struct [[nodiscard]] GeneratorPaths
14+
struct [[nodiscard("unnecessary construction")]] GeneratorPaths
1515
{
1616
const std::string headerPath;
1717
const std::string sourcePath;
1818
};
1919

20-
struct [[nodiscard]] GeneratorOptions
20+
struct [[nodiscard("unnecessary construction")]] GeneratorOptions
2121
{
2222
const GeneratorPaths paths;
2323
const bool verbose = false;
2424
};
2525

26-
class [[nodiscard]] Generator
26+
class [[nodiscard("unnecessary construction")]] Generator
2727
{
2828
public:
2929
// Initialize the generator with the introspection client or a custom GraphQL client.
30-
explicit Generator(
31-
SchemaOptions&& schemaOptions, RequestOptions&& requestOptions, GeneratorOptions&& options);
30+
explicit Generator(SchemaOptions && schemaOptions,
31+
RequestOptions && requestOptions,
32+
GeneratorOptions && options);
3233

3334
// Run the generator and return a list of filenames that were output.
34-
[[nodiscard]] std::vector<std::string> Build() const noexcept;
35+
[[nodiscard("unnecessary memory copy")]] std::vector<std::string> Build() const noexcept;
3536

3637
private:
37-
[[nodiscard]] std::string getHeaderDir() const noexcept;
38-
[[nodiscard]] std::string getSourceDir() const noexcept;
39-
[[nodiscard]] std::string getHeaderPath() const noexcept;
40-
[[nodiscard]] std::string getSourcePath() const noexcept;
41-
[[nodiscard]] const std::string& getClientNamespace() const noexcept;
42-
[[nodiscard]] const std::string& getOperationNamespace(
38+
[[nodiscard("unnecessary memory copy")]] std::string getHeaderDir() const noexcept;
39+
[[nodiscard("unnecessary memory copy")]] std::string getSourceDir() const noexcept;
40+
[[nodiscard("unnecessary memory copy")]] std::string getHeaderPath() const noexcept;
41+
[[nodiscard("unnecessary memory copy")]] std::string getSourcePath() const noexcept;
42+
[[nodiscard("unnecessary call")]] const std::string& getClientNamespace() const noexcept;
43+
[[nodiscard("unnecessary call")]] const std::string& getOperationNamespace(
4344
const Operation& operation) const noexcept;
44-
[[nodiscard]] std::string getResponseFieldCppType(
45-
const ResponseField& responseField, std::string_view currentScope = {}) const noexcept;
45+
[[nodiscard("unnecessary memory copy")]] std::string getResponseFieldCppType(
46+
const ResponseField& responseField,
47+
std::string_view currentScope = {}) const noexcept;
4648

47-
[[nodiscard]] bool outputHeader() const noexcept;
48-
void outputRequestComment(std::ostream& headerFile) const noexcept;
49-
void outputGetRequestDeclaration(std::ostream& headerFile) const noexcept;
50-
void outputGetOperationNameDeclaration(std::ostream& headerFile) const noexcept;
51-
[[nodiscard]] bool outputResponseFieldType(std::ostream& headerFile,
52-
const ResponseField& responseField, size_t indent = 0) const noexcept;
49+
[[nodiscard("unnecessary call")]] bool outputHeader() const noexcept;
50+
void outputRequestComment(std::ostream & headerFile) const noexcept;
51+
void outputGetRequestDeclaration(std::ostream & headerFile) const noexcept;
52+
void outputGetOperationNameDeclaration(std::ostream & headerFile) const noexcept;
53+
[[nodiscard("unnecessary call")]] bool outputResponseFieldType(std::ostream & headerFile,
54+
const ResponseField& responseField,
55+
size_t indent = 0) const noexcept;
5356

54-
[[nodiscard]] bool outputSource() const noexcept;
55-
void outputGetRequestImplementation(std::ostream& sourceFile) const noexcept;
56-
void outputGetOperationNameImplementation(
57-
std::ostream& sourceFile, const Operation& operation) const noexcept;
58-
bool outputModifiedResponseImplementation(std::ostream& sourceFile,
59-
const std::string& outerScope, const ResponseField& responseField) const noexcept;
60-
[[nodiscard]] static std::string getTypeModifierList(
57+
[[nodiscard("unnecessary call")]] bool outputSource() const noexcept;
58+
void outputGetRequestImplementation(std::ostream & sourceFile) const noexcept;
59+
void outputGetOperationNameImplementation(std::ostream & sourceFile, const Operation& operation)
60+
const noexcept;
61+
bool outputModifiedResponseImplementation(std::ostream & sourceFile,
62+
const std::string& outerScope,
63+
const ResponseField& responseField) const noexcept;
64+
[[nodiscard("unnecessary memory copy")]] static std::string getTypeModifierList(
6165
const TypeModifierStack& modifiers) noexcept;
6266

6367
const SchemaLoader _schemaLoader;

include/GeneratorLoader.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace graphql::generator {
1212

1313
// Types that we understand and use to generate the skeleton of a service.
14-
enum class [[nodiscard]] SchemaType {
14+
enum class [[nodiscard("unnecessary conversion")]] SchemaType {
1515
Scalar,
1616
Enum,
1717
Input,
@@ -30,10 +30,11 @@ using TypeModifierStack = std::vector<service::TypeModifier>;
3030

3131
// Recursively visit a Type node until we reach a NamedType and we've
3232
// taken stock of all of the modifier wrappers.
33-
class [[nodiscard]] TypeVisitor
33+
class [[nodiscard("unnecessary construction")]] TypeVisitor
3434
{
3535
public:
36-
[[nodiscard]] std::pair<std::string_view, TypeModifierStack> getType();
36+
[[nodiscard("unnecessary construction")]] std::pair<std::string_view, TypeModifierStack>
37+
getType();
3738

3839
void visit(const peg::ast_node& typeName);
3940

@@ -49,10 +50,10 @@ class [[nodiscard]] TypeVisitor
4950

5051
// Recursively visit a Value node representing the default value on an input field
5152
// and build a JSON representation of the hardcoded value.
52-
class [[nodiscard]] DefaultValueVisitor
53+
class [[nodiscard("unnecessary construction")]] DefaultValueVisitor
5354
{
5455
public:
55-
[[nodiscard]] response::Value getValue();
56+
[[nodiscard("unnecessary construction")]] response::Value getValue();
5657

5758
void visit(const peg::ast_node& value);
5859

include/GeneratorUtil.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
namespace graphql::generator {
1414

1515
// RAII object to help with emitting matching include guard begin and end statements
16-
class [[nodiscard]] IncludeGuardScope
16+
class [[nodiscard("unnecessary construction")]] IncludeGuardScope
1717
{
1818
public:
19-
explicit IncludeGuardScope(std::ostream& outputFile, std::string_view headerFileName) noexcept;
19+
explicit IncludeGuardScope(std::ostream & outputFile, std::string_view headerFileName) noexcept;
2020
~IncludeGuardScope() noexcept;
2121

2222
private:
@@ -25,12 +25,13 @@ class [[nodiscard]] IncludeGuardScope
2525
};
2626

2727
// RAII object to help with emitting matching namespace begin and end statements
28-
class [[nodiscard]] NamespaceScope
28+
class [[nodiscard("unnecessary construction")]] NamespaceScope
2929
{
3030
public:
31-
explicit NamespaceScope(
32-
std::ostream& outputFile, std::string_view cppNamespace, bool deferred = false) noexcept;
33-
NamespaceScope(NamespaceScope&& other) noexcept;
31+
explicit NamespaceScope(std::ostream & outputFile,
32+
std::string_view cppNamespace,
33+
bool deferred = false) noexcept;
34+
NamespaceScope(NamespaceScope && other) noexcept;
3435
~NamespaceScope() noexcept;
3536

3637
bool enter() noexcept;
@@ -44,10 +45,10 @@ class [[nodiscard]] NamespaceScope
4445

4546
// Keep track of whether we want to add a blank separator line once some additional content is about
4647
// to be output.
47-
class [[nodiscard]] PendingBlankLine
48+
class [[nodiscard("unnecessary construction")]] PendingBlankLine
4849
{
4950
public:
50-
explicit PendingBlankLine(std::ostream& outputFile) noexcept;
51+
explicit PendingBlankLine(std::ostream & outputFile) noexcept;
5152

5253
void add() noexcept;
5354
bool reset() noexcept;

0 commit comments

Comments
 (0)