Skip to content

Commit 64410f2

Browse files
Derek Lewiscodebytere
Derek Lewis
authored andcommitted
doc: normalize C++ code block info strings
Prior to this commit, C++ fenced code blocks in Markdown files had inconsistent info strings. This has been corrected to standarize on the one with the highest frequency in the doc/api/ dir. Stats: > 'cpp' => 19, > 'C++' => 6, > 'c++' => 3, PR-URL: #33483 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 748720e commit 64410f2

8 files changed

+41
-41
lines changed

doc/api/addons.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ The context-aware addon can be structured to avoid global static data by
157157
performing the following steps:
158158
* Define a class which will hold per-addon-instance data and which has a static
159159
member of the form
160-
```C++
161-
static void DeleteInstance(void* data) {
162-
// Cast `data` to an instance of the class and delete it.
163-
}
164-
```
160+
```cpp
161+
static void DeleteInstance(void* data) {
162+
// Cast `data` to an instance of the class and delete it.
163+
}
164+
```
165165
* Heap-allocate an instance of this class in the addon initializer. This can be
166166
accomplished using the `new` keyword.
167167
* Call `node::AddEnvironmentCleanupHook()`, passing it the above-created
@@ -245,7 +245,7 @@ In order to support [`Worker`][] threads, addons need to clean up any resources
245245
they may have allocated when such a thread exists. This can be achieved through
246246
the usage of the `AddEnvironmentCleanupHook()` function:
247247
248-
```c++
248+
```cpp
249249
void AddEnvironmentCleanupHook(v8::Isolate* isolate,
250250
void (*fun)(void* arg),
251251
void* arg);

doc/api/embedding.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Node.js requires some per-process state management in order to run:
3333
The following example shows how these can be set up. Some class names are from
3434
the `node` and `v8` C++ namespaces, respectively.
3535

36-
```c++
36+
```cpp
3737
int main(int argc, char** argv) {
3838
std::vector<std::string> args(argv, argv + argc);
3939
std::vector<std::string> exec_args;
@@ -93,7 +93,7 @@ The `node::NewIsolate()` helper function creates a `v8::Isolate`,
9393
sets it up with some Node.js-specific hooks (e.g. the Node.js error handler),
9494
and registers it with the platform automatically.
9595
96-
```c++
96+
```cpp
9797
int RunNodeInstance(MultiIsolatePlatform* platform,
9898
const std::vector<std::string>& args,
9999
const std::vector<std::string>& exec_args) {

doc/api/n-api.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ following `node-addon-api` code. The first section shows the
4545
`node-addon-api` code and the second section shows what actually gets
4646
used in the addon.
4747

48-
```C++
48+
```cpp
4949
Object obj = Object::New(env);
5050
obj["foo"] = String::New(env, "bar");
5151
```
5252

53-
```C++
53+
```cpp
5454
napi_status status;
5555
napi_value object, string;
5656
status = napi_create_object(env, &object);
@@ -87,7 +87,7 @@ versions:
8787

8888
* the Node.js C++ APIs available via any of
8989

90-
```C++
90+
```cpp
9191
#include <node.h>
9292
#include <node_buffer.h>
9393
#include <node_version.h>
@@ -96,13 +96,13 @@ versions:
9696

9797
* the libuv APIs which are also included with Node.js and available via
9898

99-
```C++
99+
```cpp
100100
#include <uv.h>
101101
```
102102

103103
* the V8 API available via
104104

105-
```C++
105+
```cpp
106106
#include <v8.h>
107107
```
108108

doc/guides/cpp-style-guide.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Comments should also start with uppercase and finish with a dot.
6767

6868
Examples:
6969

70-
```c++
70+
```cpp
7171
// A single-line comment.
7272

7373
// Multi-line comments
@@ -82,14 +82,14 @@ comments.
8282

8383
### 2 spaces of indentation for blocks or bodies of conditionals
8484

85-
```c++
85+
```cpp
8686
if (foo)
8787
bar();
8888
```
8989

9090
or
9191

92-
```c++
92+
```cpp
9393
if (foo) {
9494
bar();
9595
baz();
@@ -102,7 +102,7 @@ Braces are optional if the statement body only has one line.
102102

103103
### 4 spaces of indentation for statement continuations
104104

105-
```c++
105+
```cpp
106106
VeryLongTypeName very_long_result = SomeValueWithAVeryLongName +
107107
SomeOtherValueWithAVeryLongName;
108108
```
@@ -111,15 +111,15 @@ Operators are before the line break in these cases.
111111

112112
### Align function arguments vertically
113113

114-
```c++
114+
```cpp
115115
void FunctionWithAVeryLongName(int parameter_with_a_very_long_name,
116116
double other_parameter_with_a_very_long_name,
117117
...);
118118
```
119119
120120
If that doesn’t work, break after the `(` and use 4 spaces of indentation:
121121
122-
```c++
122+
```cpp
123123
void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt(
124124
int okay_there_is_no_space_left_in_the_previous_line,
125125
...);
@@ -129,7 +129,7 @@ void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt(
129129

130130
Long initialization lists are formatted like this:
131131

132-
```c++
132+
```cpp
133133
HandleWrap::HandleWrap(Environment* env,
134134
Local<Object> object,
135135
uv_handle_t* handle,
@@ -144,7 +144,7 @@ HandleWrap::HandleWrap(Environment* env,
144144
Exceptions are simple getters/setters, which are named `property_name()` and
145145
`set_property_name()`, respectively.
146146
147-
```c++
147+
```cpp
148148
class FooBar {
149149
public:
150150
void DoSomething();
@@ -157,15 +157,15 @@ class FooBar {
157157

158158
### `snake_case` for local variables and parameters
159159

160-
```c++
160+
```cpp
161161
int FunctionThatDoesSomething(const char* important_string) {
162162
const char* pointer_into_string = important_string;
163163
}
164164
```
165165
166166
### `snake_case_` for private class fields
167167
168-
```c++
168+
```cpp
169169
class Foo {
170170
private:
171171
int counter_ = 0;
@@ -176,15 +176,15 @@ class Foo {
176176

177177
For plain C-like structs snake_case can be used.
178178

179-
```c++
179+
```cpp
180180
struct foo_bar {
181181
int name;
182182
}
183183
```
184184
185185
### Space after `template`
186186
187-
```c++
187+
```cpp
188188
template <typename T>
189189
class FancyContainer {
190190
...
@@ -232,7 +232,7 @@ Using non-const references often obscures which values are changed by an
232232
assignment. Consider using a pointer instead, which requires more explicit
233233
syntax to indicate that modifications take place.
234234
235-
```c++
235+
```cpp
236236
class ExampleClass {
237237
public:
238238
explicit ExampleClass(OtherClass* other_ptr) : pointer_to_other_(other_ptr) {}
@@ -269,7 +269,7 @@ When working with typed arrays that involve direct data modification
269269
from C++, use an `AliasedBuffer` when possible. The API abstraction and
270270
the usage scope of `AliasedBuffer` are documented in [aliased_buffer.h][].
271271

272-
```c++
272+
```cpp
273273
// Create an AliasedBuffer.
274274
AliasedBuffer<uint32_t, v8::Uint32Array> data;
275275
...

doc/guides/investigating_native_memory_leak.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ example leak based on the "Hello world" addon from
103103
In this example, a loop which allocates ~1MB of memory and never frees it
104104
has been added:
105105

106-
```C++
106+
```cpp
107107
void* malloc_holder = nullptr;
108108
napi_value Method(napi_env env, napi_callback_info info) {
109109
napi_status status;

doc/guides/node-postmortem-support.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ For example, if we want to add a constant with the offset for
3535
`sizeof(req_)` depends on the type of T, which means the class definition should
3636
be like this:
3737

38-
```c++
38+
```cpp
3939
template <typename T>
4040
class ReqWrap : public AsyncWrap {
4141
private:
@@ -49,7 +49,7 @@ class ReqWrap : public AsyncWrap {
4949
5050
instead of:
5151
52-
```c++
52+
```cpp
5353
template <typename T>
5454
class ReqWrap : public AsyncWrap {
5555
private:

doc/guides/writing-tests.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ The unit test should be placed in `test/cctest` and be named with the prefix
356356
`test` followed by the name of unit being tested. For example, the code below
357357
would be placed in `test/cctest/test_env.cc`:
358358

359-
```c++
359+
```cpp
360360
#include "gtest/gtest.h"
361361
#include "node_test_fixture.h"
362362
#include "env.h"

src/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function getFoo(obj) {
137137
}
138138
```
139139

140-
```c++
140+
```cpp
141141
v8::Local<v8::Value> GetFoo(v8::Local<v8::Context> context,
142142
v8::Local<v8::Object> obj) {
143143
v8::Isolate* isolate = context->GetIsolate();
@@ -168,7 +168,7 @@ See [exception handling][] for more information about the usage of `.To()`,
168168
If it is known that a `Local<Value>` refers to a more specific type, it can
169169
be cast to that type using `.As<...>()`:
170170
171-
```c++
171+
```cpp
172172
v8::Local<v8::Value> some_value;
173173
// CHECK() is a Node.js utilitity that works similar to assert().
174174
CHECK(some_value->IsUint8Array());
@@ -201,7 +201,7 @@ alive even if no other objects refer to them. Weak global handles do not do
201201
that, and instead optionally call a callback when the object they refer to
202202
is garbage-collected.
203203

204-
```c++
204+
```cpp
205205
v8::Global<v8::Object> reference;
206206

207207
void StoreReference(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
@@ -329,7 +329,7 @@ The platform can be accessed through `isolate_data->platform()` given an
329329
C++ functions exposed to JS follow a specific signature. The following example
330330
is from `node_util.cc`:
331331
332-
```c++
332+
```cpp
333333
void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
334334
CHECK(args[0]->IsArrayBufferView());
335335
args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
@@ -351,7 +351,7 @@ floating-point number or a `Local<Value>` to set the return value.
351351
Node.js provides various helpers for building JS classes in C++ and/or attaching
352352
C++ functions to the exports of a built-in module:
353353

354-
```c++
354+
```cpp
355355
void Initialize(Local<Object> target,
356356
Local<Value> unused,
357357
Local<Context> context,
@@ -409,7 +409,7 @@ constant string, in order to disambiguate it from other classes of this type,
409409
and which could e.g. match the binding’s name (in the example above, that would
410410
be `cares_wrap`).
411411
412-
```c++
412+
```cpp
413413
// In the HTTP parser source code file:
414414
class BindingData : public BaseObject {
415415
public:
@@ -523,7 +523,7 @@ to perform further calls to APIs that return `Maybe`s.
523523
A typical pattern for dealing with APIs that return `Maybe` and `MaybeLocal` is
524524
using `.ToLocal()` and `.To()` and returning early in case there is an error:
525525

526-
```c++
526+
```cpp
527527
// This could also return a v8::MaybeLocal<v8::Number>, for example.
528528
v8::Maybe<double> SumNumbers(v8::Local<v8::Context> context,
529529
v8::Local<v8::Array> array_of_integers) {
@@ -692,7 +692,7 @@ A helper for this is the `ASSIGN_OR_RETURN_UNWRAP` macro that returns from the
692692
current function if unwrapping fails (typically that means that the `BaseObject`
693693
has been deleted earlier).
694694
695-
```c++
695+
```cpp
696696
void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
697697
Http2Session* session;
698698
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
@@ -780,7 +780,7 @@ queues once it returns.
780780
Before calling `MakeCallback()`, it is typically necessary to enter both a
781781
`HandleScope` and a `Context::Scope`.
782782

783-
```c++
783+
```cpp
784784
void StatWatcher::Callback(uv_fs_poll_t* handle,
785785
int status,
786786
const uv_stat_t* prev,
@@ -872,7 +872,7 @@ The `Utf8Value`, `TwoByteValue` (i.e. UTF-16 value) and `BufferValue`
872872
inherit from this class and allow accessing the characters in a JavaScript
873873
string this way.
874874
875-
```c++
875+
```cpp
876876
static void Chdir(const FunctionCallbackInfo<Value>& args) {
877877
Environment* env = Environment::GetCurrent(args);
878878
// ...

0 commit comments

Comments
 (0)