Skip to content

Commit

Permalink
build: add linter scripts and use it on travis
Browse files Browse the repository at this point in the history
PR-URL: #260
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
mmarchini committed Feb 26, 2019
1 parent 886a03d commit 85f067a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ matrix:
script: npm run test-all
node_js: "10"

##########
# Linter #
##########

- name: "Linter"
sudo: required
dist: trusty
before_install:
- sudo apt-get -qq update
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
install: npm install
script: npm run linter
node_js: "10"

# Allow the nightly installs to fail
allow_failures:

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"codecov-upload-cc": "codecov --disable=gcov --file=coverage-cc.info",
"codecov-upload-js": "codecov --disable=gcov --file=coverage-js.lcov",
"codecov-upload": "npm run codecov-upload-cc && npm run codecov-upload-js",
"linter": "node scripts/linter.js",
"format": "clang-format -i src/*"
},
"repository": {
Expand Down
41 changes: 41 additions & 0 deletions scripts/linter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const { getNativeBinary } = require("clang-format");
const { exec } = require("child_process");
const { readdir, readFile } = require("fs");

const dirtyFiles = [];

process.on("exit", () => {
if (dirtyFiles.length == 0) {
return;
}
process.exitCode = 1;
process._rawDebug("The following files are not formatted correctly:");
for (let file of dirtyFiles) {
process._rawDebug(` ${file}`);
}

});

readdir("./src/", (err, files) => {
for (let file of files) {
readFile(`./src/${file}`, {encoding: 'utf8'}, (err, data) => {
if (err) {
console.error(err);
process.exitCode = 2;
return;
}
exec(`${getNativeBinary()} src/${file}`, {maxBuffer: 1024 * 1024 * 5}, (err, stdout, stderr) => {
if (err) {
console.error(err);
process.exitCode = 2;
return;
}
if (stdout.trim() != data.trim()) {
dirtyFiles.push(file);
}
});
});
}
});

0 comments on commit 85f067a

Please sign in to comment.