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

Feature/clang format #3612

Closed
wants to merge 1 commit into from
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
25 changes: 25 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: 'true'
AlignConsecutiveAssignments: 'false'
AlignEscapedNewlinesLeft: 'false'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AlwaysBreakTemplateDeclarations: 'true'
BinPackArguments: 'false'
BinPackParameters: 'false'
ColumnLimit: '80'
IndentWidth: '2'
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: None
PointerAlignment: Left
SpaceAfterCStyleCast: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpacesBeforeTrailingComments: '2'
TabWidth: '2'
UseTab: Never

...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ test.tap
# Xcode workspaces and project folders
*.xcodeproj
*.xcworkspace
tools/format/clang-format-*
!tools/format/clang-format-*.sha1
tools/format/external_bin
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ copy locally.
$ git clone git@github.com:username/node.git
$ cd node
$ git remote add upstream git://github.com/nodejs/node.git
$ # Either install `clang-format` (version 3.7.0 or 3.8.0) or download one with
$ # `make download-clang-format`
$ make install-pre-commit-hook
```

#### Which branch?
Expand Down
61 changes: 58 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,62 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
tools/icu/*.h \
))

cpplint:
@$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
GOOGLE_DOWNLOAD ?= tools/format/download_from_google_storage
GOOGLE_DOWNLOAD_FLAGS ?= --no_resume --no_auth

tools/format/clang-format-mac: tools/format/clang-format-mac.sha1
@echo "Downloading clang-format, may take some time"
@$(GOOGLE_DOWNLOAD) $(GOOGLE_DOWNLOAD_FLAGS) --platform=darwin \
--bucket chromium-clang-format -s $<

tools/format/clang-format-win.exe: tools/format/clang-format-win.exe.sha1
@echo "Downloading clang-format, may take some time"
@$(GOOGLE_DOWNLOAD) $(GOOGLE_DOWNLOAD_FLAGS) --platform=win32 \
--bucket chromium-clang-format -s $<

tools/format/clang-format-linux64: tools/format/clang-format-linux64.sha1
@echo "Downloading clang-format, may take some time"
@$(GOOGLE_DOWNLOAD) $(GOOGLE_DOWNLOAD_FLAGS) --platform=linux* \
--bucket chromium-clang-format -s $<

ifeq ($(OSTYPE),darwin)
CLANG_EXTERNAL_FORMAT ?= tools/format/clang-format-mac
else ifeq ($(OSTYPE),linux)
CLANG_EXTERNAL_FORMAT ?= tools/format/clang-format-linux64
else
CLANG_EXTERNAL_FORMAT ?= tools/format/clang-format-win.exe
endif

ifneq ("$(wildcard $(CLANG_EXTERNAL_FORMAT))", "")
CLANG_FORMAT ?= $(CLANG_EXTERNAL_FORMAT)
else
CLANG_FORMAT ?= clang-format
endif

CLANG_LINT ?= ./tools/format/git-clang-format --binary $(CLANG_FORMAT)
CLANG_LINT_BASE ?= origin/master
CLANG_LINT_COMMIT ?= $(shell git merge-base @ $(CLANG_LINT_BASE))

download-clang-format: $(CLANG_EXTERNAL_FORMAT)

check-clang-format-version:
@($(CLANG_FORMAT) -version | grep -q "3\.[78]\.0") || \
(echo "Wrong clang-format version, expected either 3.7.0 or 3.8.0" && \
exit 1)

cpplint: check-clang-format-version
@echo "Formatting against $(CLANG_LINT_COMMIT)"
@if [[ $$($(CLANG_LINT) $(CLANG_LINT_COMMIT) --diff -- $(CPPLINT_FILES) | grep "diff ") ]]; then \
echo "Lint issues detected, please run \"make format-commit\""; \
exit 1;\
fi

format-commit: check-clang-format-version
@$(CLANG_LINT) -- $(CPPLINT_FILES)

install-pre-commit-hook: check-clang-format-version
@echo "#!/bin/sh\nexec make format-commit" > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit

lint: jslint cpplint

Expand All @@ -541,4 +595,5 @@ lint: jslint cpplint
dynamiclib test test-all test-addons build-addons website-upload pkg \
blog blogclean tar binary release-only bench-http-simple bench-idle \
bench-all bench bench-misc bench-array bench-buffer bench-net \
bench-http bench-fs bench-tls cctest run-ci
bench-http bench-fs bench-tls cctest run-ci format-commit \
install-pre-commit-hook download-clang-format check-clang-format-version
1 change: 1 addition & 0 deletions tools/format/clang-format-linux64.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
acc9e19e04ad4cf6be067366d2522348cd160ae1
1 change: 1 addition & 0 deletions tools/format/clang-format-mac.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e66adcd1631b8d80650e7b15106033b04c9c2212
1 change: 1 addition & 0 deletions tools/format/clang-format-win.exe.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dd661c89fa003a9ebd57d59a7fea346c1fc87f79
8 changes: 8 additions & 0 deletions tools/format/download_from_google_storage
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

base_dir=$(dirname "$0")

PYTHONDONTWRITEBYTECODE=1 exec python "$base_dir/download_from_google_storage.py" "$@"
Copy link
Member

Choose a reason for hiding this comment

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

-B does the same thing and keeps it below 80 columns.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not my file :) See copyright above.

Copy link
Member

Choose a reason for hiding this comment

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

I saw it, it's just a suggestion.

10 changes: 10 additions & 0 deletions tools/format/download_from_google_storage.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
:: Copyright (c) 2012 The Chromium Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style license that can be
:: found in the LICENSE file.

:: This is required with cygwin only.
PATH=%~dp0;%PATH%

:: Defer control.
%~dp0python "%~dp0\download_from_google_storage.py" %*
Loading