Skip to content

Commit

Permalink
chore: migrate eslint config to esm (#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh authored Dec 18, 2024
1 parent 7b920f7 commit 7f01ec8
Show file tree
Hide file tree
Showing 36 changed files with 1,464 additions and 1,297 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
timeout-minutes: 20
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.40.0-jammy
image: mcr.microsoft.com/playwright:v1.49.0-jammy
env:
PLAYWRIGHT_TEST_BASE_URL: 'http://localhost:3000'
TURSO_CONNECTION_URL: 'http://libsql:8080'
Expand Down
2 changes: 1 addition & 1 deletion apps/rpl-crawler-cli/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../eslint.config')
export { default } from '@mach/shared-eslint-config'
1 change: 1 addition & 0 deletions apps/rpl-crawler-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@mach/rpl-crawler-cli",
"type": "module",
"scripts": {
"lint": "eslint .",
"pack": "vite build",
Expand Down
10 changes: 5 additions & 5 deletions apps/web-e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const eslintPluginPlaywright = require('eslint-plugin-playwright')
// @ts-check

module.exports = [
...require('../../eslint.config'),
eslintPluginPlaywright.configs['flat/recommended'],
]
import playwright from 'eslint-plugin-playwright'
import defaultConfigs from '../../eslint.config.js'

export default [...defaultConfigs, playwright.configs['flat/recommended']]
1 change: 1 addition & 0 deletions apps/web-e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@mach/web-e2e",
"type": "module",
"dependencies": {
"@mach/shared-database": "workspace:*"
},
Expand Down
8 changes: 6 additions & 2 deletions apps/web-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ dotenv.config()
const baseURL = process.env.BASE_URL ?? 'http://localhost:4200'

export default defineConfig({
...nxE2EPreset(__filename, { testDir: './src/specs' }),
globalSetup: require.resolve('./src/setup/global-setup.ts'),
...nxE2EPreset(import.meta.url.substring('file://'.length), {
testDir: './src/specs',
}),
globalSetup: import.meta
.resolve('./src/setup/global-setup.ts')
.substring('file://'.length),
use: {
baseURL,
trace: 'on-first-retry',
Expand Down
1 change: 0 additions & 1 deletion apps/web/eslint.config.cjs

This file was deleted.

1 change: 1 addition & 0 deletions apps/web/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@mach/shared-eslint-config'
File renamed without changes.
46 changes: 1 addition & 45 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,45 +1 @@
const eslint = require('@eslint/js')
const tsEslint = require('typescript-eslint')
const reactEslint = require('eslint-plugin-react/configs/recommended')
const nxEslint = require('@nx/eslint-plugin')

module.exports = tsEslint.config(
eslint.configs.recommended,
...tsEslint.configs.recommended,
{
...reactEslint,
rules: {
...reactEslint.rules,
'react/react-in-jsx-scope': 'off',
'react/jsx-no-target-blank': 'off',
},
},
{
plugins: {
'@nx': nxEslint,
},
rules: {
'@nx/enforce-module-boundaries': [
'error',
{
allow: [],
depConstraints: [
{
sourceTag: '*',
onlyDependOnLibsWithTags: ['*'],
},
{
sourceTag: 'type:feature',
onlyDependOnLibsWithTags: ['type:shared'],
},
{
sourceTag: 'type:shared',
onlyDependOnLibsWithTags: ['type:shared'],
},
],
},
],
},
},
{ ignores: ['**/eslint.config.js', '**/eslint.config.cjs', '**/dist'] }
)
export { default } from '@mach/shared-eslint-config'
2 changes: 1 addition & 1 deletion modules/rpl-crawler/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../eslint.config')
export { default } from '@mach/shared-eslint-config'
1 change: 1 addition & 0 deletions modules/rpl-crawler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@mach/rpl-crawler",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",
"scripts": {
"lint": "eslint .",
"test": "vitest --watch=false ."
Expand Down
8 changes: 4 additions & 4 deletions modules/rpl-crawler/src/flight-decoder/flight-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const makeFlightDecoder = ({ uuid }: { uuid: (line: string) => string }) => {
const cruisingSpeed = line.substring(46, 51)
const cruisingLevel = Number(line.substring(52, 55))
const route = line
.match(/(?<=[A-Z0-9]{4}\d{4} N\d{4} \d{3} ).+(?= {2})/)![0]
.match(/(?<=[A-Z0-9]{4}\d{4} N\d{4} \d{3} ).+(?= {2})/)[0]
.trim()
const rightPadStart = line.lastIndexOf(' ') + 2
const arrivalIcao = line.substring(rightPadStart, rightPadStart + 4).trim()
Expand All @@ -46,11 +46,11 @@ const makeFlightDecoder = ({ uuid }: { uuid: (line: string) => string }) => {
estimatedEnrouteMinutes,
remarks,
departureIcao,
aircraftIcaoCode: line.match(/[A-Z0-9]+(?=(\/(M|L|H|J)))/)![0],
aircraftEquipment: remarks.match(/(?<=EQPT\/)[^\s]+/)![0],
aircraftIcaoCode: line.match(/[A-Z0-9]+(?=(\/(M|L|H|J)))/)[0],
aircraftEquipment: remarks.match(/(?<=EQPT\/)[^\s]+/)[0],
aircraftWakeTurbulence: line.match(
/(?<=\/)(M|L|H|J)/
)![0] as WakeTurbulence,
)[0] as WakeTurbulence,
estimatedOffBlockTime,
flightRules: resolveFlightRules(route),
weekdays: resolveWeekDays(weekDays),
Expand Down
2 changes: 1 addition & 1 deletion modules/rpl-crawler/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Airport, Flight } from '@mach/shared-database'
import { fetchAirportsData } from './fetch-airports-data'
import Logger from './utils/logger'
import * as Logger from './utils/logger'

type MainDependencies = {
updateChecker: (date: string) => Promise<boolean>
Expand Down
2 changes: 1 addition & 1 deletion modules/rpl-crawler/src/save-data/save-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
flights as flightsSchema,
} from '@mach/shared-database'
import { inArray } from 'drizzle-orm'
import Logger from '../utils/logger'
import * as Logger from '../utils/logger'

function sliceArray<T>(items: T[]) {
const response: T[][] = []
Expand Down
30 changes: 13 additions & 17 deletions modules/rpl-crawler/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
class Logger {
private static formatMessage(level: LoggingLevel, message: string): string {
return `${new Date().toISOString()} - [${level}] - ${message}`
}
function formatMessage(level: LoggingLevel, message: string): string {
return `${new Date().toISOString()} - [${level}] - ${message}`
}

public static info(message: string): void {
console.info(Logger.formatMessage(LoggingLevel.INFO, message))
}
export function info(message: string): void {
console.info(formatMessage(LoggingLevel.INFO, message))
}

public static error(error: Error): void {
console.error(
`${Logger.formatMessage(
LoggingLevel.ERROR,
error.message
)} - ${JSON.stringify(error)}`
)
}
export function error(error: Error): void {
console.error(
`${formatMessage(
LoggingLevel.ERROR,
error.message
)} - ${JSON.stringify(error)}`
)
}

enum LoggingLevel {
INFO = 'INFO',
ERROR = 'ERROR',
}

export default Logger
2 changes: 1 addition & 1 deletion modules/shared-database/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../eslint.config')
export { default } from '@mach/shared-eslint-config'
1 change: 1 addition & 0 deletions modules/shared-database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@mach/shared-database",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",
"scripts": {
"lint": "eslint ."
},
Expand Down
54 changes: 54 additions & 0 deletions modules/shared-eslint-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @ts-check

import eslint from '@eslint/js'
import nxPlugin from '@nx/eslint-plugin'
import reactPlugin from 'eslint-plugin-react'
import tseslint from 'typescript-eslint'

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
{
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
},
},
reactPlugin.configs.flat.recommended,
{
settings: {
react: {
version: '18.3.1',
},
},
},
reactPlugin.configs.flat['jsx-runtime'],
{ plugins: { '@nx': nxPlugin } },
{
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],

rules: {
'@nx/enforce-module-boundaries': [
'error',
{
allow: [],
depConstraints: [
{
sourceTag: '*',
onlyDependOnLibsWithTags: ['*'],
},
{
sourceTag: 'type:feature',
onlyDependOnLibsWithTags: ['type:shared'],
},
{
sourceTag: 'type:shared',
onlyDependOnLibsWithTags: ['type:shared'],
},
],
},
],
},
},
{ ignores: ['**/eslint.config.js', '**/dist'] }
)
16 changes: 16 additions & 0 deletions modules/shared-eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@mach/shared-eslint-config",
"type": "module",
"main": "eslint.config.js",
"devDependencies": {
"@eslint/js": "~9.13.0",
"@nx/eslint-plugin": "20.0.12",
"eslint": "^9.14.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jsx-a11y": "6.10.0",
"eslint-plugin-playwright": "^2.0.0",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "5.0.0",
"typescript-eslint": "^8.10.0"
}
}
2 changes: 1 addition & 1 deletion modules/web-details/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../eslint.config')
export { default } from '@mach/shared-eslint-config'
1 change: 1 addition & 0 deletions modules/web-details/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@mach/web-details",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",
"scripts": {
"lint": "eslint .",
"test": "vitest --watch=false ."
Expand Down
2 changes: 1 addition & 1 deletion modules/web-details/src/views/ivao-fpl-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function IvaoFplButton({ flight }: Props) {

return (
<Button asChild variant="primary">
<a href={url.toString()} target="_blank">
<a href={url.toString()} target="_blank" rel="noreferrer">
IVAO FP
</a>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion modules/web-details/src/views/simbrief-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function SimBriefButton({ flight }: Props) {

return (
<Button asChild>
<a href={simBriefLink} target="_blank">
<a href={simBriefLink} target="_blank" rel="noreferrer">
SimBrief
</a>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion modules/web-details/src/views/sky-vector-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function SkyVectorButton({ flight }: Props) {

return (
<Button asChild>
<a href={skyVectorLink} target="_blank">
<a href={skyVectorLink} target="_blank" rel="noreferrer">
SkyVector
</a>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion modules/web-details/src/views/vatsim-fpl-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function VatsimFplButton({ flight }: Props) {

return (
<Button asChild>
<a href={vatsimLink} target="_blank">
<a href={vatsimLink} target="_blank" rel="noreferrer">
Vatsim FP
</a>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion modules/web-home/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../eslint.config')
export { default } from '@mach/shared-eslint-config'
1 change: 1 addition & 0 deletions modules/web-home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@mach/web-home",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",
"scripts": {
"lint": "eslint .",
"test": "vitest --watch=false ."
Expand Down
2 changes: 1 addition & 1 deletion modules/web-search/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../eslint.config')
export { default } from '@mach/shared-eslint-config'
1 change: 1 addition & 0 deletions modules/web-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@mach/web-search",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",
"scripts": {
"lint": "eslint .",
"test": "vitest --watch=false ."
Expand Down
1 change: 0 additions & 1 deletion modules/web-shared-ui/eslint.config.cjs

This file was deleted.

1 change: 1 addition & 0 deletions modules/web-shared-ui/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@mach/shared-eslint-config'
8 changes: 6 additions & 2 deletions modules/web-shared-ui/src/components/layout/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ export function Footer() {
return (
<Container>
<p>
<Link href="https://github.com/jpedroh/mach/" target="_blank">
<Link
href="https://github.com/jpedroh/mach/"
target="_blank"
rel="noreferrer"
>
Mach
</Link>
{' - '}
Use for flight simulation only
</p>
<p>
Developed by{' '}
<Link href="https://jpedroh.dev" target="_blank">
<Link href="https://jpedroh.dev" target="_blank" rel="noreferrer">
João Pedro Henrique
</Link>
</p>
Expand Down
Loading

0 comments on commit 7f01ec8

Please sign in to comment.