Skip to content

Commit 179fe0f

Browse files
authored
Update to @metamask/eslint-config@v6 (#21)
Update to the new ESLint config, which includes `prettier`. The lint scripts have been updated to match the `metamask-module-template`, and `yarn lint:fix` has been run to make any required lint changes. The one manual change required was to add an ESLint ignore comment in the test where the `dist` directory is imported. The ESLint config was updated to make TypeScript an override, which allowed re-enabling a few rules that had been disabled.
1 parent b225499 commit 179fe0f

File tree

8 files changed

+2646
-2496
lines changed

8 files changed

+2646
-2496
lines changed

.eslintrc.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,12 @@ module.exports = {
33
parserOptions: {
44
ecmaVersion: 2017,
55
},
6-
extends: [
7-
'@metamask/eslint-config',
8-
'@metamask/eslint-config/config/nodejs',
9-
'@metamask/eslint-config/config/typescript',
10-
],
11-
plugins: [
12-
'json',
13-
],
14-
overrides: [{
15-
files: [
16-
'*.js',
17-
'*.json',
18-
],
19-
parserOptions: {
20-
sourceType: 'script',
21-
},
22-
rules: {
23-
'@typescript-eslint/no-require-imports': 'off',
24-
'@typescript-eslint/no-var-requires': 'off',
6+
extends: ['@metamask/eslint-config', '@metamask/eslint-config-nodejs'],
7+
overrides: [
8+
{
9+
files: ['*.ts'],
10+
extends: ['@metamask/eslint-config-typescript'],
2511
},
26-
}],
27-
ignorePatterns: [
28-
'!eslintrc.js',
29-
'dist/',
30-
'node_modules/',
3112
],
13+
ignorePatterns: ['!eslintrc.js', 'dist/', 'node_modules/'],
3214
};

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ Simple stream multiplexing for `objectMode`.
66

77
```js
88
// create multiplexer
9-
const mux = new ObjMultiplex()
9+
const mux = new ObjMultiplex();
1010

1111
// setup substreams
12-
const streamA = mux.createStream('hello')
13-
const streamB = mux.createStream('world')
12+
const streamA = mux.createStream("hello");
13+
const streamB = mux.createStream("world");
1414

1515
// pipe over transport (and back)
16-
mux.pipe(transport).pipe(mux)
16+
mux.pipe(transport).pipe(mux);
1717

1818
// send values over the substreams
19-
streamA.write({ thisIsAn: 'object' })
20-
streamA.write(123)
19+
streamA.write({ thisIsAn: "object" });
20+
streamA.write(123);
2121

2222
// or pipe together normally
23-
streamB.pipe(evilAiBrain).pipe(streamB)
23+
streamB.pipe(evilAiBrain).pipe(streamB);
2424
```
2525

2626
## Contributing

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
"setup": "yarn install && yarn allow-scripts",
1818
"build:clean": "rimraf dist && yarn build",
1919
"build": "tsc --project .",
20-
"lint": "eslint . --ext ts,js,json",
21-
"lint:fix": "yarn lint --fix",
20+
"lint:eslint": "eslint . --cache --ext js,ts",
21+
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
22+
"lint": "yarn lint:eslint && yarn lint:misc --check",
23+
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
2224
"test": "yarn build && node test",
2325
"prepublishOnly": "yarn build:clean && yarn test"
2426
},
@@ -32,17 +34,21 @@
3234
"devDependencies": {
3335
"@lavamoat/allow-scripts": "^1.0.6",
3436
"@metamask/auto-changelog": "^2.3.0",
35-
"@metamask/eslint-config": "^4.1.0",
37+
"@metamask/eslint-config": "^6.0.0",
38+
"@metamask/eslint-config-nodejs": "^6.0.0",
39+
"@metamask/eslint-config-typescript": "^6.0.0",
3640
"@types/end-of-stream": "^1.4.0",
3741
"@types/node": "^14.14.9",
3842
"@types/once": "^1.4.0",
3943
"@types/readable-stream": "^2.3.9",
40-
"@typescript-eslint/eslint-plugin": "^4.8.2",
41-
"@typescript-eslint/parser": "^4.8.2",
42-
"eslint": "^7.14.0",
43-
"eslint-plugin-import": "^2.22.1",
44-
"eslint-plugin-json": "^2.1.2",
44+
"@typescript-eslint/eslint-plugin": "^4.26.0",
45+
"@typescript-eslint/parser": "^4.26.0",
46+
"eslint": "^7.27.0",
47+
"eslint-config-prettier": "^8.3.0",
48+
"eslint-plugin-import": "^2.23.4",
4549
"eslint-plugin-node": "^11.1.0",
50+
"eslint-plugin-prettier": "^3.4.0",
51+
"prettier": "^2.3.0",
4652
"pump": "^1.0.2",
4753
"rimraf": "^3.0.2",
4854
"tape": "^4.8.0",

src/ObjectMultiplex.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ interface Chunk {
1111
}
1212

1313
export class ObjectMultiplex extends Duplex {
14-
1514
private _substreams: Record<string, Substream | typeof IGNORE_SUBSTREAM>;
1615

1716
constructor(opts: Record<string, unknown> = {}) {
@@ -39,7 +38,9 @@ export class ObjectMultiplex extends Duplex {
3938
}
4039

4140
if (this._substreams[name]) {
42-
throw new Error(`ObjectMultiplex - Substream for name "${name}" already exists`);
41+
throw new Error(
42+
`ObjectMultiplex - Substream for name "${name}" already exists`,
43+
);
4344
}
4445

4546
// create substream
@@ -61,7 +62,9 @@ export class ObjectMultiplex extends Duplex {
6162
throw new Error('ObjectMultiplex - name must not be empty');
6263
}
6364
if (this._substreams[name]) {
64-
throw new Error(`ObjectMultiplex - Substream for name "${name}" already exists`);
65+
throw new Error(
66+
`ObjectMultiplex - Substream for name "${name}" already exists`,
67+
);
6568
}
6669
// set
6770
this._substreams[name] = IGNORE_SUBSTREAM;
@@ -76,7 +79,6 @@ export class ObjectMultiplex extends Duplex {
7679
_encoding: BufferEncoding,
7780
callback: (error?: Error | null) => void,
7881
): void {
79-
8082
const { name, data } = chunk;
8183

8284
if (!name) {
@@ -101,7 +103,10 @@ export class ObjectMultiplex extends Duplex {
101103
}
102104

103105
// util
104-
function anyStreamEnd(stream: ObjectMultiplex, _cb: (error?: Error | null) => void) {
106+
function anyStreamEnd(
107+
stream: ObjectMultiplex,
108+
_cb: (error?: Error | null) => void,
109+
) {
105110
const cb = once(_cb);
106111
eos(stream, { readable: false }, cb);
107112
eos(stream, { writable: false }, cb);

src/Substream.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export interface SubstreamOptions {
77
}
88

99
export class Substream extends Duplex {
10-
1110
private readonly _parent: ObjectMultiplex;
1211

1312
private readonly _name: string;

test/index.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ const test = require('tape');
22
const pump = require('pump');
33
const { PassThrough, Transform } = require('readable-stream');
44
const endOfStream = require('end-of-stream');
5+
// eslint-disable-next-line import/no-unresolved
56
const ObjMultiplex = require('../dist');
67

78
test('basic - string', (t) => {
89
t.plan(2);
910

10-
const {
11-
inTransport,
12-
inStream, outStream,
13-
} = basicTestSetup();
11+
const { inTransport, inStream, outStream } = basicTestSetup();
1412
bufferToEnd(outStream, (err, results) => {
1513
t.error(err, 'should not error');
1614
t.deepEqual(results, ['haay', 'wuurl'], 'results should match');
@@ -28,13 +26,14 @@ test('basic - string', (t) => {
2826
test('basic - obj', (t) => {
2927
t.plan(2);
3028

31-
const {
32-
inTransport,
33-
inStream, outStream,
34-
} = basicTestSetup();
29+
const { inTransport, inStream, outStream } = basicTestSetup();
3530
bufferToEnd(outStream, (err, results) => {
3631
t.error(err, 'should not error');
37-
t.deepEqual(results, [{ message: 'haay' }, { message: 'wuurl' }], 'results should match');
32+
t.deepEqual(
33+
results,
34+
[{ message: 'haay' }, { message: 'wuurl' }],
35+
'results should match',
36+
);
3837
t.end();
3938
});
4039
// pass in messages
@@ -48,10 +47,7 @@ test('basic - obj', (t) => {
4847
test('roundtrip', (t) => {
4948
t.plan(2);
5049

51-
const {
52-
outTransport,
53-
inStream, outStream,
54-
} = basicTestSetup();
50+
const { outTransport, inStream, outStream } = basicTestSetup();
5551
const doubler = new Transform({
5652
objectMode: true,
5753
transform(chunk, _end, callback) {
@@ -60,11 +56,7 @@ test('roundtrip', (t) => {
6056
},
6157
});
6258

63-
pump(
64-
outStream,
65-
doubler,
66-
outStream,
67-
);
59+
pump(outStream, doubler, outStream);
6860

6961
bufferToEnd(inStream, (err, results) => {
7062
t.error(err, 'should not error');
@@ -104,7 +96,6 @@ test('error on createStream if ended', (t) => {
10496
// util
10597

10698
function basicTestSetup() {
107-
10899
// setup multiplex and Transport
109100
const inMux = new ObjMultiplex();
110101
const outMux = new ObjMultiplex();
@@ -115,20 +106,16 @@ function basicTestSetup() {
115106
const inStream = inMux.createStream('hello');
116107
const outStream = outMux.createStream('hello');
117108

118-
pump(
119-
inMux,
109+
pump(inMux, inTransport, outMux, outTransport, inMux);
110+
111+
return {
120112
inTransport,
121-
outMux,
122113
outTransport,
123114
inMux,
124-
);
125-
126-
return {
127-
inTransport, outTransport,
128-
inMux, outMux,
129-
inStream, outStream,
115+
outMux,
116+
inStream,
117+
outStream,
130118
};
131-
132119
}
133120

134121
function bufferToEnd(stream, callback) {

tsconfig.json

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
{
2-
"compilerOptions": {
3-
"declaration": true,
4-
"esModuleInterop": true,
5-
"module": "CommonJS",
6-
"moduleResolution": "Node",
7-
"sourceMap": true,
8-
"strict": true,
9-
"target": "ES2017",
10-
"typeRoots": [
11-
"./node_modules/@types",
12-
],
13-
"outDir": "dist"
14-
},
15-
"include": [
16-
"src/**/*.ts"
17-
],
18-
"exclude": [
19-
"node_modules",
20-
"dist"
21-
]
22-
}
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"esModuleInterop": true,
5+
"module": "CommonJS",
6+
"moduleResolution": "Node",
7+
"sourceMap": true,
8+
"strict": true,
9+
"target": "ES2017",
10+
"typeRoots": ["./node_modules/@types"],
11+
"outDir": "dist"
12+
},
13+
"include": ["src/**/*.ts"],
14+
"exclude": ["node_modules", "dist"]
15+
}

0 commit comments

Comments
 (0)