Skip to content

Commit

Permalink
Lint chat files
Browse files Browse the repository at this point in the history
  • Loading branch information
D4nte committed Mar 29, 2021
1 parent 730176b commit 3b5b203
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.chat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": "./tsconfig.chat.json" },
"env": { "es6": true },
"ignorePatterns": ["node_modules", "build", "coverage", "proto", "src"],
"plugins": ["import", "eslint-comments", "functional"],
"extends": [
"eslint:recommended",
"plugin:eslint-comments/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"prettier",
"prettier/@typescript-eslint"
],
"globals": { "BigInt": true, "console": true, "WebAssembly": true },
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"eslint-comments/disable-enable-pair": [
"error",
{ "allowWholeFile": true }
],
"eslint-comments/no-unused-disable": "error",
"import/order": [
"error",
{ "newlines-between": "always", "alphabetize": { "order": "asc" } }
],
"sort-imports": [
"error",
{ "ignoreDeclarationSort": true, "ignoreCase": true }
]
}
}
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": "./tsconfig.json" },
"env": { "es6": true },
"ignorePatterns": ["node_modules", "build", "coverage", "proto"],
"ignorePatterns": ["node_modules", "build", "coverage", "proto", "chat"],
"plugins": ["import", "eslint-comments", "functional"],
"extends": [
"eslint:recommended",
Expand Down
19 changes: 9 additions & 10 deletions chat/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import readline from 'readline';

import Waku from '../build/main/lib/waku';
import { TOPIC } from '../build/main/lib/waku_relay';
import { Message } from '../build/main/lib/waku_message';

import readline from 'readline';
import { TOPIC } from '../build/main/lib/waku_relay';
import { delay } from '../build/main/test_utils/delay';

;(async function() {
(async function () {
const opts = processArguments();

const waku = await Waku.create({ listenAddresses: [opts.listenAddr] });

// TODO: Bubble event to waku, infere topic, decode msg
waku.libp2p.pubsub.on(TOPIC, event => {
waku.libp2p.pubsub.on(TOPIC, (event) => {
const msg = Message.fromBinary(event.data);
console.log(msg.utf8Payload());
});
Expand Down Expand Up @@ -40,7 +40,7 @@ import { delay } from '../build/main/test_utils/delay';

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
});

console.log('Ready to chat!');
Expand All @@ -50,7 +50,6 @@ import { delay } from '../build/main/test_utils/delay';
const msg = Message.fromUtf8String('(js-chat) ' + line);
await waku.relay.publish(msg);
});

})();

interface Options {
Expand All @@ -59,9 +58,9 @@ interface Options {
}

function processArguments(): Options {
let passedArgs = process.argv.slice(2);
const passedArgs = process.argv.slice(2);

let opts: Options = {listenAddr: '/ip4/0.0.0.0/tcp/0'};
let opts: Options = { listenAddr: '/ip4/0.0.0.0/tcp/0' };

while (passedArgs.length) {
const arg = passedArgs.shift();
Expand All @@ -74,7 +73,7 @@ function processArguments(): Options {
break;
default:
console.log(`Unsupported argument: ${arg}`);
process.exit(1)
process.exit(1);
}
}

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
"build:chat": "tsc -p tsconfig.chat.json",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:chat:prettier": "prettier \"chat/**/*.ts\" --write",
"fix:lint": "eslint src --ext .ts --fix",
"fix:chat:lint": "eslint chat --ext .ts --fix --no-eslintrc --config .eslintrc.chat.json",
"pretest": "run-s pretest:*",
"pretest:1-init-git-submodules": "[ -f './nim-waku/build/wakunode2' ] || git submodule update --init --recursive",
"pretest:2-build-nim-waku": "cd nim-waku; [ -f './build/wakunode2' ] || make -j$(nproc --all 2>/dev/null || echo 2) wakunode2",
"start-chat": "ts-node chat/index.ts",
"chat:start": "ts-node chat/index.ts",
"test": "run-s build test:*",
"test:lint": "eslint src --ext .ts",
"test:lint-chat": "eslint chat --ext .ts --no-eslintrc --concig .eslintrc.chat.json",
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
"test:chat:prettier": "prettier \"src/**/*.ts\" --list-different",
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
"test:unit": "nyc --silent mocha --exit # TODO: Remove `--exit` and fix hanging processes",
"test:lint-proto": "buf lint",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"types": ["node", "mocha"],
"typeRoots": ["node_modules/@types"]
},
"include": ["chat/**/*.ts"],
"include": ["chat/**/*.ts", "chat/*.ts"],
"exclude": ["node_modules/**"],
"compileOnSave": false,
"ts-node": {
Expand Down

0 comments on commit 3b5b203

Please sign in to comment.