Skip to content

Commit

Permalink
Merge pull request #682 from xmtp/rygine/eslint
Browse files Browse the repository at this point in the history
Revamp linting
  • Loading branch information
rygine authored Oct 17, 2024
2 parents 79582d0 + 77c08c8 commit 44174c3
Show file tree
Hide file tree
Showing 111 changed files with 724 additions and 2,181 deletions.
8 changes: 8 additions & 0 deletions .changeset/breezy-gorillas-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@xmtp/content-type-primitives": patch
"@xmtp/content-type-reaction": patch
"@xmtp/content-type-read-receipt": patch
"@xmtp/content-type-remote-attachment": patch
---

Update `ContentCodec` generic type
18 changes: 0 additions & 18 deletions .github/workflows/content-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ jobs:
- name: Typecheck
run: yarn turbo run typecheck --filter='./content-types/*'

lint:
name: Lint
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Lint
run: yarn turbo run lint --filter='./content-types/*'

test:
name: Test
runs-on: warp-ubuntu-latest-x64-8x
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/encryption.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@ jobs:
- name: Typecheck
run: yarn turbo run typecheck --filter='./shared/encryption'

lint:
name: Lint
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Lint
run: yarn turbo run lint --filter='./shared/encryption'

test:
name: Test
runs-on: warp-ubuntu-latest-x64-8x
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/js-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ jobs:
- name: Typecheck
run: yarn turbo run typecheck --filter='./sdks/js-sdk'

lint:
name: Lint
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Lint
run: yarn turbo run lint --filter='./sdks/js-sdk'

test:
name: Test
runs-on: warp-ubuntu-latest-x64-8x
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ESLint

on:
push:
branches:
- main

pull_request:

jobs:
lint:
name: Lint
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Lint
run: yarn lint
18 changes: 0 additions & 18 deletions .github/workflows/mls-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ jobs:
- name: Typecheck
run: yarn turbo run typecheck --filter='./sdks/node-sdk'

lint:
name: Lint
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Lint
run: yarn turbo run lint --filter='./sdks/node-sdk'

test:
name: Test
runs-on: warp-ubuntu-latest-x64-8x
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/noop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ on:
- "*"
- "!.node-version"
- "!.nvmrc"
- "!.prettierignore"
- "!.prettierrc.cjs"
- "!.yarnrc.yml"
- "!turbo.json"
- "!yarn.lock"
Expand All @@ -30,12 +28,6 @@ jobs:
steps:
- run: echo "Nothing to typecheck"

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- run: echo "Nothing to lint"

test:
name: Test
runs-on: ubuntu-latest
Expand Down
7 changes: 0 additions & 7 deletions content-types/content-type-primitives/.eslintrc.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions content-types/content-type-primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"clean": "yarn clean:dist && rimraf .turbo node_modules",
"clean:dist": "rimraf dist",
"dev": "yarn clean:dist && yarn rollup -c --watch",
"lint": "eslint . --ignore-path ../../.gitignore",
"test": "yarn test:node && yarn test:jsdom",
"test:jsdom": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment happy-dom",
"test:node": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment node",
Expand All @@ -70,8 +69,6 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@types/node": "^20.16.11",
"eslint": "^8.57.0",
"eslint-config-custom": "workspace:*",
"happy-dom": "^15.7.4",
"rimraf": "^6.0.1",
"rollup": "^4.24.0",
Expand Down
19 changes: 14 additions & 5 deletions content-types/content-type-primitives/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ export type EncodedContent<Parameters = Record<string, string>> = {
content: Uint8Array;
};

export type ContentCodec<T = any> = {
export type ContentCodec<
ContentType = any,

Check warning on line 49 in content-types/content-type-primitives/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
Parameters = Record<string, string>,
> = {
contentType: ContentTypeId;
encode(content: T, registry: CodecRegistry<T>): EncodedContent;
decode(content: EncodedContent, registry: CodecRegistry<T>): T;
fallback(content: T): string | undefined;
shouldPush: (content: T) => boolean;
encode(
content: ContentType,
registry: CodecRegistry<ContentType>,
): EncodedContent<Parameters>;
decode(
content: EncodedContent<Parameters>,
registry: CodecRegistry<ContentType>,
): ContentType;
fallback(content: ContentType): string | undefined;
shouldPush: (content: ContentType) => boolean;
};

/**
Expand Down
5 changes: 0 additions & 5 deletions content-types/content-type-primitives/tsconfig.eslint.json

This file was deleted.

3 changes: 1 addition & 2 deletions content-types/content-type-primitives/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "tsconfig/build.json",
"include": ["src"],
"exclude": ["dist", "node_modules"]
"include": ["src", "rollup.config.js"]
}
7 changes: 0 additions & 7 deletions content-types/content-type-reaction/.eslintrc.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions content-types/content-type-reaction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"clean": "yarn clean:dist && rimraf .turbo node_modules",
"clean:dist": "rimraf dist",
"dev": "yarn clean:dist && yarn rollup -c --watch",
"lint": "eslint . --ignore-path ../../.gitignore",
"test": "yarn test:node && yarn test:jsdom",
"test:jsdom": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment happy-dom",
"test:node": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment node",
Expand All @@ -72,8 +71,6 @@
"@types/node": "^20.16.11",
"@xmtp/xmtp-js": "^11.6.3",
"buffer": "^6.0.3",
"eslint": "^8.57.0",
"eslint-config-custom": "workspace:*",
"ethers": "^6.11.1",
"happy-dom": "^15.7.4",
"rimraf": "^6.0.1",
Expand Down
15 changes: 9 additions & 6 deletions content-types/content-type-reaction/src/Reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ export type Reaction = {
schema: "unicode" | "shortcode" | "custom";
};

type LegacyReactionParameters = Pick<
export type LegacyReactionParameters = Pick<
Reaction,
"action" | "reference" | "schema"
> & {
encoding: "UTF-8";
};

export class ReactionCodec implements ContentCodec<Reaction> {
export class ReactionCodec
implements
ContentCodec<Reaction, LegacyReactionParameters | Record<string, never>>
{
get contentType(): ContentTypeId {
return ContentTypeReaction;
}

encode(reaction: Reaction): EncodedContent {
encode(reaction: Reaction) {
const { action, reference, referenceInboxId, schema, content } = reaction;
return {
type: this.contentType,
Expand All @@ -65,20 +68,20 @@ export class ReactionCodec implements ContentCodec<Reaction> {
};
}

decode(encodedContent: EncodedContent): Reaction {
decode(encodedContent: EncodedContent<LegacyReactionParameters>): Reaction {
const decodedContent = new TextDecoder().decode(encodedContent.content);

// First try to decode it in the canonical form.
try {
const reaction = JSON.parse(decodedContent) as Reaction;
const { action, reference, referenceInboxId, schema, content } = reaction;
return { action, reference, referenceInboxId, schema, content };
} catch (e) {
} catch {
// ignore, fall through to legacy decoding
}

// If that fails, try to decode it in the legacy form.
const parameters = encodedContent.parameters as LegacyReactionParameters;
const parameters = encodedContent.parameters;
return {
action: parameters.action,
reference: parameters.reference,
Expand Down
3 changes: 1 addition & 2 deletions content-types/content-type-reaction/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { ReactionCodec, ContentTypeReaction } from "./Reaction";
export type { Reaction } from "./Reaction";
export * from "./Reaction";
5 changes: 0 additions & 5 deletions content-types/content-type-reaction/tsconfig.eslint.json

This file was deleted.

3 changes: 1 addition & 2 deletions content-types/content-type-reaction/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "tsconfig/build.json",
"include": ["src"],
"exclude": ["dist", "node_modules"]
"include": ["src", "rollup.config.js", "vitest.config.ts", "vitest.setup.ts"]
}
7 changes: 0 additions & 7 deletions content-types/content-type-read-receipt/.eslintrc.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions content-types/content-type-read-receipt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"clean": "yarn clean:dist && rimraf .turbo node_modules",
"clean:dist": "rimraf dist",
"dev": "yarn clean:dist && yarn rollup -c --watch",
"lint": "eslint . --ignore-path ../../.gitignore",
"test": "yarn test:node && yarn test:jsdom",
"test:jsdom": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment happy-dom",
"test:node": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment node",
Expand All @@ -72,8 +71,6 @@
"@types/node": "^20.16.11",
"@xmtp/xmtp-js": "^11.6.3",
"buffer": "^6.0.3",
"eslint": "^8.57.0",
"eslint-config-custom": "workspace:*",
"ethers": "^6.11.1",
"happy-dom": "^15.7.4",
"rimraf": "^6.0.1",
Expand Down
9 changes: 6 additions & 3 deletions content-types/content-type-read-receipt/src/ReadReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ContentTypeId,
type ContentCodec,
type EncodedContent,
} from "@xmtp/content-type-primitives";

export const ContentTypeReadReceipt = new ContentTypeId({
Expand All @@ -13,12 +12,16 @@ export const ContentTypeReadReceipt = new ContentTypeId({

export type ReadReceipt = Record<string, never>;

export class ReadReceiptCodec implements ContentCodec<ReadReceipt> {
export type ReadReceiptParameters = Record<string, never>;

export class ReadReceiptCodec
implements ContentCodec<ReadReceipt, ReadReceiptParameters>
{
get contentType(): ContentTypeId {
return ContentTypeReadReceipt;
}

encode(): EncodedContent {
encode() {
return {
type: ContentTypeReadReceipt,
parameters: {},
Expand Down
3 changes: 1 addition & 2 deletions content-types/content-type-read-receipt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { ReadReceiptCodec, ContentTypeReadReceipt } from "./ReadReceipt";
export type { ReadReceipt } from "./ReadReceipt";
export * from "./ReadReceipt";
5 changes: 0 additions & 5 deletions content-types/content-type-read-receipt/tsconfig.eslint.json

This file was deleted.

3 changes: 1 addition & 2 deletions content-types/content-type-read-receipt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "tsconfig/build.json",
"include": ["src"],
"exclude": ["dist", "node_modules"]
"include": ["src", "rollup.config.js", "vitest.config.ts", "vitest.setup.ts"]
}
7 changes: 0 additions & 7 deletions content-types/content-type-remote-attachment/.eslintrc.cjs

This file was deleted.

Loading

0 comments on commit 44174c3

Please sign in to comment.