Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prettier, add ESLint #5

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CODEOWNERS
.yarn

.changeset/**/*.md
19 changes: 0 additions & 19 deletions .prettierrc

This file was deleted.

31 changes: 31 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
arrowParens: "always",
bracketSameLine: true,
bracketSpacing: true,
embeddedLanguageFormatting: "auto",
endOfLine: "lf",
htmlWhitespaceSensitivity: "css",
jsxSingleQuote: false,
printWidth: 80,
proseWrap: "preserve",
quoteProps: "as-needed",
semi: true,
singleAttributePerLine: false,
singleQuote: false,
tabWidth: 2,
trailingComma: "all",
useTabs: false,
plugins: [
"prettier-plugin-packagejson",
"@ianvs/prettier-plugin-sort-imports",
],
importOrder: [
"<BUILTIN_MODULES>",
"<THIRD_PARTY_MODULES>",
"^@(/.*)$",
"^@test(/.*)$",
"^@bench(/.*)$",
"^[.]",
],
importOrderTypeScriptVersion: "5.6.3",
};
131 changes: 131 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import path from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
import { includeIgnoreFile } from "@eslint/compat";
import eslint from "@eslint/js";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import globals from "globals";
import tseslint from "typescript-eslint";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gitignorePath = path.resolve(__dirname, ".gitignore");

export default tseslint.config(
includeIgnoreFile(gitignorePath),
{
ignores: [".yarn/**/*", "*.cursorrules"],
},
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: {
defaultProject: "tsconfig.json",
},
tsconfigRootDir: process.cwd(),
},
},
},
{
rules: {
"@typescript-eslint/consistent-type-exports": [
"error",
{
fixMixedExportsWithInlineTypeSpecifier: false,
},
],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-deprecated": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
ignoreRestSiblings: true,
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
},
],
},
},
{
files: ["**/*.cjs", "**/*.js"],
extends: [tseslint.configs.disableTypeChecked],
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
"@typescript-eslint/no-require-imports": "off",
},
},
{
files: ["**/*.test.ts"],
rules: {
"@typescript-eslint/no-non-null-assertion": "off",
},
},
{
files: ["sdks/js-sdk/**/*.ts"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "ImportDeclaration[source.value=/^(node:)?crypto$/]",
message:
"Do not import directly from `crypto`, use `@/encryption` instead.",
},
],
},
},
{
files: ["sdks/js-sdk/test/**/*.ts"],
rules: {
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/only-throw-error": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-deprecated": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-empty": "off",
},
},
{
files: ["sdks/**/*.ts"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "ImportDeclaration[source.value=/^\\.\\./]",
message:
"Relative parent imports are not allowed, use path aliases instead.",
},
],
},
},
eslintPluginPrettierRecommended,
);
4 changes: 2 additions & 2 deletions examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"dependencies": {
"@xmtp/agent-starter": "workspace:*",
"axios": "^1.7.9",
"express": "^4.21.2"
"express": "^5.0.1"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/express": "^5.0.0",
"@types/node": "^22.10.9",
"typescript": "^5.7.3"
},
Expand Down
39 changes: 20 additions & 19 deletions examples/express/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import express from "express";
import { xmtpClient, type XMTP } from "@xmtp/agent-starter";
import express, { type Request, type Response } from "express";
import fetch from "node-fetch";
import { xmtpClient, XMTP } from "@xmtp/agent-starter";

async function createServer(port: number, agent: XMTP) {
const app = express();
app.use(express.json());

// Endpoint to RECEIVE encrypted messages
app.post("/receive", async (req, res) => {
try {
const { nonce, ciphertext, fromAddress } = req.body;
const decryptedMessage = await agent.decrypt(
nonce,
ciphertext,
fromAddress,
);

console.log(`Server on port ${port} decrypted:`, decryptedMessage);
return res.json({ success: true, decryptedMessage });
} catch (error) {
console.error("Error in /receive:", error);
return res.status(500).json({ error: (error as Error).message });
}
app.post("/receive", (req: Request, res: Response) => {
const { nonce, ciphertext, fromAddress } = req.body as {
nonce: string;
ciphertext: string;
fromAddress: string;
};
agent
.decrypt(nonce, ciphertext, fromAddress)
.then((decryptedMessage) => {
console.log(`Server on port ${port} decrypted:`, decryptedMessage);
res.json({ success: true, decryptedMessage });
})
.catch((error: unknown) => {
console.error("Error in /receive:", error);
res.status(500).json({ error: (error as Error).message });
});
});

return new Promise((resolve) => {
Expand Down Expand Up @@ -66,8 +67,8 @@ async function main() {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
nonce: nonce as string,
ciphertext: ciphertext as string,
nonce: nonce,
ciphertext: ciphertext,
fromAddress: agentA.address as string, // the "sender"
}),
});
Expand Down
Loading
Loading