Browse Source

ts, travis: Run prettier (#525)

Armani Ferrante 4 years ago
parent
commit
2c80042ef5

+ 3 - 1
.travis.yml

@@ -44,7 +44,9 @@ jobs:
         - cargo fmt -- --check
         - cargo fmt -- --check
         - cargo clippy --all-targets -- -D warnings
         - cargo clippy --all-targets -- -D warnings
         - cargo test
         - cargo test
-        - pushd ts && yarn && yarn test && popd
+        - pushd ts && yarn && popd
+        - pushd ts && yarn test && popd
+        - pushd ts && yarn lint && popd
     - <<: *examples
     - <<: *examples
       name: Runs the examples 1
       name: Runs the examples 1
       script:
       script:

+ 2 - 1
ts/package.json

@@ -15,7 +15,8 @@
   "scripts": {
   "scripts": {
     "build": "rm -rf dist/ && yarn build:node",
     "build": "rm -rf dist/ && yarn build:node",
     "build:node": "tsc && tsc -p tsconfig.cjs.json",
     "build:node": "tsc && tsc -p tsconfig.cjs.json",
-    "lint:fix": "prettier src/** -w",
+    "lint:fix": "prettier src/** tests/** -w",
+    "lint": "prettier src/** tests/** --check",
     "watch": "tsc -p tsconfig.cjs.json --watch",
     "watch": "tsc -p tsconfig.cjs.json --watch",
     "prepublishOnly": "yarn build",
     "prepublishOnly": "yarn build",
     "docs": "typedoc --excludePrivate --includeVersion --out ../docs/src/.vuepress/dist/ts/ --readme none src/index.ts",
     "docs": "typedoc --excludePrivate --includeVersion --out ../docs/src/.vuepress/dist/ts/ --readme none src/index.ts",

+ 1 - 1
ts/src/coder/event.ts

@@ -51,7 +51,7 @@ export class EventCoder {
     // This will throw if log length is not a multiple of 4.
     // This will throw if log length is not a multiple of 4.
     try {
     try {
       logArr = Buffer.from(base64.toByteArray(log));
       logArr = Buffer.from(base64.toByteArray(log));
-    } catch (e){
+    } catch (e) {
       return null;
       return null;
     }
     }
     const disc = base64.fromByteArray(logArr.slice(0, 8));
     const disc = base64.fromByteArray(logArr.slice(0, 8));

+ 6 - 5
ts/src/program/event.ts

@@ -58,7 +58,10 @@ export class EventParser {
     log: string
     log: string
   ): [Event | null, string | null, boolean] {
   ): [Event | null, string | null, boolean] {
     // Executing program is this program.
     // Executing program is this program.
-    if (execution.stack.length > 0 && execution.program() === this.programId.toString()) {
+    if (
+      execution.stack.length > 0 &&
+      execution.program() === this.programId.toString()
+    ) {
       return this.handleProgramLog(log);
       return this.handleProgramLog(log);
     }
     }
     // Executing program is not this program.
     // Executing program is not this program.
@@ -89,11 +92,9 @@ export class EventParser {
     const logStart = log.split(":")[0];
     const logStart = log.split(":")[0];
 
 
     // Did the program finish executing?
     // Did the program finish executing?
-    if (
-      logStart.match(/^Program (.*) success/g) !== null
-    ) {
+    if (logStart.match(/^Program (.*) success/g) !== null) {
       return [null, true];
       return [null, true];
-    // Recursive call.
+      // Recursive call.
     } else if (
     } else if (
       logStart.startsWith(`Program ${this.programId.toString()} invoke`)
       logStart.startsWith(`Program ${this.programId.toString()} invoke`)
     ) {
     ) {

+ 8 - 2
ts/src/program/index.ts

@@ -250,8 +250,14 @@ export class Program {
     this._coder = new Coder(idl);
     this._coder = new Coder(idl);
 
 
     // Dynamic namespaces.
     // Dynamic namespaces.
-    const [rpc, instruction, transaction, account, simulate, state] =
-      NamespaceFactory.build(idl, this._coder, programId, this._provider);
+    const [
+      rpc,
+      instruction,
+      transaction,
+      account,
+      simulate,
+      state,
+    ] = NamespaceFactory.build(idl, this._coder, programId, this._provider);
     this.rpc = rpc;
     this.rpc = rpc;
     this.instruction = instruction;
     this.instruction = instruction;
     this.transaction = transaction;
     this.transaction = transaction;

+ 3 - 4
ts/src/program/namespace/account.ts

@@ -235,10 +235,9 @@ export class AccountClient {
       fromPubkey: this._provider.wallet.publicKey,
       fromPubkey: this._provider.wallet.publicKey,
       newAccountPubkey: signer.publicKey,
       newAccountPubkey: signer.publicKey,
       space: sizeOverride ?? size,
       space: sizeOverride ?? size,
-      lamports:
-        await this._provider.connection.getMinimumBalanceForRentExemption(
-          sizeOverride ?? size
-        ),
+      lamports: await this._provider.connection.getMinimumBalanceForRentExemption(
+        sizeOverride ?? size
+      ),
       programId: this._programId,
       programId: this._programId,
     });
     });
   }
   }

+ 5 - 3
ts/src/workspace.ts

@@ -42,16 +42,18 @@ const workspace = new Proxy({} as any, {
 
 
       const idlFolder = `${projectRoot}/target/idl`;
       const idlFolder = `${projectRoot}/target/idl`;
       if (!fs.existsSync(idlFolder)) {
       if (!fs.existsSync(idlFolder)) {
-        throw new Error(`${idlFolder} doesn't exist. Did you use "anchor build"?`);
+        throw new Error(
+          `${idlFolder} doesn't exist. Did you use "anchor build"?`
+        );
       }
       }
 
 
       const idlMap = new Map<string, Idl>();
       const idlMap = new Map<string, Idl>();
-      fs.readdirSync(idlFolder).forEach(file => {
+      fs.readdirSync(idlFolder).forEach((file) => {
         const filePath = `${idlFolder}/${file}`;
         const filePath = `${idlFolder}/${file}`;
         const idlStr = fs.readFileSync(filePath);
         const idlStr = fs.readFileSync(filePath);
         const idl = JSON.parse(idlStr);
         const idl = JSON.parse(idlStr);
         idlMap.set(idl.name, idl);
         idlMap.set(idl.name, idl);
-        const name = camelCase(idl.name, {pascalCase: true});
+        const name = camelCase(idl.name, { pascalCase: true });
         if (idl.metadata && idl.metadata.address) {
         if (idl.metadata && idl.metadata.address) {
           workspaceCache[name] = new Program(
           workspaceCache[name] = new Program(
             idl,
             idl,