Skip to content

Commit

Permalink
chore: add eslint configuration (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh authored Sep 17, 2023
1 parent 4259cc1 commit 76d02f4
Show file tree
Hide file tree
Showing 14 changed files with 1,358 additions and 51 deletions.
32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@next/next/recommended',
],
overrides: [
{
env: {
node: true,
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'react'],
rules: {
'@next/next/no-html-link-for-pages': ['error', 'packages/app'],
},
}
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
AISWEB_API_PASSWORD: ${{ secrets.aisweb_api_password }}
RPL_DATE: ${{ github.event.inputs.date }}
- run: pnpm test
- run: pnpm lint
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
"@types/node": "^20.6.0",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"autoprefixer": "^10.4.15",
"conventional-changelog-conventionalcommits": "^7.0.2",
"drizzle-kit": "^0.19.13",
"esbuild": "^0.19.3",
"eslint": "^8.49.0",
"eslint-config-next": "^13.4.19",
"eslint-plugin-react": "^7.33.2",
"nx": "16.8.1",
"pg-hstore": "^2.3.3",
"postcss": "^8.4.29",
Expand All @@ -45,6 +50,7 @@
"scripts": {
"serve": "nx run @mach/app:dev",
"build": "nx run-many --target=build",
"lint": "eslint .",
"test": "vitest"
},
"workspaces": {
Expand Down
6 changes: 0 additions & 6 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
"build": "next build",
"start": "next start"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand Down
10 changes: 6 additions & 4 deletions packages/app/src/components/SelectInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Select from 'react-select'

export function SelectInput<Option>(props: {
type Option = { value: string; label: string }

export function SelectInput(props: {
options: Option[]
onChange: (value: string) => void
name: string
}) {
return (
<Select
<Select<Option>
options={props.options}
name={props.name}
unstyled
Expand All @@ -20,15 +22,15 @@ export function SelectInput<Option>(props: {
return className
},
option(props) {
let className = `py-2 px-4 ${
const className = `py-2 px-4 ${
props.isFocused
? 'bg-blue-600 text-white'
: 'bg-white dark:bg-gray-600 dark:text-gray-200'
}`
return className
},
}}
onChange={(evt: any) => props.onChange(!!evt ? evt.value : '')}
onChange={(evt) => props.onChange(evt?.value ?? '')}
></Select>
)
}
12 changes: 6 additions & 6 deletions packages/app/src/components/SimBriefButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ type Props = {
}

const VatsimButton: FC<Props> = ({ flight }) => {
const query = {
const query: Record<string, string> = {
airline: flight.company,
fltnum: flight.flightNumber,
fltnum: flight.flightNumber.toString(),
type: flight.aircraft.icaoCode,
orig: flight.departureIcao,
dest: flight.arrivalIcao,
deph: flight.estimatedOffBlockTime.substr(0, 2),
depm: flight.estimatedOffBlockTime.substr(2, 2),
route: flight.route,
steh: Math.floor(flight.estimatedEnrouteMinutes / 60),
stem: flight.estimatedEnrouteMinutes % 60,
fl: flight.cruisingLevel * 100,
steh: Math.floor(flight.estimatedEnrouteMinutes / 60).toString(),
stem: (flight.estimatedEnrouteMinutes % 60).toString(),
fl: (flight.cruisingLevel ** 100).toString(),
manualrmk: flight.remarks,
}

const simBriefLink = `http://www.simbrief.com/system/dispatch.php?${new URLSearchParams(
query as any
query
).toString()}`

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/services/fetch-aircraft-icao-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { sql } from 'drizzle-orm'
export async function fetchAircraftIcaoCodes() {
const aircrafts = await db
.select({
aircraftIcaoCode: sql`DISTINCT(${flights.aircraft}->>"$.icaoCode")`,
aircraftIcaoCode: sql<string>`DISTINCT(${flights.aircraft}->>"$.icaoCode")`,
})
.from(flights)

return aircrafts?.map((v: any) => v.aircraftIcaoCode) ?? []
return aircrafts?.map((v) => v.aircraftIcaoCode) ?? []
}
13 changes: 5 additions & 8 deletions packages/app/src/utils/http.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
function http<R = any, T = any>({
url,
query,
}: {
url: string
query: T
}): Promise<R> {
const fullUrl = `${url}?${new URLSearchParams(query as any).toString()}`
function http<
R = unknown,
T extends Record<string, string> = Record<string, string>,
>({ url, query }: { url: string; query: T }): Promise<R> {
const fullUrl = `${url}?${new URLSearchParams(query).toString()}`
console.log(`Making HTTP request to ${fullUrl}`)

return fetch(fullUrl, { cache: 'no-store' }).then((response) =>
Expand Down
1 change: 1 addition & 0 deletions packages/database/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const credentialsSchema = z
const connection = connect({
...credentialsSchema.parse(process.env),
fetch: (url, init) => {
// eslint-disable-next-line
delete (init as any)['cache'] // Remove cache header
// @ts-expect-error missing fetch
return fetch(url, init)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest'
import makeFlightDecoder from './flight-decoder'

describe('flight-decoder', () => {
const flightDecoder = makeFlightDecoder({ uuid: (_) => randomUUID() })
const flightDecoder = makeFlightDecoder({ uuid: () => randomUUID() })

test('Given flight with begin and end date', () => {
const line = `#C 230720 TAM3587 26 230720 011020 IS A321/M SW/C SBRF 0005
Expand Down
1 change: 0 additions & 1 deletion packages/rpl-crawler/src/flight-decoder/flight-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const makeFlightDecoder = ({ uuid }: { uuid: (line: string) => string }) => {
const flightNumber = Number(callsign.match(/\d+/)[0])
const departureIcao = LINE_1.substr(-9, 4)
const estimatedOffBlockTime = LINE_1.match(/\d{4}$/)[0]
const flightRules = LINE_1.match(/(?<= ).(?=[A-Z] )/)[0]
const weekDays = LINE_1.match(/(?<= )(\d| ){7}(?= )/)[0].trim()

const LINE_2 = LINES[1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Axios from 'axios'

type HttpClient = {
get: (
url: string,
Expand All @@ -11,7 +9,7 @@ const firRplFileDownloader = ({ http }: { http: HttpClient }) => {
return async (fir: string, date: string) => {
const fileLink = `http://portal.cgna.decea.mil.br/files/abas/${date}/painel_rpl/bdr/RPL${fir}.zip`

const { data } = await Axios.get(fileLink, {
const { data } = await http.get(fileLink, {
responseType: 'arraybuffer',
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { describe, expect, test, vi } from 'vitest'
import makeUpdateChecker from './update-checker'

describe('update-checker', () => {
let httpMock = {
const httpMock = {
get: vi.fn(),
}
let updateChecker = makeUpdateChecker({ http: httpMock })
const updateChecker = makeUpdateChecker({ http: httpMock })

describe('Given a date with no updates was given', () => {
const date = '2020-08-02'
Expand Down
Loading

0 comments on commit 76d02f4

Please sign in to comment.