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

Run linter (clang-format) on Travis #260

Closed
wants to merge 3 commits 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
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ uninstall-linux:

.PHONY: format
format:
clang-format -i src/*
npm run format

# This depends on the system setting e.g. $PATH so can't actually be skipped
.PHONY: configure
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"coverage": "npm run coverage-cc && npm run coverage-js",
"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"
"codecov-upload": "npm run codecov-upload-cc && npm run codecov-upload-js",
"linter": "node scripts/linter.js",
"format": "clang-format -i src/*"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,6 +56,7 @@
"devDependencies": {
"codecov": "^3.1.0",
"nyc": "^13.1.0",
"clang-format": "1.2.4",
"tape": "^4.4.0"
},
"nyc": {
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");
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
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);
}
});
});
}
});
10 changes: 4 additions & 6 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

namespace llnode {

using lldb::eReturnStatusFailed;
using lldb::eReturnStatusSuccessFinishResult;
using lldb::SBCommandInterpreter;
using lldb::SBCommandReturnObject;
using lldb::SBDebugger;
Expand All @@ -30,8 +32,6 @@ using lldb::SBSymbol;
using lldb::SBTarget;
using lldb::SBThread;
using lldb::SBValue;
using lldb::eReturnStatusFailed;
using lldb::eReturnStatusSuccessFinishResult;


bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
Expand Down Expand Up @@ -433,17 +433,15 @@ bool PluginInitialize(SBDebugger d) {
"JavaScript frame.\n\n"
"Syntax: v8 source list [flags]\n\n"
"Flags:\n"
" * -l <line> - Print source code below line <line>.\n"
);
" * -l <line> - Print source code below line <line>.\n");
interpreter.AddCommand("jssource", new llnode::ListCmd(&llv8),
"Alias for `v8 source list`");

v8.AddCommand("findjsobjects", new llnode::FindObjectsCmd(&llscan),
"List all object types and instance counts grouped by type "
"name and sorted by instance count. Use -d or --detailed to "
"get an output grouped by type name, properties, and array "
"length, as well as more information regarding each type.\n"
);
"length, as well as more information regarding each type.\n");

SBCommand settingsCmd =
v8.AddMultiwordCommand("settings", "Interpreter settings");
Expand Down
2 changes: 1 addition & 1 deletion src/llnode_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define SRC_LLNODE_API_H_

#include <memory>
#include <unordered_set>
#include <string>
#include <unordered_set>
#include <vector>

namespace lldb {
Expand Down
11 changes: 5 additions & 6 deletions src/llscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
namespace llnode {

using lldb::ByteOrder;
using lldb::eReturnStatusFailed;
using lldb::eReturnStatusSuccessFinishResult;
using lldb::SBCommandReturnObject;
using lldb::SBDebugger;
using lldb::SBError;
using lldb::SBExpressionOptions;
using lldb::SBStream;
using lldb::SBTarget;
using lldb::SBValue;
using lldb::eReturnStatusFailed;
using lldb::eReturnStatusSuccessFinishResult;


char** ParsePrinterOptions(char** cmd, Printer::PrinterOptions* options) {
Expand Down Expand Up @@ -261,10 +261,9 @@ bool FindInstancesCmd::DoExecute(SBDebugger d, char** cmd,
final_p_offset = pagination_.total_entries;
}

auto it =
pagination_.current_page == 0
? t->GetInstances().begin()
: std::next(t->GetInstances().begin(), initial_p_offset);
auto it = pagination_.current_page == 0
? t->GetInstances().begin()
: std::next(t->GetInstances().begin(), initial_p_offset);
for (; it != t->GetInstances().end() &&
it != (std::next(t->GetInstances().begin(), final_p_offset));
++it) {
Expand Down
2 changes: 1 addition & 1 deletion src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace llnode {
namespace v8 {
namespace constants {

using lldb::addr_t;
using lldb::SBAddress;
using lldb::SBError;
using lldb::SBProcess;
using lldb::SBSymbol;
using lldb::SBSymbolContext;
using lldb::SBSymbolContextList;
using lldb::SBTarget;
using lldb::addr_t;

void Module::Assign(SBTarget target, Common* common) {
loaded_ = false;
Expand Down
2 changes: 1 addition & 1 deletion src/llv8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
namespace llnode {
namespace v8 {

using lldb::addr_t;
using lldb::SBError;
using lldb::SBTarget;
using lldb::addr_t;

static std::string kConstantPrefix = "v8dbg_";

Expand Down