summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormustiikhalil <mustii@mmk.one>2020-12-11 21:46:10 +0300
committerGitHub <noreply@github.com>2020-12-11 10:46:10 -0800
commit8ab7c7e2c82c168e6ce019f7b538350e3a1528dc (patch)
tree6dfa99e059daea50e153abc2ec05d886ac214272
parent7e00390289ef61dae0f27b22328c77f208917397 (diff)
downloadflatbuffers-8ab7c7e2c82c168e6ce019f7b538350e3a1528dc.tar.gz
flatbuffers-8ab7c7e2c82c168e6ce019f7b538350e3a1528dc.tar.bz2
flatbuffers-8ab7c7e2c82c168e6ce019f7b538350e3a1528dc.zip
[CI] Adds formatter to CI (#6272)
* Adds formatters CI Adds Error message & setup formatting like cpp Adds Swift Adds typescript Adds python tests yarn Adds format.md * Removes unneeded scripts + moves install script to install phase * Adds format.md content * Adds cpp to the formatter.md and fixes ci * Adds cpp to formatter ci
-rw-r--r--.travis.yml8
-rw-r--r--.travis/format_check.sh42
-rw-r--r--.travis/format_install.sh82
-rw-r--r--Formatters.md22
4 files changed, 154 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml
index 17d3cc0c..fb174fcf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -200,3 +200,11 @@ matrix:
script:
- cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .; make; export PATH="$PATH:${PWD}"
- cd android; ./gradlew clean build
+
+ - language: generic
+ os: linux
+ install:
+ - bash .travis/format_install.sh
+
+ script:
+ - bash .travis/format_check.sh
diff --git a/.travis/format_check.sh b/.travis/format_check.sh
new file mode 100644
index 00000000..cae8a29b
--- /dev/null
+++ b/.travis/format_check.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Copyright 2020 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+# HACKY solution to make nodejs work.
+source ~/.nvm/nvm.sh
+nvm alias default node
+nvm use default
+
+sh src/clang-format-git.sh
+
+node_modules/.bin/eslint ts/** --ext .ts --quiet --fix
+
+#PYTHON IS DISABLED UNTIL WE CREATE A .pylintrc FILE FOR IT
+pylint python/** --disable=all
+
+swiftformat --config swift.swiftformat .
+
+if ! git diff --quiet; then
+ echo >&2
+ echo "ERROR: ********************************************************" >&2
+ echo "ERROR: The following differences were found after running" >&2
+ echo "ERROR: .travis/format_check.sh script. Maybe you forgot to format" >&2
+ echo "ERROR: the code after making changes? please check Formatters.md" >&2
+ echo "ERROR: ********************************************************" >&2
+ echo >&2
+ git diff --binary --exit-code
+fi \ No newline at end of file
diff --git a/.travis/format_install.sh b/.travis/format_install.sh
new file mode 100644
index 00000000..41a3fed3
--- /dev/null
+++ b/.travis/format_install.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+#
+# Copyright 2020 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+set -x
+
+# install devtools
+install_languages() {
+ sudo apt update
+
+ # Install nodeJS and yarn
+ wget https://raw.githubusercontent.com/creationix/nvm/v0.31.0/nvm.sh -O ~/.nvm/nvm.sh
+ source ~/.nvm/nvm.sh
+ nvm install node
+ node --version
+ curl -o- -L https://yarnpkg.com/install.sh | bash
+ export PATH="$HOME/.yarn/bin:$PATH"
+ yarn config set prefix ~/.yarn -g
+ export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
+
+ # Install swift
+ sudo apt-get install \
+ binutils \
+ git \
+ libc6-dev \
+ libcurl3 \
+ libedit2 \
+ libgcc-5-dev \
+ libpython2.7 \
+ libsqlite3-0 \
+ libstdc++-5-dev \
+ libxml2 \
+ pkg-config \
+ tzdata \
+ zlib1g-dev
+
+ SWIFT_URL=https://swift.org/builds/swift-5.3.1-release/ubuntu1604/swift-5.3.1-RELEASE/swift-5.3.1-RELEASE-ubuntu16.04.tar.gz
+ curl -fSsL "$SWIFT_URL" -o swift.tar.gz
+
+ mkdir ~/swiftbuild
+ tar -xvzf swift.tar.gz -C ~/swiftbuild
+
+ export PATH="~/swiftbuild/swift-5.3.1-RELEASE-ubuntu16.04/usr/bin:$PATH"
+
+ swift --version
+ yarn -v
+ node -v
+}
+
+install_formatters() {
+ # installing swift formatter
+ git clone --depth 1 --branch 0.47.4 https://github.com/nicklockwood/SwiftFormat.git
+ cd SwiftFormat
+ swift build -c release
+ sudo cp .build/release/swiftformat /usr/local/bin/swiftformat
+ cd ..
+
+ which yarn
+ which node
+ yarn -v
+ node -v
+
+ yarn install
+ pip install pylint
+}
+
+install_languages
+export PATH="~/swift/swift/usr/bin:$PATH"
+install_formatters \ No newline at end of file
diff --git a/Formatters.md b/Formatters.md
new file mode 100644
index 00000000..18a51c4c
--- /dev/null
+++ b/Formatters.md
@@ -0,0 +1,22 @@
+# Format Guidelines
+
+If you are interesting in contributing to the flatbuffers project, please take a second to read this document. Each language has it's own set of rules, that are defined in their respective formatter/linter documents.
+
+# Notes
+
+- Run the linter on the language you are working on before making a Pull Request.
+- DONT format/lint the generated code.
+
+# Languages
+
+## C++
+
+C++ uses `clang-format` as it's formatter. Run the following script `sh src/clang-format-git.sh`, and it should style the C++ code according to [google style guide](https://google.github.io/styleguide/cppguide.html).
+
+## Swift
+
+Swift uses swiftformat as it's formatter. Take a look at [how to install here](https://github.com/nicklockwood/SwiftFormat/blob/master/README.md#how-do-i-install-it). Run the following command `swiftformat --config swift.swiftformat .` in the root directory of the project
+
+## Typescript
+
+Typescript uses eslint as it's linter. Take a look at [how to install here](https://eslint.org/docs/user-guide/getting-started). Run the following command `eslint ts/** --ext .ts` in the root directory of the project \ No newline at end of file