From 79850dccfe8a8b7a018ca9ecf99766f94e378263 Mon Sep 17 00:00:00 2001
From: suryarajendhran <32726562+suryarajendhran@users.noreply.github.com>
Date: Thu, 25 Jul 2024 15:08:47 +0530
Subject: [PATCH] lint: format & fix style issues in project
---
.github/workflows/node.js.yml | 1 +
.vscode/extensions.json | 4 +-
biome.json | 17 ++
extensions/checkout-ui-2/babel.config.js | 6 +-
.../checkout-ui-2/src/Checkout.test.tsx | 45 ++---
extensions/checkout-ui-2/src/Checkout.tsx | 4 +-
extensions/checkout-ui/babel.config.js | 12 +-
extensions/checkout-ui/src/Checkout.jsx | 5 +-
extensions/checkout-ui/src/Checkout.test.jsx | 44 ++---
package-lock.json | 158 ++++++++++++++++++
package.json | 14 +-
11 files changed, 244 insertions(+), 66 deletions(-)
create mode 100644 biome.json
diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml
index 5d5bef4..3eed505 100644
--- a/.github/workflows/node.js.yml
+++ b/.github/workflows/node.js.yml
@@ -27,5 +27,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
+ - run: npm run lint
- run: npm run build --if-present
- run: npm test --workspaces --if-present
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index 6e72a6a..ac39d54 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -1,5 +1,3 @@
{
- "recommendations": [
- "graphql.vscode-graphql"
- ]
+ "recommendations": ["graphql.vscode-graphql"]
}
diff --git a/biome.json b/biome.json
new file mode 100644
index 0000000..e0dd882
--- /dev/null
+++ b/biome.json
@@ -0,0 +1,17 @@
+{
+ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
+ "formatter": {
+ "enabled": true,
+ "indentWidth": 2,
+ "indentStyle": "space"
+ },
+ "organizeImports": {
+ "enabled": true
+ },
+ "linter": {
+ "enabled": true,
+ "rules": {
+ "recommended": true
+ }
+ }
+}
diff --git a/extensions/checkout-ui-2/babel.config.js b/extensions/checkout-ui-2/babel.config.js
index 286a34c..f7fde52 100644
--- a/extensions/checkout-ui-2/babel.config.js
+++ b/extensions/checkout-ui-2/babel.config.js
@@ -1,7 +1,7 @@
module.exports = {
presets: [
- ['@babel/preset-env', { targets: { node: 'current' } }],
- ['@babel/preset-react', { runtime: 'automatic' }],
- '@babel/preset-typescript',
+ ["@babel/preset-env", { targets: { node: "current" } }],
+ ["@babel/preset-react", { runtime: "automatic" }],
+ "@babel/preset-typescript",
],
};
diff --git a/extensions/checkout-ui-2/src/Checkout.test.tsx b/extensions/checkout-ui-2/src/Checkout.test.tsx
index 6c01fb9..66f4a60 100644
--- a/extensions/checkout-ui-2/src/Checkout.test.tsx
+++ b/extensions/checkout-ui-2/src/Checkout.test.tsx
@@ -1,28 +1,31 @@
-import { mount } from '@remote-ui/testing'
-import { createRoot } from '@remote-ui/react'
-import { Extension } from './Checkout'
-import * as Shopify from '@shopify/ui-extensions-react/checkout';
-import '@remote-ui/testing/matchers';
+import { createRoot } from "@remote-ui/react";
+import { mount } from "@remote-ui/testing";
+import * as Shopify from "@shopify/ui-extensions-react/checkout";
+import { Extension } from "./Checkout";
+import "@remote-ui/testing/matchers";
-jest.mock('@shopify/ui-extensions-react/checkout', () => {
- return {
- __esModule: true,
- ...jest.requireActual('@shopify/ui-extensions-react/checkout'),
- };
+jest.mock("@shopify/ui-extensions-react/checkout", () => {
+ return {
+ __esModule: true,
+ ...jest.requireActual("@shopify/ui-extensions-react/checkout"),
+ };
});
jest
- .spyOn(Shopify, 'useTranslate')
- .mockImplementation(() => (translationKey: string) => translationKey as any);
+ .spyOn(Shopify, "useTranslate")
+ // biome-ignore lint/suspicious/noExplicitAny: can't mock an i18n function
+ .mockImplementation(() => (translationKey: string) => translationKey as any);
-jest.spyOn(Shopify, 'useApi').mockImplementation(() => ({ extension: { target: 'purchase.checkout.block.render' } }));
+jest.spyOn(Shopify, "useApi").mockImplementation(() => ({
+ extension: { target: "purchase.checkout.block.render" },
+}));
-describe('Header', () => {
- it('renders the header', () => {
- const app = mount((root) => {
- createRoot(root).render()
- })
+describe("Extension", () => {
+ it("renders the welcome text", () => {
+ const app = mount((root) => {
+ createRoot(root).render();
+ });
- expect(app).toContainRemoteText('welcome');
- })
-})
\ No newline at end of file
+ expect(app).toContainRemoteText("welcome");
+ });
+});
diff --git a/extensions/checkout-ui-2/src/Checkout.tsx b/extensions/checkout-ui-2/src/Checkout.tsx
index 67988b0..3328b84 100644
--- a/extensions/checkout-ui-2/src/Checkout.tsx
+++ b/extensions/checkout-ui-2/src/Checkout.tsx
@@ -1,8 +1,8 @@
import {
- reactExtension,
Banner,
BlockStack,
Text,
+ reactExtension,
useApi,
useTranslate,
} from "@shopify/ui-extensions-react/checkout";
@@ -24,4 +24,4 @@ export function Extension() {
);
-}
\ No newline at end of file
+}
diff --git a/extensions/checkout-ui/babel.config.js b/extensions/checkout-ui/babel.config.js
index 6e4fd7b..85db31a 100644
--- a/extensions/checkout-ui/babel.config.js
+++ b/extensions/checkout-ui/babel.config.js
@@ -1,7 +1,7 @@
module.exports = {
- presets: [
- '@babel/preset-env',
- ['@babel/preset-react', {runtime: 'automatic'}],
- "@babel/preset-typescript",
- ],
- };
\ No newline at end of file
+ presets: [
+ "@babel/preset-env",
+ ["@babel/preset-react", { runtime: "automatic" }],
+ "@babel/preset-typescript",
+ ],
+};
diff --git a/extensions/checkout-ui/src/Checkout.jsx b/extensions/checkout-ui/src/Checkout.jsx
index f5159bf..3328b84 100644
--- a/extensions/checkout-ui/src/Checkout.jsx
+++ b/extensions/checkout-ui/src/Checkout.jsx
@@ -1,8 +1,8 @@
import {
- reactExtension,
Banner,
BlockStack,
Text,
+ reactExtension,
useApi,
useTranslate,
} from "@shopify/ui-extensions-react/checkout";
@@ -15,7 +15,6 @@ export function Extension() {
const translate = useTranslate();
const { extension } = useApi();
- // 3. Render a UI
return (
@@ -25,4 +24,4 @@ export function Extension() {
);
-}
\ No newline at end of file
+}
diff --git a/extensions/checkout-ui/src/Checkout.test.jsx b/extensions/checkout-ui/src/Checkout.test.jsx
index d6c7ebf..c843258 100644
--- a/extensions/checkout-ui/src/Checkout.test.jsx
+++ b/extensions/checkout-ui/src/Checkout.test.jsx
@@ -1,28 +1,30 @@
-import { mount } from '@remote-ui/testing'
-import { createRoot } from '@remote-ui/react'
-import { Extension } from './Checkout'
-import * as Shopify from '@shopify/ui-extensions-react/checkout';
-import '@remote-ui/testing/matchers';
+import { createRoot } from "@remote-ui/react";
+import { mount } from "@remote-ui/testing";
+import * as Shopify from "@shopify/ui-extensions-react/checkout";
+import { Extension } from "./Checkout";
+import "@remote-ui/testing/matchers";
-jest.mock('@shopify/ui-extensions-react/checkout', () => {
- return {
- __esModule: true,
- ...jest.requireActual('@shopify/ui-extensions-react/checkout'),
- };
+jest.mock("@shopify/ui-extensions-react/checkout", () => {
+ return {
+ __esModule: true,
+ ...jest.requireActual("@shopify/ui-extensions-react/checkout"),
+ };
});
jest
- .spyOn(Shopify, 'useTranslate')
- .mockImplementation(() => (translationKey) => translationKey);
+ .spyOn(Shopify, "useTranslate")
+ .mockImplementation(() => (translationKey) => translationKey);
-jest.spyOn(Shopify, 'useApi').mockImplementation(() => ({ extension: { target: 'purchase.checkout.block.render' } }));
+jest.spyOn(Shopify, "useApi").mockImplementation(() => ({
+ extension: { target: "purchase.checkout.block.render" },
+}));
-describe('Header', () => {
- it('renders the header', () => {
- const app = mount((root) => {
- createRoot(root).render()
- })
+describe("Extension", () => {
+ it("renders the welcome text", () => {
+ const app = mount((root) => {
+ createRoot(root).render();
+ });
- expect(app).toContainRemoteText('welcome');
- })
-})
\ No newline at end of file
+ expect(app).toContainRemoteText("welcome");
+ });
+});
diff --git a/package-lock.json b/package-lock.json
index 87fdf07..4aba6eb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,6 +14,9 @@
"dependencies": {
"@shopify/app": "^3.58.2",
"@shopify/cli": "^3.64.1"
+ },
+ "devDependencies": {
+ "@biomejs/biome": "1.8.3"
}
},
"extensions/checkout-ui": {
@@ -2125,6 +2128,161 @@
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
"dev": true
},
+ "node_modules/@biomejs/biome": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.8.3.tgz",
+ "integrity": "sha512-/uUV3MV+vyAczO+vKrPdOW0Iaet7UnJMU4bNMinggGJTAnBPjCoLEYcyYtYHNnUNYlv4xZMH6hVIQCAozq8d5w==",
+ "dev": true,
+ "hasInstallScript": true,
+ "bin": {
+ "biome": "bin/biome"
+ },
+ "engines": {
+ "node": ">=14.21.3"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/biome"
+ },
+ "optionalDependencies": {
+ "@biomejs/cli-darwin-arm64": "1.8.3",
+ "@biomejs/cli-darwin-x64": "1.8.3",
+ "@biomejs/cli-linux-arm64": "1.8.3",
+ "@biomejs/cli-linux-arm64-musl": "1.8.3",
+ "@biomejs/cli-linux-x64": "1.8.3",
+ "@biomejs/cli-linux-x64-musl": "1.8.3",
+ "@biomejs/cli-win32-arm64": "1.8.3",
+ "@biomejs/cli-win32-x64": "1.8.3"
+ }
+ },
+ "node_modules/@biomejs/cli-darwin-arm64": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.8.3.tgz",
+ "integrity": "sha512-9DYOjclFpKrH/m1Oz75SSExR8VKvNSSsLnVIqdnKexj6NwmiMlKk94Wa1kZEdv6MCOHGHgyyoV57Cw8WzL5n3A==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-darwin-x64": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.8.3.tgz",
+ "integrity": "sha512-UeW44L/AtbmOF7KXLCoM+9PSgPo0IDcyEUfIoOXYeANaNXXf9mLUwV1GeF2OWjyic5zj6CnAJ9uzk2LT3v/wAw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-linux-arm64": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.8.3.tgz",
+ "integrity": "sha512-fed2ji8s+I/m8upWpTJGanqiJ0rnlHOK3DdxsyVLZQ8ClY6qLuPc9uehCREBifRJLl/iJyQpHIRufLDeotsPtw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-linux-arm64-musl": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.8.3.tgz",
+ "integrity": "sha512-9yjUfOFN7wrYsXt/T/gEWfvVxKlnh3yBpnScw98IF+oOeCYb5/b/+K7YNqKROV2i1DlMjg9g/EcN9wvj+NkMuQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-linux-x64": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.8.3.tgz",
+ "integrity": "sha512-I8G2QmuE1teISyT8ie1HXsjFRz9L1m5n83U1O6m30Kw+kPMPSKjag6QGUn+sXT8V+XWIZxFFBoTDEDZW2KPDDw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-linux-x64-musl": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.8.3.tgz",
+ "integrity": "sha512-UHrGJX7PrKMKzPGoEsooKC9jXJMa28TUSMjcIlbDnIO4EAavCoVmNQaIuUSH0Ls2mpGMwUIf+aZJv657zfWWjA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-win32-arm64": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.8.3.tgz",
+ "integrity": "sha512-J+Hu9WvrBevfy06eU1Na0lpc7uR9tibm9maHynLIoAjLZpQU3IW+OKHUtyL8p6/3pT2Ju5t5emReeIS2SAxhkQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
+ "node_modules/@biomejs/cli-win32-x64": {
+ "version": "1.8.3",
+ "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.8.3.tgz",
+ "integrity": "sha512-/PJ59vA1pnQeKahemaQf4Nyj7IKUvGQSc3Ze1uIGi+Wvr1xF7rGobSrAAG01T/gUDG21vkDsZYM03NAmPiVkqg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=14.21.3"
+ }
+ },
"node_modules/@bugsnag/browser": {
"version": "7.25.0",
"resolved": "https://registry.npmjs.org/@bugsnag/browser/-/browser-7.25.0.tgz",
diff --git a/package.json b/package.json
index c947b0c..306abf3 100644
--- a/package.json
+++ b/package.json
@@ -8,18 +8,18 @@
"dev": "shopify app dev",
"info": "shopify app info",
"generate": "shopify app generate",
- "deploy": "shopify app deploy"
+ "deploy": "shopify app deploy",
+ "lint": "biome check --write ."
},
"dependencies": {
"@shopify/app": "^3.58.2",
"@shopify/cli": "^3.64.1"
},
- "trustedDependencies": [
- "@shopify/plugin-cloudflare"
- ],
+ "trustedDependencies": ["@shopify/plugin-cloudflare"],
"author": "suryarajendhran",
"private": true,
- "workspaces": [
- "extensions/*"
- ]
+ "workspaces": ["extensions/*"],
+ "devDependencies": {
+ "@biomejs/biome": "1.8.3"
+ }
}