diff --git a/.eslintrc.json b/.eslintrc.json index bffb357..f8a16da 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,7 @@ { - "extends": "next/core-web-vitals" + "extends": ["next/core-web-vitals", "prettier"], + "plugins": ["prettier"], + "rules": { + "prettier/prettier": "error" + } } diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..e14c2cb --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,30 @@ +name: Code Quality + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + format-check: + name: Prettier Format Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Check formatting + run: npx prettier --check . + + - name: Run ESLint + run: npm run lint diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..e96b017 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +node_modules +.next +build +dist +public \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..866b7c1 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,20 @@ +{ + "arrowParens": "avoid", + "bracketSpacing": true, + "endOfLine": "lf", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "singleAttributePerLine": false, + "bracketSameLine": false, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 100, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "requirePragma": false, + "semi": true, + "trailingComma": "es5", + "tabWidth": 2, + "useTabs": false, + "vueIndentScriptAndStyle": false +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ee214f9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + } +} diff --git a/app/components/NetworkSelector.tsx b/app/components/NetworkSelector.tsx index 8e07342..47bbb8d 100644 --- a/app/components/NetworkSelector.tsx +++ b/app/components/NetworkSelector.tsx @@ -1,16 +1,16 @@ "use client"; -import React from 'react'; -import { useNetwork } from '../contexts/NetworkContext'; +import React from "react"; +import { useNetwork } from "../contexts/NetworkContext"; // Using string literals for network values as required by LitNodeClient const NETWORKS = { - DATIL_DEV: 'datil-dev', - DATIL_TEST: 'datil-test', - DATIL: 'datil' + DATIL_DEV: "datil-dev", + DATIL_TEST: "datil-test", + DATIL: "datil", } as const; -type NetworkType = typeof NETWORKS[keyof typeof NETWORKS]; +type NetworkType = (typeof NETWORKS)[keyof typeof NETWORKS]; export const NetworkSelector = () => { const { network, setNetwork } = useNetwork(); diff --git a/app/contexts/NetworkContext.tsx b/app/contexts/NetworkContext.tsx index 105b700..c02e252 100644 --- a/app/contexts/NetworkContext.tsx +++ b/app/contexts/NetworkContext.tsx @@ -1,15 +1,15 @@ "use client"; -import React, { createContext, useContext, useState, ReactNode } from 'react'; +import React, { createContext, useContext, useState, ReactNode } from "react"; // Using string literals for network values as required by LitNodeClient const NETWORKS = { - DATIL_DEV: 'datil-dev', - DATIL_TEST: 'datil-test', - DATIL: 'datil' + DATIL_DEV: "datil-dev", + DATIL_TEST: "datil-test", + DATIL: "datil", } as const; -type NetworkType = typeof NETWORKS[keyof typeof NETWORKS]; +type NetworkType = (typeof NETWORKS)[keyof typeof NETWORKS]; type NetworkContextType = { network: NetworkType; @@ -26,16 +26,14 @@ export function NetworkProvider({ children }: NetworkProviderProps) { const [network, setNetwork] = useState(NETWORKS.DATIL_DEV); return ( - - {children} - + {children} ); } export function useNetwork() { const context = useContext(NetworkContext); if (context === undefined) { - throw new Error('useNetwork must be used within a NetworkProvider'); + throw new Error("useNetwork must be used within a NetworkProvider"); } return context; } diff --git a/app/createSecrets/page.jsx b/app/createSecrets/page.jsx index 710918a..c9cea4e 100644 --- a/app/createSecrets/page.jsx +++ b/app/createSecrets/page.jsx @@ -1,7 +1,7 @@ -"use client" -import React, { useState, useEffect } from 'react' +"use client"; +import React, { useState, useEffect } from "react"; import { LitNodeClient, encryptString } from "@lit-protocol/lit-node-client"; -import { useNetwork } from '../contexts/NetworkContext'; +import { useNetwork } from "../contexts/NetworkContext"; import { Copy, Trash2 } from "lucide-react"; export default function Secrets() { @@ -17,7 +17,7 @@ export default function Secrets() { const [encryptedHistory, setEncryptedHistory] = useState([]); useEffect(() => { - const savedHistory = localStorage.getItem('secretsHistory'); + const savedHistory = localStorage.getItem("secretsHistory"); if (savedHistory) { setEncryptedHistory(JSON.parse(savedHistory)); } @@ -33,31 +33,31 @@ export default function Secrets() { } }; - const saveToHistory = (secretObject) => { + const saveToHistory = secretObject => { const newSecret = { id: Date.now(), timestamp: new Date().toISOString(), litActionCid, - secretObject + secretObject, }; const updatedHistory = [...encryptedHistory, newSecret]; setEncryptedHistory(updatedHistory); - localStorage.setItem('secretsHistory', JSON.stringify(updatedHistory)); + localStorage.setItem("secretsHistory", JSON.stringify(updatedHistory)); }; const clearHistory = () => { setEncryptedHistory([]); - localStorage.removeItem('secretsHistory'); + localStorage.removeItem("secretsHistory"); }; - const deleteHistoryItem = (id) => { + const deleteHistoryItem = id => { const updatedHistory = encryptedHistory.filter(item => item.id !== id); setEncryptedHistory(updatedHistory); - localStorage.setItem('secretsHistory', JSON.stringify(updatedHistory)); + localStorage.setItem("secretsHistory", JSON.stringify(updatedHistory)); }; - const encryptKey = async (dataToEncrypt) => { + const encryptKey = async dataToEncrypt => { try { setIsLoading(true); setError(""); @@ -87,13 +87,12 @@ export default function Secrets() { const secretObject = { encryptedData: ciphertext, dataToEncryptHash, - accessControlConditions, // Include access control conditions - litNetwork: network // Include network information + accessControlConditions, // Include access control conditions + litNetwork: network, // Include network information }; setCurrentSecret(secretObject); saveToHistory(secretObject); - } catch (err) { setError("Failed to encrypt: " + err.message); } finally { @@ -108,7 +107,7 @@ export default function Secrets() { setError(""); const litNodeClient = new LitNodeClient({ litNetwork: network, - debug: false + debug: false, }); await litNodeClient.connect(); setLitNodeClient(litNodeClient); @@ -148,14 +147,12 @@ export default function Secrets() {
- + setLitActionCid(e.target.value)} + onChange={e => setLitActionCid(e.target.value)} className="w-full p-3 border border-orange-200 rounded focus:ring-2 focus:ring-orange-500 focus:border-transparent outline-none text-gray-900" />
@@ -167,7 +164,7 @@ export default function Secrets() {