Skip to content

Commit

Permalink
doc: normalize C++ code block info strings
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Derek Lewis authored and BridgeAR committed May 23, 2020
1 parent 78eb420 commit 9dd7557
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
12 changes: 6 additions & 6 deletions doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ The context-aware addon can be structured to avoid global static data by
performing the following steps:
* Define a class which will hold per-addon-instance data and which has a static
member of the form
```C++
static void DeleteInstance(void* data) {
// Cast `data` to an instance of the class and delete it.
}
```
```cpp
static void DeleteInstance(void* data) {
// Cast `data` to an instance of the class and delete it.
}
```
* Heap-allocate an instance of this class in the addon initializer. This can be
accomplished using the `new` keyword.
* Call `node::AddEnvironmentCleanupHook()`, passing it the above-created
Expand Down Expand Up @@ -245,7 +245,7 @@ In order to support [`Worker`][] threads, addons need to clean up any resources
they may have allocated when such a thread exists. This can be achieved through
the usage of the `AddEnvironmentCleanupHook()` function:
```c++
```cpp
void AddEnvironmentCleanupHook(v8::Isolate* isolate,
void (*fun)(void* arg),
void* arg);
Expand Down
4 changes: 2 additions & 2 deletions doc/api/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Node.js requires some per-process state management in order to run:
The following example shows how these can be set up. Some class names are from
the `node` and `v8` C++ namespaces, respectively.

```c++
```cpp
int main(int argc, char** argv) {
std::vector<std::string> args(argv, argv + argc);
std::vector<std::string> exec_args;
Expand Down Expand Up @@ -93,7 +93,7 @@ The `node::NewIsolate()` helper function creates a `v8::Isolate`,
sets it up with some Node.js-specific hooks (e.g. the Node.js error handler),
and registers it with the platform automatically.
```c++
```cpp
int RunNodeInstance(MultiIsolatePlatform* platform,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args) {
Expand Down
10 changes: 5 additions & 5 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ following `node-addon-api` code. The first section shows the
`node-addon-api` code and the second section shows what actually gets
used in the addon.

```C++
```cpp
Object obj = Object::New(env);
obj["foo"] = String::New(env, "bar");
```

```C++
```cpp
napi_status status;
napi_value object, string;
status = napi_create_object(env, &object);
Expand Down Expand Up @@ -87,7 +87,7 @@ versions:

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

```C++
```cpp
#include <node.h>
#include <node_buffer.h>
#include <node_version.h>
Expand All @@ -96,13 +96,13 @@ versions:

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

```C++
```cpp
#include <uv.h>
```

* the V8 API available via

```C++
```cpp
#include <v8.h>
```

Expand Down
28 changes: 14 additions & 14 deletions doc/guides/cpp-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Comments should also start with uppercase and finish with a dot.

Examples:

```c++
```cpp
// A single-line comment.

// Multi-line comments
Expand All @@ -82,14 +82,14 @@ comments.

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

```c++
```cpp
if (foo)
bar();
```

or

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

### 4 spaces of indentation for statement continuations

```c++
```cpp
VeryLongTypeName very_long_result = SomeValueWithAVeryLongName +
SomeOtherValueWithAVeryLongName;
```
Expand All @@ -111,15 +111,15 @@ Operators are before the line break in these cases.

### Align function arguments vertically

```c++
```cpp
void FunctionWithAVeryLongName(int parameter_with_a_very_long_name,
double other_parameter_with_a_very_long_name,
...);
```
If that doesn’t work, break after the `(` and use 4 spaces of indentation:
```c++
```cpp
void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt(
int okay_there_is_no_space_left_in_the_previous_line,
...);
Expand All @@ -129,7 +129,7 @@ void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt(

Long initialization lists are formatted like this:

```c++
```cpp
HandleWrap::HandleWrap(Environment* env,
Local<Object> object,
uv_handle_t* handle,
Expand All @@ -144,7 +144,7 @@ HandleWrap::HandleWrap(Environment* env,
Exceptions are simple getters/setters, which are named `property_name()` and
`set_property_name()`, respectively.
```c++
```cpp
class FooBar {
public:
void DoSomething();
Expand All @@ -157,15 +157,15 @@ class FooBar {

### `snake_case` for local variables and parameters

```c++
```cpp
int FunctionThatDoesSomething(const char* important_string) {
const char* pointer_into_string = important_string;
}
```
### `snake_case_` for private class fields
```c++
```cpp
class Foo {
private:
int counter_ = 0;
Expand All @@ -176,15 +176,15 @@ class Foo {

For plain C-like structs snake_case can be used.

```c++
```cpp
struct foo_bar {
int name;
}
```
### Space after `template`
```c++
```cpp
template <typename T>
class FancyContainer {
...
Expand Down Expand Up @@ -232,7 +232,7 @@ Using non-const references often obscures which values are changed by an
assignment. Consider using a pointer instead, which requires more explicit
syntax to indicate that modifications take place.
```c++
```cpp
class ExampleClass {
public:
explicit ExampleClass(OtherClass* other_ptr) : pointer_to_other_(other_ptr) {}
Expand Down Expand Up @@ -269,7 +269,7 @@ When working with typed arrays that involve direct data modification
from C++, use an `AliasedBuffer` when possible. The API abstraction and
the usage scope of `AliasedBuffer` are documented in [aliased_buffer.h][].

```c++
```cpp
// Create an AliasedBuffer.
AliasedBuffer<uint32_t, v8::Uint32Array> data;
...
Expand Down
2 changes: 1 addition & 1 deletion doc/guides/investigating_native_memory_leak.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ example leak based on the "Hello world" addon from
In this example, a loop which allocates ~1MB of memory and never frees it
has been added:

```C++
```cpp
void* malloc_holder = nullptr;
napi_value Method(napi_env env, napi_callback_info info) {
napi_status status;
Expand Down
4 changes: 2 additions & 2 deletions doc/guides/node-postmortem-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ For example, if we want to add a constant with the offset for
`sizeof(req_)` depends on the type of T, which means the class definition should
be like this:

```c++
```cpp
template <typename T>
class ReqWrap : public AsyncWrap {
private:
Expand All @@ -49,7 +49,7 @@ class ReqWrap : public AsyncWrap {
instead of:
```c++
```cpp
template <typename T>
class ReqWrap : public AsyncWrap {
private:
Expand Down
2 changes: 1 addition & 1 deletion doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ The unit test should be placed in `test/cctest` and be named with the prefix
`test` followed by the name of unit being tested. For example, the code below
would be placed in `test/cctest/test_env.cc`:

```c++
```cpp
#include "gtest/gtest.h"
#include "node_test_fixture.h"
#include "env.h"
Expand Down
20 changes: 10 additions & 10 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function getFoo(obj) {
}
```

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

```c++
```cpp
v8::Global<v8::Object> reference;

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

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

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

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

0 comments on commit 9dd7557

Please sign in to comment.