Browse Source

Add lint scripts for generated clients (#51)

Loris Leiva 1 year ago
parent
commit
587286c94a

+ 5 - 0
.changeset/sixty-hornets-cough.md

@@ -0,0 +1,5 @@
+---
+"create-solana-program": patch
+---
+
+Add lint scripts for generated clients

+ 4 - 11
scripts/snapshot.mjs

@@ -79,25 +79,18 @@ for (const projectName of projects) {
     });
   }
 
-  // Test clients.
+  // Lint and test clients.
   for (const client of CLIENTS) {
     if (`clients:${client}:test` in pkg.scripts) {
+      await executeStep(`lint ${client} client`, async () => {
+        await $`pnpm clients:${client}:lint`;
+      });
       await executeStep(`test ${client} client`, async () => {
         await $`pnpm clients:${client}:test`;
       });
     }
   }
 
-  // Additional JavaScript client tests.
-  if (`clients:js:test` in pkg.scripts) {
-    await executeStep(`lint js client`, async () => {
-      cd(path.join(projectDirectory, 'clients', 'js'));
-      await $`pnpm lint`;
-      await $`pnpm format`;
-      cd(projectDirectory);
-    });
-  }
-
   // Add line break between projects.
   echo('');
 }

+ 1 - 0
template/clients/js/package.json

@@ -1,5 +1,6 @@
 {
   "scripts": {
+    "clients:js:lint": "zx ./scripts/client/lint-js.mjs",
     "clients:js:test": "zx ./scripts/client/test-js.mjs"
   },
   "devDependencies": {

+ 9 - 0
template/clients/js/scripts/client/lint-js.mjs

@@ -0,0 +1,9 @@
+#!/usr/bin/env zx
+import 'zx/globals';
+import { workingDirectory } from '../utils.mjs';
+
+// Check the client using ESLint and Prettier.
+cd(path.join(workingDirectory, 'clients', 'js'));
+await $`pnpm install`;
+await $`pnpm lint`;
+await $`pnpm format`;

+ 1 - 0
template/clients/rust/package.json

@@ -1,5 +1,6 @@
 {
   "scripts": {
+    "clients:rust:lint": "zx ./scripts/client/lint-rust.mjs",
     "clients:rust:test": "zx ./scripts/client/test-rust.mjs"
   },
   "devDependencies": {

+ 7 - 0
template/clients/rust/scripts/client/lint-rust.mjs

@@ -0,0 +1,7 @@
+#!/usr/bin/env zx
+import 'zx/globals';
+import { workingDirectory } from '../utils.mjs';
+
+// Check the client using Clippy.
+cd(path.join(workingDirectory, 'clients', 'rust'));
+await $`cargo clippy ${argv._}`;