diff --git a/.eslintrc.chat.json b/.eslintrc.chat.json new file mode 100644 index 0000000000..c600aac007 --- /dev/null +++ b/.eslintrc.chat.json @@ -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 } + ] + } +} diff --git a/.eslintrc.json b/.eslintrc.json index 67d7fd21d7..08bed2ca21 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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", diff --git a/chat/index.ts b/chat/index.ts index 3b21e418bf..c53aff597d 100644 --- a/chat/index.ts +++ b/chat/index.ts @@ -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()); }); @@ -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!'); @@ -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 { @@ -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(); @@ -74,7 +73,7 @@ function processArguments(): Options { break; default: console.log(`Unsupported argument: ${arg}`); - process.exit(1) + process.exit(1); } } diff --git a/package.json b/package.json index 8829b8b5e6..19cc6525ae 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tsconfig.chat.json b/tsconfig.chat.json index 7a9b8796f6..68d92932cb 100644 --- a/tsconfig.chat.json +++ b/tsconfig.chat.json @@ -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": {