Skip to content

Commit

Permalink
chore(ci): add lint checks
Browse files Browse the repository at this point in the history
Refs: #742
  • Loading branch information
subzero10 authored Apr 24, 2022
1 parent 261668a commit 6ee86fb
Show file tree
Hide file tree
Showing 46 changed files with 357 additions and 305 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/bundle.js
19 changes: 16 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@
],
"parser": "@typescript-eslint/parser",
"rules": {
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"indent": ["error", 2],
"no-var": "error",
"object-curly-spacing": [
"error",
"always"
],
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-unused-vars": [
"error",
Expand All @@ -21,8 +34,7 @@
},
"ignorePatterns": [
"test/integration/",
"dist",
"examples"
"dist"
],
"plugins": [
"@typescript-eslint",
Expand All @@ -32,6 +44,7 @@
{
"browser": true,
"node": true,
"es6": true
"es6": true,
"webextensions": true
}
}
78 changes: 56 additions & 22 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,86 @@ on:

jobs:
unit:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
cache: 'npm'

integration:
- name: Build
run: npm ci

runs-on: ubuntu-latest
- name: Run unit tests
run: npm test

integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14.x'
- name: npm install, build, and test
cache: 'npm'
cache-dependency-path: |
package-lock.json
test/integration/package-lock.json
- name: Build
run: |
npm ci
cd test/integration
npm ci
npm test
- name: Run integration tests
env:
CI: true
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
run: npm run test:integration

tsd:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14.x'
- run: npm ci
- run: npm run tsd
cache: 'npm'

- name: Build
run: npm ci

- name: Check Typescript type definitions
run: npm run tsd

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14.x'
cache: 'npm'

- name: Build
run: npm ci

- name: Run lint checks
run: npm run lint
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']}
module.exports = { extends: ['@commitlint/config-conventional'] }
13 changes: 7 additions & 6 deletions examples/almond/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
console.log(arguments);
}
}
requirejs(["../../dist/browser/honeybadger"], function(Honeybadger) {
// eslint-disable-next-line no-undef
requirejs(['../../dist/browser/honeybadger'], function(Honeybadger) {
Honeybadger.configure({
apiKey: prompt("Enter the API key for your Honeybadger project:"),
apiKey: prompt('Enter the API key for your Honeybadger project:'),
debug: true
});
log("Attaching event");
document.getElementById('btn').addEventListener("click", function(){
log("Failing in event listener...");
throw new Error("This is a test error raised from an addEventListener callback.");
log('Attaching event');
document.getElementById('btn').addEventListener('click', function(){
log('Failing in event listener...');
throw new Error('This is a test error raised from an addEventListener callback.');
});
});
})();
18 changes: 9 additions & 9 deletions examples/aws-lambda/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ module.exports = {
syncError: honeybadgerWrapper(async (event) => {
const willReport = event.body && event.body.report === 'yes';
if (willReport) {
throw new Error("sync-error");
throw new Error('sync-error');
}

return formatJSONResponse({
message: `You summoned the sync-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
message: "You summoned the sync-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
event,
});
}),
asyncError: honeybadgerWrapper(async (event) => {
const asyncThatThrows = async (shouldThrow) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
(shouldThrow ? reject(new Error("async-error")): resolve())
(shouldThrow ? reject(new Error('async-error')): resolve())
}, 300);
});
}

const willReport = event.body && event.body.report === 'yes';
await asyncThatThrows(willReport);
return formatJSONResponse({
message: `You summoned the async-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
message: "You summoned the async-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
event,
});
}),
callbackError: honeybadgerWrapper((event, context, callback) => {
const willReport = event.body && event.body.report === 'yes';
if (willReport) {
callback(new Error("callback-error"));
callback(new Error('callback-error'));
return;
}

const resp = formatJSONResponse({
message: `You summoned the callback-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
message: "You summoned the callback-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
event,
});
callback(null, resp);
Expand All @@ -65,15 +65,15 @@ module.exports = {
}

const resp = formatJSONResponse({
message: `You summoned the set-timeout-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
message: "You summoned the setTimeout-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
event,
});
callback(null, resp);
}, 300);
}),
timeoutWarning: honeybadgerWrapper(async (event) => {
const asyncThatThrows = async (shouldTimeout) => {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
setTimeout(() => {
resolve()
}, shouldTimeout ? (1000 * 60 * 20) : 200) // 20 minutes
Expand All @@ -83,7 +83,7 @@ module.exports = {
const shouldTimeout = event.body && event.body.timeout === 'yes';
await asyncThatThrows(shouldTimeout);
return formatJSONResponse({
message: `You summoned the timeoutWarning handler! Nothing was sent to Honeybadger. POST with { 'body': { 'timeout': 'yes' } } to run the function until it times out.`,
message: "You summoned the timeoutWarning handler! Nothing was sent to Honeybadger. POST with { 'body': { 'timeout': 'yes' } } to run the function until it times out.",
event,
});
}),
Expand Down
16 changes: 8 additions & 8 deletions examples/browserify/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var hb = require('../../dist/browser/honeybadger');
let hb = require('../../dist/browser/honeybadger');
hb.configure({
apiKey: prompt("Enter the API key for your Honeybadger project:"),
apiKey: prompt('Enter the API key for your Honeybadger project:'),
debug: true
});

Expand All @@ -12,14 +12,14 @@ hb.configure({
}

window.onload = function(){
log("Attaching event");
document.getElementById('btn').addEventListener("click", function(){
log("Failing in event listener...");
throw new Error("This is a test error raised from an addEventListener callback.");
log('Attaching event');
document.getElementById('btn').addEventListener('click', function(){
log('Failing in event listener...');
throw new Error('This is a test error raised from an addEventListener callback.');
});

document.getElementById('btn-check-in').addEventListener("click", function(){
const checkInId = prompt("Enter check-in id:")
document.getElementById('btn-check-in').addEventListener('click', function(){
const checkInId = prompt('Enter check-in id:')
hb.checkIn(checkInId)
});
};
Expand Down
3 changes: 2 additions & 1 deletion examples/chrome-extension/error-reporting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line no-undef
Honeybadger.configure({
apiKey: 'YOUR_API_KEY',
environment: 'production'
});
});
17 changes: 9 additions & 8 deletions examples/chrome-extension/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let page = document.getElementById("buttonDiv");
let selectedClassName = "current";
const presetButtonColors = ["#3aa757", "#e8453c", "#f9bb2d", "#4688f1"];
let page = document.getElementById('buttonDiv');
let selectedClassName = 'current';
const presetButtonColors = ['#3aa757', '#e8453c', '#f9bb2d', '#4688f1'];

// Reacts to a button click by marking the selected button and saving
// the selection
Expand All @@ -21,12 +21,12 @@ function handleButtonClick(event) {

// Add a button to the page for each supplied color
function constructOptions(buttonColors) {
chrome.storage.sync.get("color", (data) => {
chrome.storage.sync.get('color', (data) => {
let currentColor = data.color;
// For each color we were provided…
for (let buttonColor of buttonColors) {
// …create a button with that color…
let button = document.createElement("button");
let button = document.createElement('button');
button.dataset.color = buttonColor;
button.style.backgroundColor = buttonColor;

Expand All @@ -36,19 +36,20 @@ function constructOptions(buttonColors) {
}

// …and register a listener for when that button is clicked
button.addEventListener("click", handleButtonClick);
button.addEventListener('click', handleButtonClick);
page.appendChild(button);
}
});
}

function setupReportErrorListener() {
const button = document.getElementById('reportErrorButton');
button.addEventListener("click", () => {
button.addEventListener('click', () => {
// eslint-disable-next-line no-undef
mySecondUndefinedFunction();
});
}

// Initialize the page by constructing the color options
constructOptions(presetButtonColors);
setupReportErrorListener();
setupReportErrorListener();
8 changes: 4 additions & 4 deletions examples/chrome-extension/popup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Initialize button with user's preferred color
let changeColor = document.getElementById("changeColor");
let changeColor = document.getElementById('changeColor');

chrome.storage.sync.get("color", ({ color }) => {
chrome.storage.sync.get('color', ({ color }) => {
changeColor.style.backgroundColor = color;
});

// When the button is clicked, inject setPageBackgroundColor into current page
changeColor.addEventListener("click", async () => {
changeColor.addEventListener('click', async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });

chrome.scripting.executeScript({
Expand All @@ -18,7 +18,7 @@ changeColor.addEventListener("click", async () => {
// The body of this function will be executed as a content script inside the
// current page
function setPageBackgroundColor() {
chrome.storage.sync.get("color", ({ color }) => {
chrome.storage.sync.get('color', ({ color }) => {
document.body.style.backgroundColor = color;
});
}
2 changes: 1 addition & 1 deletion examples/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ app.get('/', (req, res) => {
res.send('Hello World!')
})

app.get('/fail', (req, res) => {
app.get('/fail', (_req, _res) => {
Honeybadger.setContext({
local: 'true'
})
Expand Down
Loading

0 comments on commit 6ee86fb

Please sign in to comment.