From 16e821bd5b9921e03ffa0f6f6809255c378d5e8f Mon Sep 17 00:00:00 2001 From: Pavel Murygin Date: Wed, 15 Dec 2021 18:19:50 +0300 Subject: [PATCH] fix prettier and eslint issues --- .eslintrc.js | 2 +- .prettierignore | 5 ++++ package-lock.json | 19 ++++++++++++++ package.json | 1 + .../integration/compiler/compiler.spec.ts | 4 +-- src/__test__/integration/compiler/gen1.ts | 1 + src/__test__/integration/compiler/gen2.ts | 1 + src/__test__/integration/peer.spec.ts | 11 ++++---- src/__test__/unit/KeyPair.spec.ts | 3 ++- src/__test__/unit/builtInHandler.spec.ts | 25 ++++++++++--------- src/__test__/unit/compilerSupport.spec.ts | 1 + src/__test__/util.ts | 4 +-- 12 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 .prettierignore diff --git a/.eslintrc.js b/.eslintrc.js index c3098c76..26f67513 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,7 +14,7 @@ module.exports = { rules: { indent: ['off'], 'linebreak-style': ['error', 'unix'], - quotes: ['error', 'single', { avoidEscape: true }], + quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }], semi: ['error', 'always'], 'no-empty-function': 'off', '@typescript-eslint/no-empty-function': ['off'], diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..b0138262 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +docs +.github +.prettierrc.js +tsconfig.json +dist/ \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 17de508a..f5348f75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "eslint-plugin-simple-import-sort": "^7.0.0", "jest": "^26.6.3", "js-base64": "^3.7.2", + "prettier": "^2.5.1", "ts-jest": "^26.5.4", "typedoc": "^0.21.9", "typescript": "^4.0.0" @@ -7063,6 +7064,18 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", + "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/pretty-format": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", @@ -14778,6 +14791,12 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "prettier": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", + "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", + "dev": true + }, "pretty-format": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", diff --git a/package.json b/package.json index 0a7fff87..10d8fb3b 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "eslint-plugin-simple-import-sort": "^7.0.0", "jest": "^26.6.3", "js-base64": "^3.7.2", + "prettier": "^2.5.1", "ts-jest": "^26.5.4", "typedoc": "^0.21.9", "typescript": "^4.0.0" diff --git a/src/__test__/integration/compiler/compiler.spec.ts b/src/__test__/integration/compiler/compiler.spec.ts index 771867ca..ac34cff4 100644 --- a/src/__test__/integration/compiler/compiler.spec.ts +++ b/src/__test__/integration/compiler/compiler.spec.ts @@ -1,9 +1,9 @@ import { Fluence, FluencePeer } from '../../..'; +import { callFunction } from '../../../internal/compilerSupport/v2'; import { Particle } from '../../../internal/Particle'; +import { handleTimeout } from '../../../internal/utils'; import { registerHandlersHelper } from '../../util'; import { callMeBack, registerHelloWorld } from './gen1'; -import { callFunction } from '../../../internal/compilerSupport/v2'; -import { handleTimeout } from '../../../internal/utils'; describe('Compiler support infrastructure tests', () => { it('Compiled code for function should work', async () => { diff --git a/src/__test__/integration/compiler/gen1.ts b/src/__test__/integration/compiler/gen1.ts index 29677bb5..b1dbb4f8 100644 --- a/src/__test__/integration/compiler/gen1.ts +++ b/src/__test__/integration/compiler/gen1.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { ResultCodes, RequestFlow, RequestFlowBuilder, CallParams } from '../../../internal/compilerSupport/v1'; import { Fluence, FluencePeer } from '../../../index'; diff --git a/src/__test__/integration/compiler/gen2.ts b/src/__test__/integration/compiler/gen2.ts index 8e3f11aa..49db7b2a 100644 --- a/src/__test__/integration/compiler/gen2.ts +++ b/src/__test__/integration/compiler/gen2.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { CallParams, registerService, callFunction } from '../../../internal/compilerSupport/v2'; import { FluencePeer } from '../../../index'; diff --git a/src/__test__/integration/peer.spec.ts b/src/__test__/integration/peer.spec.ts index fe5e100f..358c33cf 100644 --- a/src/__test__/integration/peer.spec.ts +++ b/src/__test__/integration/peer.spec.ts @@ -1,8 +1,9 @@ import { Multiaddr } from 'multiaddr'; -import { nodes } from '../connection'; + import { Fluence, FluencePeer, setLogLevel } from '../../index'; -import { checkConnection, doNothing, handleTimeout } from '../../internal/utils'; import { Particle } from '../../internal/Particle'; +import { checkConnection, doNothing, handleTimeout } from '../../internal/utils'; +import { nodes } from '../connection'; import { registerHandlersHelper } from '../util'; const anotherPeer = new FluencePeer(); @@ -134,7 +135,7 @@ describe('Typescript usage suite', () => { it('check connection should work', async function () { await anotherPeer.start({ connectTo: nodes[0] }); - let isConnected = await checkConnection(anotherPeer); + const isConnected = await checkConnection(anotherPeer); expect(isConnected).toEqual(true); }); @@ -142,7 +143,7 @@ describe('Typescript usage suite', () => { it('check connection should work with ttl', async function () { await anotherPeer.start({ connectTo: nodes[0] }); - let isConnected = await checkConnection(anotherPeer, 10000); + const isConnected = await checkConnection(anotherPeer, 10000); expect(isConnected).toEqual(true); }); @@ -328,7 +329,7 @@ describe('Typescript usage suite', () => { // assert await expect(res).rejects.toMatchObject({ msg: expect.stringContaining( - `No handler has been registered for serviceId='incorrect' fnName='incorrect' args=''\"'`, + `No handler has been registered for serviceId='incorrect' fnName='incorrect' args=''"'`, ), instruction: 'call %init_peer_id% ("incorrect" "incorrect") [] res', }); diff --git a/src/__test__/unit/KeyPair.spec.ts b/src/__test__/unit/KeyPair.spec.ts index c4678ed3..78695800 100644 --- a/src/__test__/unit/KeyPair.spec.ts +++ b/src/__test__/unit/KeyPair.spec.ts @@ -1,5 +1,6 @@ -import * as bs58 from 'bs58'; import * as base64 from 'base64-js'; +import * as bs58 from 'bs58'; + import { KeyPair } from '../../internal/KeyPair'; describe('KeyPair tests', () => { diff --git a/src/__test__/unit/builtInHandler.spec.ts b/src/__test__/unit/builtInHandler.spec.ts index a8fe5ce1..fa6892c8 100644 --- a/src/__test__/unit/builtInHandler.spec.ts +++ b/src/__test__/unit/builtInHandler.spec.ts @@ -1,9 +1,10 @@ -import { CallServiceData } from '../../internal/commonTypes'; import each from 'jest-each'; -import { BuiltInServiceContext, builtInServices } from '../../internal/builtInServices'; -import { KeyPair } from '../../internal/KeyPair'; import { toUint8Array } from 'js-base64'; +import { BuiltInServiceContext, builtInServices } from '../../internal/builtInServices'; +import { CallServiceData } from '../../internal/commonTypes'; +import { KeyPair } from '../../internal/KeyPair'; + const key = '+cmeYlZKj+MfSa9dpHV+BmLPm6wq4inGlsPlQ1GvtPk='; const context = (async () => { @@ -49,17 +50,17 @@ describe('Tests for default handler', () => { ${'op'} | ${'concat'} | ${[]} | ${0} | ${[]} ${'op'} | ${'concat'} | ${[1, [1, 2], 1]} | ${1} | ${"All arguments of 'concat' must be arrays: arguments 0, 2 are not"} - ${'op'} | ${'string_to_b58'} | ${["test"]} | ${0} | ${"3yZe7d"} - ${'op'} | ${'string_to_b58'} | ${["test", 1]} | ${1} | ${"string_to_b58 accepts only one string argument"} + ${'op'} | ${'string_to_b58'} | ${['test']} | ${0} | ${'3yZe7d'} + ${'op'} | ${'string_to_b58'} | ${['test', 1]} | ${1} | ${'string_to_b58 accepts only one string argument'} - ${'op'} | ${'string_from_b58'} | ${["3yZe7d"]} | ${0} | ${"test"} - ${'op'} | ${'string_from_b58'} | ${["3yZe7d", 1]} | ${1} | ${"string_from_b58 accepts only one string argument"} + ${'op'} | ${'string_from_b58'} | ${['3yZe7d']} | ${0} | ${'test'} + ${'op'} | ${'string_from_b58'} | ${['3yZe7d', 1]} | ${1} | ${'string_from_b58 accepts only one string argument'} - ${'op'} | ${'bytes_to_b58'} | ${[[116, 101, 115, 116]]} | ${0} | ${"3yZe7d"} - ${'op'} | ${'bytes_to_b58'} | ${[[116, 101, 115, 116], 1]} | ${1} | ${"bytes_to_b58 accepts only single argument: array of numbers"} + ${'op'} | ${'bytes_to_b58'} | ${[[116, 101, 115, 116]]} | ${0} | ${'3yZe7d'} + ${'op'} | ${'bytes_to_b58'} | ${[[116, 101, 115, 116], 1]} | ${1} | ${'bytes_to_b58 accepts only single argument: array of numbers'} - ${'op'} | ${'bytes_from_b58'} | ${["3yZe7d"]} | ${0} | ${[116, 101, 115, 116]} - ${'op'} | ${'bytes_from_b58'} | ${["3yZe7d", 1]} | ${1} | ${"bytes_from_b58 accepts only one string argument"} + ${'op'} | ${'bytes_from_b58'} | ${['3yZe7d']} | ${0} | ${[116, 101, 115, 116]} + ${'op'} | ${'bytes_from_b58'} | ${['3yZe7d', 1]} | ${1} | ${'bytes_from_b58 accepts only one string argument'} ${'peer'} | ${'timeout'} | ${[200, []]} | ${0} | ${[]}} ${'peer'} | ${'timeout'} | ${[200, ['test']]} | ${0} | ${['test']}} @@ -249,7 +250,7 @@ describe('Tests for default handler', () => { // assert expect(res).toMatchObject({ retCode: 1, - result: expect.stringContaining("Only data from the following services is allowed to be signed:"), + result: expect.stringContaining('Only data from the following services is allowed to be signed:'), }); }); diff --git a/src/__test__/unit/compilerSupport.spec.ts b/src/__test__/unit/compilerSupport.spec.ts index a529ffb5..103bb8cf 100644 --- a/src/__test__/unit/compilerSupport.spec.ts +++ b/src/__test__/unit/compilerSupport.spec.ts @@ -1,4 +1,5 @@ import each from 'jest-each'; + import { Fluence, FluencePeer } from '../..'; import { forTests } from '../../internal/compilerSupport/v2'; diff --git a/src/__test__/util.ts b/src/__test__/util.ts index d7e3e895..5ded1547 100644 --- a/src/__test__/util.ts +++ b/src/__test__/util.ts @@ -3,8 +3,8 @@ import { Particle } from '../internal/Particle'; import { MakeServiceCall } from '../internal/utils'; export const registerHandlersHelper = (peer: FluencePeer, particle: Particle, handlers) => { - for (let serviceId in handlers) { - for (let fnName in handlers[serviceId]) { + for (const serviceId in handlers) { + for (const fnName in handlers[serviceId]) { // of type [args] => result const h = handlers[serviceId][fnName]; peer.internals.regHandler.forParticle(particle.id, serviceId, fnName, MakeServiceCall(h));