Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT LAND] src: run clang-format on LINT_CPP_FILES #21998

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!test/fixtures/**/.*
!tools/node_modules/**/.*
!tools/doc/node_modules/**/.*
!.clang-format
!.editorconfig
!.eslintignore
!.eslintrc.js
Expand Down
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,33 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
# and the actual filename is generated so it won't match header guards
ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard

format-cpp-build:
cd tools/clang-format && $(call available-node,$(run-npm-install))

format-cpp-clean:
$(RM) -r tools/clang-format/node_modules

CLANG_FORMAT_START ?= HEAD
.PHONY: format-cpp
# To format staged changes:
# $ make format-cpp
# To format HEAD~1...HEAD (latest commit):
# $ CLANG_FORMAT_START=`git rev-parse HEAD~1` make format-cpp
# To format diff between master and current branch head (master...HEAD):
# $ CLANG_FORMAT_START=master make format-cpp
format-cpp: ## Format C++ diff from $CLANG_FORMAT_START to current changes
ifneq ("","$(wildcard tools/clang-format/node_modules/)")
@echo "Formatting C++ diff from $(CLANG_FORMAT_START).."
@$(PYTHON) tools/clang-format/node_modules/.bin/git-clang-format \
--binary=tools/clang-format/node_modules/.bin/clang-format \
--style=file \
$(CLANG_FORMAT_START) -- \
$(LINT_CPP_FILES)
else
@echo "clang-format is not installed."
@echo "To install (requires internet access) run: $ make format-cpp-build"
endif

.PHONY: lint-cpp
# Lints the C++ code with cpplint.py and check-imports.py.
lint-cpp: tools/.cpplintstamp
Expand Down
2 changes: 1 addition & 1 deletion benchmark/napi/function_call/binding.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <v8.h>
#include <node.h>
#include <v8.h>

static int c = 0;

Expand Down
58 changes: 18 additions & 40 deletions src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#ifndef SRC_ALIASED_BUFFER_H_
#define SRC_ALIASED_BUFFER_H_

#include "v8.h"
#include "util-inl.h"
#include "v8.h"

namespace node {

Expand All @@ -25,10 +25,7 @@ template <class NativeT, class V8T>
class AliasedBuffer {
public:
AliasedBuffer(v8::Isolate* isolate, const size_t count)
: isolate_(isolate),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this was more readable before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ConstructorInitializerAllOnOneLineOrOnePerLine. There is apparently no option to force one per line.

count_(count),
byte_offset_(0),
free_buffer_(true) {
: isolate_(isolate), count_(count), byte_offset_(0), free_buffer_(true) {
CHECK_GT(count, 0);
const v8::HandleScope handle_scope(isolate_);

Expand All @@ -38,8 +35,8 @@ class AliasedBuffer {
buffer_ = Calloc<NativeT>(count);

// allocate v8 ArrayBuffer
v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
isolate_, buffer_, sizeInBytes);
v8::Local<v8::ArrayBuffer> ab =
v8::ArrayBuffer::New(isolate_, buffer_, sizeInBytes);

// allocate v8 TypedArray
v8::Local<V8T> js_array = V8T::New(ab, byte_offset_, count);
Expand All @@ -57,8 +54,7 @@ class AliasedBuffer {
AliasedBuffer(v8::Isolate* isolate,
const size_t byte_offset,
const size_t count,
const AliasedBuffer<uint8_t,
v8::Uint8Array>& backing_buffer)
const AliasedBuffer<uint8_t, v8::Uint8Array>& backing_buffer)
: isolate_(isolate),
count_(count),
byte_offset_(byte_offset),
Expand All @@ -70,7 +66,7 @@ class AliasedBuffer {
// validate that the byte_offset is aligned with sizeof(NativeT)
CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0);
// validate this fits inside the backing buffer
CHECK_LE(sizeof(NativeT) * count, ab->ByteLength() - byte_offset);
CHECK_LE(sizeof(NativeT) * count, ab->ByteLength() - byte_offset);

buffer_ = reinterpret_cast<NativeT*>(
const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset));
Expand Down Expand Up @@ -117,14 +113,10 @@ class AliasedBuffer {
class Reference {
public:
Reference(AliasedBuffer<NativeT, V8T>* aliased_buffer, size_t index)
: aliased_buffer_(aliased_buffer),
index_(index) {
}
: aliased_buffer_(aliased_buffer), index_(index) {}

Reference(const Reference& that)
: aliased_buffer_(that.aliased_buffer_),
index_(that.index_) {
}
: aliased_buffer_(that.aliased_buffer_), index_(that.index_) {}

inline Reference& operator=(const NativeT& val) {
aliased_buffer_->SetValue(index_, val);
Expand All @@ -135,9 +127,7 @@ class AliasedBuffer {
return *this = static_cast<NativeT>(val);
}

operator NativeT() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have return always on a new line?

return aliased_buffer_->GetValue(index_);
}
operator NativeT() const { return aliased_buffer_->GetValue(index_); }

inline Reference& operator+=(const NativeT& val) {
const NativeT current = aliased_buffer_->GetValue(index_);
Expand All @@ -163,14 +153,12 @@ class AliasedBuffer {
/**
* Get the underlying v8 TypedArray overlayed on top of the native buffer
*/
v8::Local<V8T> GetJSArray() const {
return js_array_.Get(isolate_);
}
v8::Local<V8T> GetJSArray() const { return js_array_.Get(isolate_); }

/**
* Get the underlying v8::ArrayBuffer underlying the TypedArray and
* overlaying the native buffer
*/
* Get the underlying v8::ArrayBuffer underlying the TypedArray and
* overlaying the native buffer
*/
v8::Local<v8::ArrayBuffer> GetArrayBuffer() const {
return GetJSArray()->Buffer();
}
Expand All @@ -179,16 +167,12 @@ class AliasedBuffer {
* Get the underlying native buffer. Note that all reads/writes should occur
* through the GetValue/SetValue/operator[] methods
*/
inline const NativeT* GetNativeBuffer() const {
return buffer_;
}
inline const NativeT* GetNativeBuffer() const { return buffer_; }

/**
* Synonym for GetBuffer()
*/
inline const NativeT* operator * () const {
return GetNativeBuffer();
}
inline const NativeT* operator*() const { return GetNativeBuffer(); }

/**
* Set position index to given value.
Expand All @@ -213,17 +197,11 @@ class AliasedBuffer {
/**
* Effectively, a synonym for GetValue/SetValue
*/
Reference operator[](size_t index) {
return Reference(this, index);
}
Reference operator[](size_t index) { return Reference(this, index); }

NativeT operator[](size_t index) const {
return GetValue(index);
}
NativeT operator[](size_t index) const { return GetValue(index); }

size_t Length() const {
return count_;
}
size_t Length() const { return count_; }

private:
v8::Isolate* isolate_;
Expand Down
26 changes: 6 additions & 20 deletions src/async_wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
return provider_type_;
}


inline double AsyncWrap::get_async_id() const {
return async_id_;
}


inline double AsyncWrap::get_trigger_async_id() const {
return trigger_async_id_;
}


inline AsyncWrap::AsyncScope::AsyncScope(AsyncWrap* wrap)
: wrap_(wrap) {
inline AsyncWrap::AsyncScope::AsyncScope(AsyncWrap* wrap) : wrap_(wrap) {
Environment* env = wrap->env();
if (env->async_hooks()->fields()[Environment::AsyncHooks::kBefore] == 0)
return;
Expand All @@ -60,27 +56,18 @@ inline AsyncWrap::AsyncScope::~AsyncScope() {
EmitAfter(env, wrap_->get_async_id());
}


inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
const v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv) {
const v8::Local<v8::String> symbol, int argc, v8::Local<v8::Value>* argv) {
return MakeCallback(symbol.As<v8::Name>(), argc, argv);
}


inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
const v8::Local<v8::Symbol> symbol,
int argc,
v8::Local<v8::Value>* argv) {
const v8::Local<v8::Symbol> symbol, int argc, v8::Local<v8::Value>* argv) {
return MakeCallback(symbol.As<v8::Name>(), argc, argv);
}


inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
const v8::Local<v8::Name> symbol,
int argc,
v8::Local<v8::Value>* argv) {
const v8::Local<v8::Name> symbol, int argc, v8::Local<v8::Value>* argv) {
v8::Local<v8::Value> cb_v;
if (!object()->Get(env()->context(), symbol).ToLocal(&cb_v))
return v8::MaybeLocal<v8::Value>();
Expand All @@ -92,10 +79,9 @@ inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
return MakeCallback(cb_v.As<v8::Function>(), argc, argv);
}


// Defined here to avoid a circular dependency with env-inl.h.
inline Environment::AsyncHooks::DefaultTriggerAsyncIdScope
::DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap)
inline Environment::AsyncHooks::DefaultTriggerAsyncIdScope ::
DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap)
: DefaultTriggerAsyncIdScope(async_wrap->env(),
async_wrap->get_async_id()) {}

Expand Down
Loading