Skip to content

Commit 8ab7c7e

Browse files
author
mustiikhalil
authored
[CI] Adds formatter to CI (google#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
1 parent 7e00390 commit 8ab7c7e

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,11 @@ matrix:
200200
script:
201201
- cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .; make; export PATH="$PATH:${PWD}"
202202
- cd android; ./gradlew clean build
203+
204+
- language: generic
205+
os: linux
206+
install:
207+
- bash .travis/format_install.sh
208+
209+
script:
210+
- bash .travis/format_check.sh

.travis/format_check.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2020 Google Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
# HACKY solution to make nodejs work.
20+
source ~/.nvm/nvm.sh
21+
nvm alias default node
22+
nvm use default
23+
24+
sh src/clang-format-git.sh
25+
26+
node_modules/.bin/eslint ts/** --ext .ts --quiet --fix
27+
28+
#PYTHON IS DISABLED UNTIL WE CREATE A .pylintrc FILE FOR IT
29+
pylint python/** --disable=all
30+
31+
swiftformat --config swift.swiftformat .
32+
33+
if ! git diff --quiet; then
34+
echo >&2
35+
echo "ERROR: ********************************************************" >&2
36+
echo "ERROR: The following differences were found after running" >&2
37+
echo "ERROR: .travis/format_check.sh script. Maybe you forgot to format" >&2
38+
echo "ERROR: the code after making changes? please check Formatters.md" >&2
39+
echo "ERROR: ********************************************************" >&2
40+
echo >&2
41+
git diff --binary --exit-code
42+
fi

.travis/format_install.sh

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2020 Google Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
set -x
19+
20+
# install devtools
21+
install_languages() {
22+
sudo apt update
23+
24+
# Install nodeJS and yarn
25+
wget https://raw.githubusercontent.com/creationix/nvm/v0.31.0/nvm.sh -O ~/.nvm/nvm.sh
26+
source ~/.nvm/nvm.sh
27+
nvm install node
28+
node --version
29+
curl -o- -L https://yarnpkg.com/install.sh | bash
30+
export PATH="$HOME/.yarn/bin:$PATH"
31+
yarn config set prefix ~/.yarn -g
32+
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
33+
34+
# Install swift
35+
sudo apt-get install \
36+
binutils \
37+
git \
38+
libc6-dev \
39+
libcurl3 \
40+
libedit2 \
41+
libgcc-5-dev \
42+
libpython2.7 \
43+
libsqlite3-0 \
44+
libstdc++-5-dev \
45+
libxml2 \
46+
pkg-config \
47+
tzdata \
48+
zlib1g-dev
49+
50+
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
51+
curl -fSsL "$SWIFT_URL" -o swift.tar.gz
52+
53+
mkdir ~/swiftbuild
54+
tar -xvzf swift.tar.gz -C ~/swiftbuild
55+
56+
export PATH="~/swiftbuild/swift-5.3.1-RELEASE-ubuntu16.04/usr/bin:$PATH"
57+
58+
swift --version
59+
yarn -v
60+
node -v
61+
}
62+
63+
install_formatters() {
64+
# installing swift formatter
65+
git clone --depth 1 --branch 0.47.4 https://github.com/nicklockwood/SwiftFormat.git
66+
cd SwiftFormat
67+
swift build -c release
68+
sudo cp .build/release/swiftformat /usr/local/bin/swiftformat
69+
cd ..
70+
71+
which yarn
72+
which node
73+
yarn -v
74+
node -v
75+
76+
yarn install
77+
pip install pylint
78+
}
79+
80+
install_languages
81+
export PATH="~/swift/swift/usr/bin:$PATH"
82+
install_formatters

Formatters.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Format Guidelines
2+
3+
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.
4+
5+
# Notes
6+
7+
- Run the linter on the language you are working on before making a Pull Request.
8+
- DONT format/lint the generated code.
9+
10+
# Languages
11+
12+
## C++
13+
14+
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).
15+
16+
## Swift
17+
18+
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
19+
20+
## Typescript
21+
22+
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

0 commit comments

Comments
 (0)