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

Adds lint workflow #19

Merged
merged 8 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"array-callback-return": ["error"],
"no-await-in-loop": ["error"],
"no-constant-binary-expression": ["error"],
"no-constructor-return": ["error"],
"no-duplicate-imports": ["error"],
"no-new-native-nonconstructor": ["error"],
"no-self-compare": ["error"],
"no-template-curly-in-string": ["error"],
"no-unmodified-loop-condition": ["error"],
"no-unreachable-loop": ["error"],
"no-unused-private-class-members": ["error"],
"require-atomic-updates": ["error"]
},
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint
on:
workflow_dispatch: {}
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: npm install
- name: Run ESLint
run: npm run lint
17 changes: 8 additions & 9 deletions __test__/auth/AccessTokenService.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AccessTokenService from "../../src/features/auth/domain/AccessTokenService"
import { IOAuthToken } from "../../src/features/auth/domain/IOAuthTokenRepository"

test("It reads the access token from the repository", async () => {
const sut = new AccessTokenService({
Expand All @@ -11,9 +10,9 @@ test("It reads the access token from the repository", async () => {
refreshTokenExpiryDate: new Date(new Date().getTime() + 3600 * 1000)
}
},
async storeOAuthToken(_token: IOAuthToken) {}
async storeOAuthToken() {}
}, {
async refreshAccessToken(_refreshToken: string) {
async refreshAccessToken() {
return {
accessToken: "foo",
refreshToken: "bar",
Expand All @@ -36,9 +35,9 @@ test("It refreshes an expired access token", async () => {
refreshTokenExpiryDate: new Date(new Date().getTime() + 3600 * 1000)
}
},
async storeOAuthToken(_token: IOAuthToken) {}
async storeOAuthToken() {}
}, {
async refreshAccessToken(_refreshToken: string) {
async refreshAccessToken() {
return {
accessToken: "new",
refreshToken: "bar",
Expand All @@ -62,11 +61,11 @@ test("It stores the refreshed access token", async () => {
refreshTokenExpiryDate: new Date(new Date().getTime() + 3600 * 1000)
}
},
async storeOAuthToken(_token: IOAuthToken) {
async storeOAuthToken() {
didStoreRefreshedToken = true
}
}, {
async refreshAccessToken(_refreshToken: string) {
async refreshAccessToken() {
return {
accessToken: "new",
refreshToken: "bar",
Expand All @@ -89,9 +88,9 @@ test("It errors when the refresh token has expired", async () => {
refreshTokenExpiryDate: new Date(new Date().getTime() - 3600 * 1000)
}
},
async storeOAuthToken(_token: IOAuthToken) {}
async storeOAuthToken() {}
}, {
async refreshAccessToken(_refreshToken: string) {
async refreshAccessToken() {
return {
accessToken: "new",
refreshToken: "bar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import ExistingCommentCheckingPullRequestEventHandler from "../../src/features/h
test("It fetches comments from the repository", async () => {
let didFetchComments = false
const sut = new ExistingCommentCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {}
async pullRequestOpened() {}
}, {
async getComments(_operation) {
async getComments() {
didFetchComments = true
return []
},
async addComment(_operation) {}
async addComment() {}
}, "https://docs.shapetools.io")
await sut.pullRequestOpened({
appInstallationId: 42,
Expand All @@ -24,14 +24,14 @@ test("It fetches comments from the repository", async () => {
test("It does calls decorated event handler if a comment does not exist in the repository", async () => {
let didCallEventHandler = false
const sut = new ExistingCommentCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, {
async getComments(_operation) {
async getComments() {
return []
},
async addComment(_operation) {}
async addComment() {}
}, "https://docs.shapetools.io")
await sut.pullRequestOpened({
appInstallationId: 42,
Expand All @@ -46,17 +46,17 @@ test("It does calls decorated event handler if a comment does not exist in the r
test("It does not call the event handler if a comment already exists in the repository", async () => {
let didCallEventHandler = false
const sut = new ExistingCommentCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, {
async getComments(_operation) {
async getComments() {
return [{
body: "The documentation is available on https://docs.shapetools.io",
isFromBot: true
}]
},
async addComment(_operation) {}
async addComment() {}
}, "https://docs.shapetools.io")
await sut.pullRequestOpened({
appInstallationId: 42,
Expand All @@ -71,17 +71,17 @@ test("It does not call the event handler if a comment already exists in the repo
test("It calls the event handler if a comment exists matching the needle domain but that comment is not from a bot", async () => {
let didCallEventHandler = false
const sut = new ExistingCommentCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, {
async getComments(_operation) {
async getComments() {
return [{
body: "The documentation is available on https://docs.shapetools.io",
isFromBot: false
}]
},
async addComment(_operation) {}
async addComment() {}
}, "https://docs.shapetools.io")
await sut.pullRequestOpened({
appInstallationId: 42,
Expand All @@ -96,17 +96,17 @@ test("It calls the event handler if a comment exists matching the needle domain
test("It calls the event handler if the repository contains a comment from a bot but that comment does not contain the needle domain", async () => {
let didCallEventHandler = false
const sut = new ExistingCommentCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, {
async getComments(_operation) {
async getComments() {
return [{
body: "Hello world!",
isFromBot: true
}]
},
async addComment(_operation) {}
async addComment() {}
}, "https://docs.shapetools.io")
await sut.pullRequestOpened({
appInstallationId: 42,
Expand Down
8 changes: 4 additions & 4 deletions __test__/hooks/PostCommentPullRequestEventHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import PostCommentPullRequestEventHandler from "../../src/features/hooks/domain/
test("It adds a comment to the repository", async () => {
let didAddComment = false
const sut = new PostCommentPullRequestEventHandler({
async getComments(_operation) {
async getComments() {
return []
},
async addComment(_operation) {
async addComment() {
didAddComment = true
}
}, "https://docs.shapetools.io")
Expand All @@ -23,7 +23,7 @@ test("It adds a comment to the repository", async () => {
test("It adds a comment containing a link to the documentation", async () => {
let commentBody: string | undefined
const sut = new PostCommentPullRequestEventHandler({
async getComments(_operation) {
async getComments() {
return []
},
async addComment(operation) {
Expand All @@ -43,7 +43,7 @@ test("It adds a comment containing a link to the documentation", async () => {
test("It removes the \"openapi\" suffix of the repository name", async () => {
let commentBody: string | undefined
const sut = new PostCommentPullRequestEventHandler({
async getComments(_operation) {
async getComments() {
return []
},
async addComment(operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RepositoryNameCheckingPullRequestEventHandler from "../../src/features/ho
test("It does not call event handler when repository name does not have \"-openapi\" suffix", async () => {
let didCallEventHandler = false
const sut = new RepositoryNameCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, [], [])
Expand All @@ -20,7 +20,7 @@ test("It does not call event handler when repository name does not have \"-opena
test("It does not call event handler when repository name contains \"-openapi\" but it is not the last part of the repository name", async () => {
let didCallEventHandler = false
const sut = new RepositoryNameCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, [], [])
Expand All @@ -37,7 +37,7 @@ test("It does not call event handler when repository name contains \"-openapi\"
test("It calls event handler when no repositories have been allowed or disallowed", async () => {
let didCallEventHandler = false
const sut = new RepositoryNameCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, [], [])
Expand All @@ -54,7 +54,7 @@ test("It calls event handler when no repositories have been allowed or disallowe
test("It does not call event handler for repository that is not on the allowlist", async () => {
let didCallEventHandler = false
const sut = new RepositoryNameCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, ["example-openapi"], [])
Expand All @@ -71,7 +71,7 @@ test("It does not call event handler for repository that is not on the allowlist
test("It does not call event handler for repository that is on the disallowlist", async () => {
let didCallEventHandler = false
const sut = new RepositoryNameCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, [], ["example-openapi"])
Expand All @@ -88,7 +88,7 @@ test("It does not call event handler for repository that is on the disallowlist"
test("It lets the disallowlist takes precedence over the allowlist", async () => {
let didCallEventHandler = false
const sut = new RepositoryNameCheckingPullRequestEventHandler({
async pullRequestOpened(_event) {
async pullRequestOpened() {
didCallEventHandler = true
}
}, ["example-openapi"], ["example-openapi"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export async function GET(req: NextRequest, { params }: { params: GetBlobParams
path: fullPath,
ref: ref || undefined
})
let item = response.data as GitHubContentItem
const item = response.data as GitHubContentItem
return NextResponse.redirect(new URL(item.download_url))
}
2 changes: 1 addition & 1 deletion src/app/api/hooks/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const commentRepository = new GitHubPullRequestCommentRepository({
appId: GITHUB_APP_ID,
privateKey: privateKey,
clientId: GITHUB_CLIENT_ID,
clientSecret: GITHUB_WEBHOOK_SECRET
clientSecret: GITHUB_CLIENT_SECRET
})
const hookHandler = new GitHubHookHandler({
secret: GITHUB_WEBHOOK_SECRET,
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/user/projects/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server"
import { NextResponse } from "next/server"
import { projectRepository } from "@/common/startup"

export async function GET(_req: NextRequest) {
export async function GET() {
const projects = await projectRepository.getProjects()
return NextResponse.json({projects})
}
15 changes: 9 additions & 6 deletions src/common/client/ThemeRegistry.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
"use client"

import { useState } from "react"
import createCache from "@emotion/cache"
import { ReactNode, useState } from "react"
import createCache, { Options } from "@emotion/cache"
import { useServerInsertedHTML } from "next/navigation"
import { CacheProvider } from "@emotion/react"
import { ThemeProvider } from "@mui/material/styles"
import CssBaseline from "@mui/material/CssBaseline"
import theme from "./theme"
import useMediaQuery from "@mui/material/useMediaQuery"

type ThemeRegistryProps = {
options: Options
children: ReactNode
}

// This implementation is from emotion-js
// https://github.com/emotion-js/emotion/issues/2928#issuecomment-1319747902
export default function ThemeRegistry(props: any) {
export default function ThemeRegistry(props: ThemeRegistryProps) {
const { options, children } = props;
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
const [{ cache, flush }] = useState(() => {
const cache = createCache(options);
cache.compat = true;
Expand Down Expand Up @@ -56,7 +59,7 @@ export default function ThemeRegistry(props: any) {

return (
<CacheProvider value={cache}>
<ThemeProvider theme={theme(prefersDarkMode)}>
<ThemeProvider theme={theme()}>
<CssBaseline />
{children}
</ThemeProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/common/client/theme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTheme } from "@mui/material/styles"
import { blue } from "@mui/material/colors"

const theme = (_prefersDarkMode: boolean) => createTheme({
const theme = () => createTheme({
palette: {
mode: "light",
primary: {
Expand Down
14 changes: 7 additions & 7 deletions src/common/events/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import BaseEvent, { Events } from "./BaseEvent"

function subscribe(eventName: Events, listener: (event: CustomEvent<any>) => void) {
document.addEventListener(eventName, listener as () => void);
function subscribe(eventName: Events, listener: () => void) {
document.addEventListener(eventName, listener)
}

function unsubscribe(eventName: Events, listener: (event: CustomEvent<any>) => void) {
document.removeEventListener(eventName, listener as () => void);
function unsubscribe(eventName: Events, listener: () => void) {
document.removeEventListener(eventName, listener)
}

function publish<T>(event: BaseEvent<T>) {
const customEvent = new CustomEvent(event.name, {
detail: event.data
});
document.dispatchEvent(customEvent);
})
document.dispatchEvent(customEvent)
}

export { publish, subscribe, unsubscribe };
export { publish, subscribe, unsubscribe }
3 changes: 2 additions & 1 deletion src/common/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default async function fetcher<JSON = any>(
/* eslint-disable @typescript-eslint/no-explicit-any */
export default async function fetcher<JSON = any>(
input: RequestInfo,
init?: RequestInit
): Promise<JSON> {
Expand Down
Loading
Loading