Skip to content

Commit 85f067a

Browse files
committed
build: add linter scripts and use it on travis
PR-URL: #260 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 886a03d commit 85f067a

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ matrix:
112112
script: npm run test-all
113113
node_js: "10"
114114

115+
##########
116+
# Linter #
117+
##########
118+
119+
- name: "Linter"
120+
sudo: required
121+
dist: trusty
122+
before_install:
123+
- sudo apt-get -qq update
124+
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
125+
install: npm install
126+
script: npm run linter
127+
node_js: "10"
128+
115129
# Allow the nightly installs to fail
116130
allow_failures:
117131

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"codecov-upload-cc": "codecov --disable=gcov --file=coverage-cc.info",
2626
"codecov-upload-js": "codecov --disable=gcov --file=coverage-js.lcov",
2727
"codecov-upload": "npm run codecov-upload-cc && npm run codecov-upload-js",
28+
"linter": "node scripts/linter.js",
2829
"format": "clang-format -i src/*"
2930
},
3031
"repository": {

scripts/linter.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const { getNativeBinary } = require("clang-format");
4+
const { exec } = require("child_process");
5+
const { readdir, readFile } = require("fs");
6+
7+
const dirtyFiles = [];
8+
9+
process.on("exit", () => {
10+
if (dirtyFiles.length == 0) {
11+
return;
12+
}
13+
process.exitCode = 1;
14+
process._rawDebug("The following files are not formatted correctly:");
15+
for (let file of dirtyFiles) {
16+
process._rawDebug(` ${file}`);
17+
}
18+
19+
});
20+
21+
readdir("./src/", (err, files) => {
22+
for (let file of files) {
23+
readFile(`./src/${file}`, {encoding: 'utf8'}, (err, data) => {
24+
if (err) {
25+
console.error(err);
26+
process.exitCode = 2;
27+
return;
28+
}
29+
exec(`${getNativeBinary()} src/${file}`, {maxBuffer: 1024 * 1024 * 5}, (err, stdout, stderr) => {
30+
if (err) {
31+
console.error(err);
32+
process.exitCode = 2;
33+
return;
34+
}
35+
if (stdout.trim() != data.trim()) {
36+
dirtyFiles.push(file);
37+
}
38+
});
39+
});
40+
}
41+
});

0 commit comments

Comments
 (0)