Skip to content

Commit

Permalink
add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed May 8, 2024
1 parent cbf4222 commit 2e92458
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ jobs:
node-version: 20.6.1
- run: npm run limits

linter:
name: Code Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 20.6.1
- run: npm run lint

package-report:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ test/
test.sh
.github/
limitation.js
eslint*
*.sw?
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import globals from "globals";
import pluginJs from "@eslint/js";

export default [
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: globals.node }},
pluginJs.configs.recommended,
{rules: {
"semi": "error",
}}
];
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dc-polyfill.js",
"scripts": {
"test": "./test.sh",
"lint": "eslint .",
"limits": "./limitation.js"
},
"keywords": [
Expand All @@ -25,6 +26,9 @@
"url": "https://github.com/DataDog/dc-polyfill/issues"
},
"devDependencies": {
"@eslint/js": "^9.2.0",
"eslint": "^9.2.0",
"globals": "^15.1.0",
"tape": "^5.6.6"
},
"limits": {
Expand Down
1 change: 0 additions & 1 deletion patch-channel-unsubscribe-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = function (unpatched) {
const channels = new WeakSet();

const dc_channel = unpatched.channel;
const dc_Channel = unpatched.Channel;

const dc = { ...unpatched };

Expand Down
3 changes: 1 addition & 2 deletions reimplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {
* It has been extended to support a global, cross-package-instance registry of channels
*/

const util = require('util');
const { ERR_INVALID_ARG_TYPE } = require('./errors.js');

const channels = require('./acquire-channel-registry.js');
Expand All @@ -32,7 +31,7 @@ class ActiveChannel {

// When there are no more active subscribers, restore to fast prototype.
if (!this._subscribers.length) {
// eslint-disable-next-line no-use-before-define
ObjectSetPrototypeOf(this, Channel.prototype);
}

Expand Down
4 changes: 2 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function getCallSite(top) {
const err = new Error();
Error.captureStackTrace(err, top);
// With the V8 Error API, the stack is not formatted until it is accessed
err.stack; // eslint-disable-line no-unused-expressions
err.stack;
Error.prepareStackTrace = originalStackFormatter;
return err.stack;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ function _mustCallInner(fn, criteria = 1, field) {

mustCallChecks.push(context);

const _return = function() { // eslint-disable-line func-style
const _return = function() {
context.actual++;
return fn.apply(this, arguments);
};
Expand Down
3 changes: 1 addition & 2 deletions test/shared-channel-registry.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const path = require('path');
const test = require('tape');
const common = require('./common.js');
const checks = require('../checks.js');
Expand Down Expand Up @@ -33,7 +32,7 @@ test('shared-channel-registry', (t) => {

dc_v1.subscribe('foo', common.mustCall(function(msg) {
t.equal(msg, 'bar');
}))
}));

dc_v2.channel('foo').publish('bar');
});
3 changes: 1 addition & 2 deletions test/test-diagnostics-channel-has-subscribers.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const assert = require('assert');
const test = require('tape');

const { channel, hasSubscribers } = require('../dc-polyfill.js');
Expand All @@ -14,7 +13,7 @@ test('test-diagnostics-channel-has-subscribers', t => {
// TypeError: WeakRefPrototypeGet is not a function
t.comment('SKIPPING TEST DUE TO A BUG IN THIS VERSION OF NODE.JS');
t.end();
return
return;
}

const dc = channel('test-diagnostics-channel-has-subscribers');
Expand Down
1 change: 0 additions & 1 deletion test/test-diagnostics-channel-memory-leak.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This test ensures that diagnostic channel references aren't leaked.

const test = require('tape');
const common = require('./common.js');
const { subscribe, unsubscribe } = require('../dc-polyfill.js');

const v8 = require('v8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('test-diagnostics-channel-http', (t) => {
t.strictEqual(err, error);
}));

channel.subscribe(common.mustCall((message, name) => {
channel.subscribe(common.mustCall(() => {
throw error;
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const test = require('tape');
const common = require('./common.js');
const dc = require('../dc-polyfill.js');
const { MAJOR, MINOR } = require('../checks.js');
const { MAJOR } = require('../checks.js');

test('test-diagnostics-channel-tracing-channel-async', (t) => {
t.plan(23);
Expand Down
2 changes: 1 addition & 1 deletion test/test-diagnostics-channel-worker-threads.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const test = require('tape');
const common = require('./common.js');
const dc = require('../dc-polyfill.js');
const { Worker } = require('worker_threads');
const { MAJOR, MINOR } = require('../checks.js');
const { MAJOR } = require('../checks.js');

// This test depends on features only available in certain versions of Node.js
if (MAJOR < 19) return;
Expand Down

0 comments on commit 2e92458

Please sign in to comment.