Skip to content

Commit 6ee86fb

Browse files
authored
chore(ci): add lint checks
Refs: #742
1 parent 261668a commit 6ee86fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+357
-305
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/bundle.js

.eslintrc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@
1010
],
1111
"parser": "@typescript-eslint/parser",
1212
"rules": {
13+
"quotes": [
14+
"error",
15+
"single",
16+
{
17+
"avoidEscape": true
18+
}
19+
],
1320
"indent": ["error", 2],
21+
"no-var": "error",
22+
"object-curly-spacing": [
23+
"error",
24+
"always"
25+
],
26+
"@typescript-eslint/no-var-requires": 0,
1427
"@typescript-eslint/ban-ts-comment": 0,
1528
"@typescript-eslint/no-unused-vars": [
1629
"error",
@@ -21,8 +34,7 @@
2134
},
2235
"ignorePatterns": [
2336
"test/integration/",
24-
"dist",
25-
"examples"
37+
"dist"
2638
],
2739
"plugins": [
2840
"@typescript-eslint",
@@ -32,6 +44,7 @@
3244
{
3345
"browser": true,
3446
"node": true,
35-
"es6": true
47+
"es6": true,
48+
"webextensions": true
3649
}
3750
}

.github/workflows/node.js.yml

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,86 @@ on:
88

99
jobs:
1010
unit:
11-
1211
runs-on: ubuntu-latest
13-
1412
strategy:
1513
matrix:
1614
node-version: [12.x, 14.x, 16.x]
17-
1815
steps:
19-
- uses: actions/checkout@v2
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v1
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Setup Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v3
2221
with:
2322
node-version: ${{ matrix.node-version }}
24-
- run: npm ci
25-
- run: npm test
23+
cache: 'npm'
2624

27-
integration:
25+
- name: Build
26+
run: npm ci
2827

29-
runs-on: ubuntu-latest
28+
- name: Run unit tests
29+
run: npm test
3030

31+
integration:
32+
runs-on: ubuntu-latest
3133
steps:
32-
- uses: actions/checkout@v2
33-
- name: Use Node.js
34-
uses: actions/setup-node@v1
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
37+
- name: Setup Node.js
38+
uses: actions/setup-node@v3
3539
with:
3640
node-version: '14.x'
37-
- name: npm install, build, and test
41+
cache: 'npm'
42+
cache-dependency-path: |
43+
package-lock.json
44+
test/integration/package-lock.json
45+
46+
- name: Build
3847
run: |
3948
npm ci
4049
cd test/integration
4150
npm ci
42-
npm test
51+
52+
- name: Run integration tests
4353
env:
4454
CI: true
4555
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
4656
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
57+
run: npm run test:integration
4758

4859
tsd:
49-
5060
runs-on: ubuntu-latest
51-
5261
steps:
53-
- uses: actions/checkout@v2
54-
- name: Use Node.js
55-
uses: actions/setup-node@v1
62+
- name: Checkout
63+
uses: actions/checkout@v3
64+
65+
- name: Setup Node.js
66+
uses: actions/setup-node@v3
5667
with:
5768
node-version: '14.x'
58-
- run: npm ci
59-
- run: npm run tsd
69+
cache: 'npm'
70+
71+
- name: Build
72+
run: npm ci
73+
74+
- name: Check Typescript type definitions
75+
run: npm run tsd
76+
77+
lint:
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v3
82+
83+
- name: Setup Node.js
84+
uses: actions/setup-node@v3
85+
with:
86+
node-version: '14.x'
87+
cache: 'npm'
88+
89+
- name: Build
90+
run: npm ci
91+
92+
- name: Run lint checks
93+
run: npm run lint

commitlint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = {extends: ['@commitlint/config-conventional']}
1+
module.exports = { extends: ['@commitlint/config-conventional'] }

examples/almond/main.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
console.log(arguments);
55
}
66
}
7-
requirejs(["../../dist/browser/honeybadger"], function(Honeybadger) {
7+
// eslint-disable-next-line no-undef
8+
requirejs(['../../dist/browser/honeybadger'], function(Honeybadger) {
89
Honeybadger.configure({
9-
apiKey: prompt("Enter the API key for your Honeybadger project:"),
10+
apiKey: prompt('Enter the API key for your Honeybadger project:'),
1011
debug: true
1112
});
12-
log("Attaching event");
13-
document.getElementById('btn').addEventListener("click", function(){
14-
log("Failing in event listener...");
15-
throw new Error("This is a test error raised from an addEventListener callback.");
13+
log('Attaching event');
14+
document.getElementById('btn').addEventListener('click', function(){
15+
log('Failing in event listener...');
16+
throw new Error('This is a test error raised from an addEventListener callback.');
1617
});
1718
});
1819
})();

examples/aws-lambda/handler.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,39 @@ module.exports = {
2020
syncError: honeybadgerWrapper(async (event) => {
2121
const willReport = event.body && event.body.report === 'yes';
2222
if (willReport) {
23-
throw new Error("sync-error");
23+
throw new Error('sync-error');
2424
}
2525

2626
return formatJSONResponse({
27-
message: `You summoned the sync-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
27+
message: "You summoned the sync-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
2828
event,
2929
});
3030
}),
3131
asyncError: honeybadgerWrapper(async (event) => {
3232
const asyncThatThrows = async (shouldThrow) => {
3333
return new Promise((resolve, reject) => {
3434
setTimeout(() => {
35-
(shouldThrow ? reject(new Error("async-error")): resolve())
35+
(shouldThrow ? reject(new Error('async-error')): resolve())
3636
}, 300);
3737
});
3838
}
3939

4040
const willReport = event.body && event.body.report === 'yes';
4141
await asyncThatThrows(willReport);
4242
return formatJSONResponse({
43-
message: `You summoned the async-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
43+
message: "You summoned the async-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
4444
event,
4545
});
4646
}),
4747
callbackError: honeybadgerWrapper((event, context, callback) => {
4848
const willReport = event.body && event.body.report === 'yes';
4949
if (willReport) {
50-
callback(new Error("callback-error"));
50+
callback(new Error('callback-error'));
5151
return;
5252
}
5353

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

6767
const resp = formatJSONResponse({
68-
message: `You summoned the set-timeout-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.`,
68+
message: "You summoned the setTimeout-error handler! Nothing was sent to Honeybadger. POST with { 'body': { 'report': 'yes' } } to report to Honeybadger.",
6969
event,
7070
});
7171
callback(null, resp);
7272
}, 300);
7373
}),
7474
timeoutWarning: honeybadgerWrapper(async (event) => {
7575
const asyncThatThrows = async (shouldTimeout) => {
76-
return new Promise((resolve, reject) => {
76+
return new Promise((resolve, _reject) => {
7777
setTimeout(() => {
7878
resolve()
7979
}, shouldTimeout ? (1000 * 60 * 20) : 200) // 20 minutes
@@ -83,7 +83,7 @@ module.exports = {
8383
const shouldTimeout = event.body && event.body.timeout === 'yes';
8484
await asyncThatThrows(shouldTimeout);
8585
return formatJSONResponse({
86-
message: `You summoned the timeoutWarning handler! Nothing was sent to Honeybadger. POST with { 'body': { 'timeout': 'yes' } } to run the function until it times out.`,
86+
message: "You summoned the timeoutWarning handler! Nothing was sent to Honeybadger. POST with { 'body': { 'timeout': 'yes' } } to run the function until it times out.",
8787
event,
8888
});
8989
}),

examples/browserify/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var hb = require('../../dist/browser/honeybadger');
1+
let hb = require('../../dist/browser/honeybadger');
22
hb.configure({
3-
apiKey: prompt("Enter the API key for your Honeybadger project:"),
3+
apiKey: prompt('Enter the API key for your Honeybadger project:'),
44
debug: true
55
});
66

@@ -12,14 +12,14 @@ hb.configure({
1212
}
1313

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

21-
document.getElementById('btn-check-in').addEventListener("click", function(){
22-
const checkInId = prompt("Enter check-in id:")
21+
document.getElementById('btn-check-in').addEventListener('click', function(){
22+
const checkInId = prompt('Enter check-in id:')
2323
hb.checkIn(checkInId)
2424
});
2525
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
// eslint-disable-next-line no-undef
12
Honeybadger.configure({
23
apiKey: 'YOUR_API_KEY',
34
environment: 'production'
4-
});
5+
});

examples/chrome-extension/options.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
let page = document.getElementById("buttonDiv");
2-
let selectedClassName = "current";
3-
const presetButtonColors = ["#3aa757", "#e8453c", "#f9bb2d", "#4688f1"];
1+
let page = document.getElementById('buttonDiv');
2+
let selectedClassName = 'current';
3+
const presetButtonColors = ['#3aa757', '#e8453c', '#f9bb2d', '#4688f1'];
44

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

2222
// Add a button to the page for each supplied color
2323
function constructOptions(buttonColors) {
24-
chrome.storage.sync.get("color", (data) => {
24+
chrome.storage.sync.get('color', (data) => {
2525
let currentColor = data.color;
2626
// For each color we were provided…
2727
for (let buttonColor of buttonColors) {
2828
// …create a button with that color…
29-
let button = document.createElement("button");
29+
let button = document.createElement('button');
3030
button.dataset.color = buttonColor;
3131
button.style.backgroundColor = buttonColor;
3232

@@ -36,19 +36,20 @@ function constructOptions(buttonColors) {
3636
}
3737

3838
// …and register a listener for when that button is clicked
39-
button.addEventListener("click", handleButtonClick);
39+
button.addEventListener('click', handleButtonClick);
4040
page.appendChild(button);
4141
}
4242
});
4343
}
4444

4545
function setupReportErrorListener() {
4646
const button = document.getElementById('reportErrorButton');
47-
button.addEventListener("click", () => {
47+
button.addEventListener('click', () => {
48+
// eslint-disable-next-line no-undef
4849
mySecondUndefinedFunction();
4950
});
5051
}
5152

5253
// Initialize the page by constructing the color options
5354
constructOptions(presetButtonColors);
54-
setupReportErrorListener();
55+
setupReportErrorListener();

examples/chrome-extension/popup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Initialize button with user's preferred color
2-
let changeColor = document.getElementById("changeColor");
2+
let changeColor = document.getElementById('changeColor');
33

4-
chrome.storage.sync.get("color", ({ color }) => {
4+
chrome.storage.sync.get('color', ({ color }) => {
55
changeColor.style.backgroundColor = color;
66
});
77

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

1212
chrome.scripting.executeScript({
@@ -18,7 +18,7 @@ changeColor.addEventListener("click", async () => {
1818
// The body of this function will be executed as a content script inside the
1919
// current page
2020
function setPageBackgroundColor() {
21-
chrome.storage.sync.get("color", ({ color }) => {
21+
chrome.storage.sync.get('color', ({ color }) => {
2222
document.body.style.backgroundColor = color;
2323
});
2424
}

examples/express/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ app.get('/', (req, res) => {
2121
res.send('Hello World!')
2222
})
2323

24-
app.get('/fail', (req, res) => {
24+
app.get('/fail', (_req, _res) => {
2525
Honeybadger.setContext({
2626
local: 'true'
2727
})

0 commit comments

Comments
 (0)