Skip to content

Commit 566ff3f

Browse files
authored
Merge pull request #614 from shapehq/enhancement/migrate-to-es-lint
Migrates from `next lint` to `eslint`
2 parents 59fae5e + c2961c0 commit 566ff3f

File tree

14 files changed

+103
-34
lines changed

14 files changed

+103
-34
lines changed

__test__/auth/AuthjsAccountsOAuthTokenRepository.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test("It gets token for user ID and provider", async () => {
1414
async disconnect() {},
1515
}
1616
},
17-
async query(_query, values: any[] = []) {
17+
async query(_query, values: readonly unknown[] = []) {
1818
queryProvider = values[0]
1919
queryUserId = values[1]
2020
return {
@@ -44,7 +44,7 @@ test("It does not set token", async () => {
4444
async disconnect() {},
4545
}
4646
},
47-
async query(_query, _values: any[] = []) {
47+
async query(_query, _values: readonly unknown[] = []) {
4848
didSetToken = true
4949
return { rows: [] }
5050
}
@@ -67,7 +67,7 @@ test("It does not delete token", async () => {
6767
async disconnect() {},
6868
}
6969
},
70-
async query(_query, _values: any[] = []) {
70+
async query(_query, _values: readonly unknown[] = []) {
7171
didDeleteToken = true
7272
return { rows: [] }
7373
}

__test__/auth/OAuthTokenRepository.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ test("It reads the auth token for the specified user", async () => {
88
db: {
99
async connect() {
1010
return {
11-
async query(_query: string, _values: any[] = []) {
11+
async query(_query: string, _values: readonly unknown[] = []) {
1212
return { rows: [] }
1313
},
1414
async disconnect() {},
1515
}
1616
},
17-
async query(_query: string, values: any[] = []) {
17+
async query(_query: string, values: [string, string]) {
1818
readProvider = values[0]
1919
readUserId = values[1]
2020
return {
@@ -36,20 +36,20 @@ test("It reads the auth token for the specified user", async () => {
3636
test("It stores the auth token for the specified user", async () => {
3737
let storedProvider: string | undefined
3838
let storedUserId: string | undefined
39-
let storedAccessToken: any | undefined
40-
let storedRefreshToken: any | undefined
39+
let storedAccessToken: string | undefined
40+
let storedRefreshToken: string | undefined
4141
const sut = new OAuthTokenRepository({
4242
provider: "github",
4343
db: {
4444
async connect() {
4545
return {
46-
async query(_query: string, _values: any[] = []) {
46+
async query(_query: string, _values: readonly unknown[] = []) {
4747
return { rows: [] }
4848
},
4949
async disconnect() {},
5050
}
5151
},
52-
async query(_query: string, values: any[] = []) {
52+
async query(_query: string, values: [string, string, string, string]) {
5353
storedProvider = values[0]
5454
storedUserId = values[1]
5555
storedAccessToken = values[2]
@@ -76,13 +76,13 @@ test("It deletes the auth token for the specified user", async () => {
7676
db: {
7777
async connect() {
7878
return {
79-
async query(_query: string, _values: any[] = []) {
79+
async query(_query: string, _values: readonly unknown[] = []) {
8080
return { rows: [] }
8181
},
8282
async disconnect() {},
8383
}
8484
},
85-
async query(_query: string, values: any[] = []) {
85+
async query(_query: string, values: [string, string]) {
8686
deletedUserId = values[1]
8787
return { rows: [] }
8888
}

__test__/common/github/OAuthTokenRefreshingGitHubClient.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ test("It does not refresh an OAuth token when the initial request was successful
285285
},
286286
oauthTokenRefresher: {
287287
async refreshOAuthToken(_refreshToken) {
288+
didRefreshOAuthToken = true
288289
return {
289290
accessToken: "newAccessToken",
290291
refreshToken: "newRefreshToken"

__test__/common/utils/saneParseInt.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { saneParseInt } from "@/common"
22

33
test("It parses an integer", async () => {
4-
// @ts-ignore
4+
// @ts-expect-error - verifying that non-string input is rejected
55
const val = saneParseInt(42 as string)
66
expect(val).toBe(42)
77
})

__test__/projects/GitHubRepositoryDataSource.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test("It queries for both .yml and .yaml file extension with no extension", asyn
189189
})
190190

191191
test("It loads repositories for all logins", async () => {
192-
let searchQueries: string[] = []
192+
const searchQueries: string[] = []
193193
const sut = new GitHubRepositoryDataSource({
194194
repositoryNameSuffix: "-openapi",
195195
projectConfigurationFilename: ".demo-docs",

eslint.config.mjs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { defineConfig } from "eslint/config"
2+
import typescriptEslint from "@typescript-eslint/eslint-plugin"
3+
import tsParser from "@typescript-eslint/parser"
4+
import path from "node:path"
5+
import { fileURLToPath } from "node:url"
6+
import js from "@eslint/js"
7+
import { FlatCompat } from "@eslint/eslintrc"
8+
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = path.dirname(__filename)
11+
const compat = new FlatCompat({
12+
baseDirectory: __dirname,
13+
recommendedConfig: js.configs.recommended,
14+
allConfig: js.configs.all
15+
})
16+
17+
export default defineConfig([
18+
{
19+
ignores: ["next-env.d.ts", ".next"],
20+
},
21+
{
22+
extends: [
23+
...compat.extends("next/core-web-vitals"),
24+
...compat.extends("eslint:recommended"),
25+
...compat.extends("plugin:@typescript-eslint/recommended")
26+
],
27+
28+
plugins: {
29+
"@typescript-eslint": typescriptEslint,
30+
},
31+
32+
languageOptions: {
33+
parser: tsParser,
34+
},
35+
36+
rules: {
37+
"array-callback-return": ["error"],
38+
"no-await-in-loop": ["error"],
39+
"no-constant-binary-expression": ["error"],
40+
"no-constructor-return": ["error"],
41+
"no-duplicate-imports": ["error"],
42+
"no-new-native-nonconstructor": ["error"],
43+
"no-self-compare": ["error"],
44+
"no-template-curly-in-string": ["error"],
45+
"no-unmodified-loop-condition": ["error"],
46+
"no-unreachable-loop": ["error"],
47+
"no-unused-private-class-members": ["error"],
48+
"require-atomic-updates": ["error"],
49+
50+
"@typescript-eslint/no-unused-vars": ["error", {
51+
argsIgnorePattern: "^_",
52+
}],
53+
},
54+
}
55+
])

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dev": "next dev",
1111
"build": "next build",
1212
"start": "next start",
13-
"lint": "next lint --max-warnings=0",
13+
"lint": "eslint --max-warnings=0 .",
1414
"test": "node --experimental-vm-modules ./node_modules/.bin/jest",
1515
"testwatch": "node --experimental-vm-modules ./node_modules/.bin/jest --watch"
1616
},

src/common/utils/fileUtils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export async function downloadFile(params: {
3636
let didExceedMaxBytes = false;
3737
const reader = response.body.getReader();
3838
const chunks: Uint8Array[] = [];
39-
// eslint-disable-next-line no-constant-condition
4039
while (true) {
4140
// eslint-disable-next-line no-await-in-loop
4241
const { done, value } = await reader.read();
@@ -55,11 +54,15 @@ export async function downloadFile(params: {
5554
const error = new Error("Maximum file size exceeded");
5655
error.name = ErrorName.MAX_FILE_SIZE_EXCEEDED;
5756
throw error;
57+
}
58+
const allBytes = new Uint8Array(totalBytes);
59+
let offset = 0;
60+
for (const chunk of chunks) {
61+
allBytes.set(chunk, offset);
62+
offset += chunk.length;
5863
}
59-
const blob = new Blob(chunks);
60-
const arrayBuffer = await blob.arrayBuffer();
6164
const decoder = new TextDecoder();
62-
return decoder.decode(arrayBuffer);
65+
return decoder.decode(allBytes);
6366
}
6467

6568
export function checkIfJsonOrYaml(fileText: string) {

src/features/auth/view/SignInTexts.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import { BASE_COLORS } from "@/common/theme/theme"
44
import { Box, Typography, SxProps } from "@mui/material"
55
import { useEffect, useState, useMemo } from "react"
66

7+
const getRandomTextColor = ({ excluding }: { excluding?: string } = {}) => {
8+
const colors = BASE_COLORS
9+
.filter(e => e !== excluding)
10+
return colors[Math.floor(Math.random() * colors.length)]
11+
}
12+
13+
const INITIAL_TEXT_COLOR = getRandomTextColor()
14+
715
const SignInTexts = ({ prefix }: { prefix: string }) => {
8-
const getRandomTextColor = ({ excluding }: { excluding?: string }) => {
9-
const colors = BASE_COLORS
10-
.filter(e => e !== excluding)
11-
return colors[Math.floor(Math.random() * colors.length)]
12-
}
1316
const [characterIndex, setCharacterIndex] = useState(0)
1417
const [textIndex, setTextIndex] = useState(0)
1518
const [displayedText, setDisplayedText] = useState("")
16-
const [textColor, setTextColor] = useState(getRandomTextColor({}))
19+
const [textColor, setTextColor] = useState(INITIAL_TEXT_COLOR)
1720
const texts = useMemo(() => [
1821
"is a great OpenAPI viewer",
1922
"facilitates spec-driven development",

src/features/encrypt/view/EncryptionForm.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { encrypt } from "./encryptAction"
77
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
88
import { faClipboard } from "@fortawesome/free-regular-svg-icons"
99

10+
const EncryptedValueTextField = styled(TextField)({
11+
'& .MuiInputBase-root': {
12+
backgroundColor: '#F8F8F8'
13+
}
14+
})
15+
1016
export const EncryptionForm = () => {
1117
const [inputText, setInputText] = useState('')
1218
const [encryptedText, setEncryptedText] = useState('')
@@ -32,12 +38,6 @@ export const EncryptionForm = () => {
3238
const handleCloseSnackbar = () => {
3339
setOpenSnackbar(false)
3440
}
35-
36-
const EncryptedValueTextField = styled(TextField)({
37-
'& .MuiInputBase-root': {
38-
backgroundColor: '#F8F8F8'
39-
}
40-
})
4141

4242
return <Box
4343
component="form"

0 commit comments

Comments
 (0)