Skip to content

Commit

Permalink
ci: add eslint + prettier
Browse files Browse the repository at this point in the history
Signed-off-by: Till Sanders <[email protected]>
  • Loading branch information
tillsanders committed Mar 21, 2024
1 parent b2d3a4b commit eb6b351
Show file tree
Hide file tree
Showing 23 changed files with 2,699 additions and 1,006 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github
dist
coverage
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {}
}
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ jobs:
node-version: 20
- name: Install
run: npm ci
- name: Test
run: npm test
- name: Run tests
run: npx vitest run --coverage
- name: Run linting
run: npm run lint
- name: Check formatting
run: npx prettier . --check
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/
coverage/
dist/
.tern-port
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github
dist
coverage
package.json
package-lock.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $ npm install --save esm-itter
After installation the only thing you need to do is import the module:

```js
import { ESMitter } from 'esm-itter'
import { ESMitter } from "esm-itter";
```

### Tests and benchmarks
Expand Down
111 changes: 60 additions & 51 deletions benchmarks/run/add-remove.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,69 @@
'use strict';
"use strict";

var benchmark = require('benchmark');
import { Suite } from "benchmark";

var EventEmitter2 = require('eventemitter2').EventEmitter2
, EventEmitter1 = require('events').EventEmitter
, EventEmitter3 = require('eventemitter3')
, Drip = require('drip').EventEmitter
, CE = require('contra/emitter')
, EE = require('event-emitter')
, FE = require('fastemitter')
import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import EE from "event-emitter";
import FE from "fastemitter";

import('../../dist/index.js').then((ESMitter) => {
import("../../dist/index.js").then((ESMitter) => {
const Master = ESMitter.ESMitter;

function handle() {
if (arguments.length > 100) console.log('damn');
if (arguments.length > 100) console.log("damn");
}

var ee1 = new EventEmitter1()
, ee2 = new EventEmitter2()
, ee3 = new EventEmitter3()
, master = new Master()
, drip = new Drip()
, fe = new FE()
, ce = CE()
, ee = EE();
var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
ee3 = new EventEmitter3(),
master = new Master(),
drip = new Drip(),
fe = new FE(),
ce = CE(),
ee = EE();

(
new benchmark.Suite()
).add('EventEmitter1', function() {
ee1.on('foo', handle);
ee1.removeListener('foo', handle);
}).add('EventEmitter2', function() {
ee2.on('foo', handle);
ee2.removeListener('foo', handle);
}).add('[email protected]', function() {
ee3.on('foo', handle);
ee3.removeListener('foo', handle);
}).add('ESMitter(main)', function() {
master.on('foo', handle);
master.removeListener('foo', handle);
}).add('Drip', function() {
drip.on('foo', handle);
drip.removeListener('foo', handle);
}).add('fastemitter', function() {
fe.on('foo', handle);
fe.removeListener('foo', handle);
}).add('event-emitter', function() {
ee.on('foo', handle);
ee.off('foo', handle);
}).add('contra/emitter', function() {
ce.on('foo', handle);
ce.off('foo', handle);
}).on('cycle', function cycle(e) {
console.log(e.target.toString());
}).on('complete', function completed() {
console.log('Fastest is %s', this.filter('fastest').map('name'));
}).run({ async: true });
});
new Suite()
.add("EventEmitter1", function () {
ee1.on("foo", handle);
ee1.removeListener("foo", handle);
})
.add("EventEmitter2", function () {
ee2.on("foo", handle);
ee2.removeListener("foo", handle);
})
.add("[email protected]", function () {
ee3.on("foo", handle);
ee3.removeListener("foo", handle);
})
.add("ESMitter(main)", function () {
master.on("foo", handle);
master.removeListener("foo", handle);
})
.add("Drip", function () {
drip.on("foo", handle);
drip.removeListener("foo", handle);
})
.add("fastemitter", function () {
fe.on("foo", handle);
fe.removeListener("foo", handle);
})
.add("event-emitter", function () {
ee.on("foo", handle);
ee.off("foo", handle);
})
.add("contra/emitter", function () {
ce.on("foo", handle);
ce.off("foo", handle);
})
.on("cycle", function cycle(e) {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
})
.run({ async: true });
});
159 changes: 84 additions & 75 deletions benchmarks/run/context.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,96 @@
'use strict';
"use strict";

var benchmark = require('benchmark');
import { Suite } from "benchmark";

var EventEmitter2 = require('eventemitter2').EventEmitter2
, EventEmitter1 = require('events').EventEmitter
, EventEmitter3 = require('eventemitter3')
, Drip = require('drip').EventEmitter
, CE = require('contra/emitter')
, EE = require('event-emitter')
, FE = require('fastemitter')
import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import EE from "event-emitter";
import FE from "fastemitter";

import('../../dist/index.js').then((ESMitter) => {
import("../../dist/index.js").then((ESMitter) => {
const Master = ESMitter.ESMitter;

var ctx = { foo: 'bar' };
var ctx = { foo: "bar" };

function handle() {
if (arguments.length > 100) console.log('damn');
if (arguments.length > 100) console.log("damn");
}

var ee1 = new EventEmitter1()
, ee2 = new EventEmitter2()
, ee3 = new EventEmitter3()
, master = new Master()
, drip = new Drip()
, fe = new FE()
, ce = CE()
, ee = EE();
var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
ee3 = new EventEmitter3(),
master = new Master(),
drip = new Drip(),
fe = new FE(),
ce = CE(),
ee = EE();

ee3.on('foo', handle, ctx);
ee2.on('foo', handle.bind(ctx));
ee1.on('foo', handle.bind(ctx));
drip.on('foo', handle.bind(ctx));
master.on('foo', handle, ctx);
ee.on('foo', handle.bind(ctx));
fe.on('foo', handle.bind(ctx));
ce.on('foo', handle.bind(ctx));
ee3.on("foo", handle, ctx);
ee2.on("foo", handle.bind(ctx));
ee1.on("foo", handle.bind(ctx));
drip.on("foo", handle.bind(ctx));
master.on("foo", handle, ctx);
ee.on("foo", handle.bind(ctx));
fe.on("foo", handle.bind(ctx));
ce.on("foo", handle.bind(ctx));

(
new benchmark.Suite()
).add('EventEmitter1', function() {
ee1.emit('foo');
ee1.emit('foo', 'bar');
ee1.emit('foo', 'bar', 'baz');
ee1.emit('foo', 'bar', 'baz', 'boom');
}).add('EventEmitter2', function() {
ee2.emit('foo');
ee2.emit('foo', 'bar');
ee2.emit('foo', 'bar', 'baz');
ee2.emit('foo', 'bar', 'baz', 'boom');
}).add('[email protected]', function() {
ee3.emit('foo');
ee3.emit('foo', 'bar');
ee3.emit('foo', 'bar', 'baz');
ee3.emit('foo', 'bar', 'baz', 'boom');
}).add('ESMitter(main)', function() {
master.emit('foo');
master.emit('foo', 'bar');
master.emit('foo', 'bar', 'baz');
master.emit('foo', 'bar', 'baz', 'boom');
}).add('Drip', function() {
drip.emit('foo');
drip.emit('foo', 'bar');
drip.emit('foo', 'bar', 'baz');
drip.emit('foo', 'bar', 'baz', 'boom');
}).add('fastemitter', function() {
fe.emit('foo');
fe.emit('foo', 'bar');
fe.emit('foo', 'bar', 'baz');
fe.emit('foo', 'bar', 'baz', 'boom');
}).add('event-emitter', function() {
ee.emit('foo');
ee.emit('foo', 'bar');
ee.emit('foo', 'bar', 'baz');
ee.emit('foo', 'bar', 'baz', 'boom');
}).add('contra/emitter', function() {
ce.emit('foo');
ce.emit('foo', 'bar');
ce.emit('foo', 'bar', 'baz');
ce.emit('foo', 'bar', 'baz', 'boom');
}).on('cycle', function cycle(e) {
console.log(e.target.toString());
}).on('complete', function completed() {
console.log('Fastest is %s', this.filter('fastest').map('name'));
}).run({ async: true });
new Suite()
.add("EventEmitter1", function () {
ee1.emit("foo");
ee1.emit("foo", "bar");
ee1.emit("foo", "bar", "baz");
ee1.emit("foo", "bar", "baz", "boom");
})
.add("EventEmitter2", function () {
ee2.emit("foo");
ee2.emit("foo", "bar");
ee2.emit("foo", "bar", "baz");
ee2.emit("foo", "bar", "baz", "boom");
})
.add("[email protected]", function () {
ee3.emit("foo");
ee3.emit("foo", "bar");
ee3.emit("foo", "bar", "baz");
ee3.emit("foo", "bar", "baz", "boom");
})
.add("ESMitter(main)", function () {
master.emit("foo");
master.emit("foo", "bar");
master.emit("foo", "bar", "baz");
master.emit("foo", "bar", "baz", "boom");
})
.add("Drip", function () {
drip.emit("foo");
drip.emit("foo", "bar");
drip.emit("foo", "bar", "baz");
drip.emit("foo", "bar", "baz", "boom");
})
.add("fastemitter", function () {
fe.emit("foo");
fe.emit("foo", "bar");
fe.emit("foo", "bar", "baz");
fe.emit("foo", "bar", "baz", "boom");
})
.add("event-emitter", function () {
ee.emit("foo");
ee.emit("foo", "bar");
ee.emit("foo", "bar", "baz");
ee.emit("foo", "bar", "baz", "boom");
})
.add("contra/emitter", function () {
ce.emit("foo");
ce.emit("foo", "bar");
ce.emit("foo", "bar", "baz");
ce.emit("foo", "bar", "baz", "boom");
})
.on("cycle", function cycle(e) {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
})
.run({ async: true });
});
Loading

0 comments on commit eb6b351

Please sign in to comment.