Skip to content

Commit 83d00e3

Browse files
authored
Merge pull request #169 from neaps/prettier
Add prettier, update eslint
2 parents 271bcf8 + 8b6f6b7 commit 83d00e3

17 files changed

Lines changed: 124 additions & 110 deletions

File tree

.eslintrc.cjs

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/dependabot.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "npm"
4-
directory: "/"
3+
- package-ecosystem: 'npm'
4+
directory: '/'
55
schedule:
6-
interval: "weekly"
6+
interval: 'weekly'
77
open-pull-requests-limit: 100
8-
- package-ecosystem: "github-actions"
9-
directory: "/"
8+
- package-ecosystem: 'github-actions'
9+
directory: '/'
1010
schedule:
11-
interval: "weekly"
11+
interval: 'weekly'
1212
open-pull-requests-limit: 100

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
.test-cache

.prettierrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 100
3+
}

eslint.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import eslint from '@eslint/js'
2+
import tseslint from 'typescript-eslint'
3+
import prettier from 'eslint-config-prettier'
4+
5+
export default [
6+
{ ignores: ['dist/', 'node_modules/'] },
7+
eslint.configs.recommended,
8+
...tseslint.configs.recommended,
9+
prettier,
10+
{ files: ['**/*.ts'], languageOptions: { parser: tseslint.parser } },
11+
{ files: ['**/*.js'] }
12+
]

index.html

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,54 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
3+
<head>
4+
<title>Tide Predictor in the browser</title>
5+
<link
6+
rel="stylesheet"
7+
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
8+
/>
9+
</head>
310

4-
<head>
5-
<title>Tide Predictor in the browser</title>
6-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
7-
</head>
11+
<body>
12+
<div class="container">
13+
<h1>High/low tides for Monterey, CA</h1>
14+
<table class="table">
15+
<thead>
16+
<tr>
17+
<th>Time</th>
18+
<th>High/Low</th>
19+
<th>Level (meters)</th>
20+
</tr>
21+
</thead>
22+
<tbody id="tides"></tbody>
23+
</table>
24+
</div>
825

9-
<body>
10-
<div class="container">
11-
<h1>High/low tides for Monterey, CA</h1>
12-
<table class="table">
13-
<thead>
14-
<tr>
15-
<th>Time</th>
16-
<th>High/Low</th>
17-
<th>Level (meters)</th>
18-
</tr>
19-
<tbody id="tides"></tbody>
20-
</thead>
21-
</table>
22-
</div>
23-
24-
<script type="module">
25-
import tidePredictor from './src/index.js'
26-
27-
(() => {
28-
fetch('https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/stations/9413450/harcon.json?units=metric')
29-
.then(response => {
26+
<script type="module">
27+
import tidePredictor from './src/index.js'
28+
fetch(
29+
'https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/stations/9413450/harcon.json?units=metric'
30+
)
31+
.then((response) => {
3032
return response.json()
3133
})
32-
.then(harmonics => {
34+
.then((harmonics) => {
3335
const start = new Date()
34-
const end = new Date(start.getTime() + (10 * 24 * 60 * 60 * 1000))
36+
const end = new Date(start.getTime() + 10 * 24 * 60 * 60 * 1000)
3537

36-
const highLow = tidePredictor(harmonics.HarmonicConstituents).getExtremesPrediction({ start, end })
38+
const highLow = tidePredictor(
39+
harmonics.HarmonicConstituents
40+
).getExtremesPrediction({ start, end })
3741

38-
highLow.forEach(level => {
42+
highLow.forEach((level) => {
3943
const tableRow = document.createElement('tr')
4044
tableRow.innerHTML = `
41-
<td>${level
42-
.time}</td>
43-
<td>${level
44-
.label}</td>
45-
<td>${level
46-
.level}</td>
45+
<td>${level.time}</td>
46+
<td>${level.label}</td>
47+
<td>${level.level}</td>
4748
`
48-
document
49-
.getElementById('tides')
50-
.appendChild(tableRow)
49+
document.getElementById('tides').appendChild(tableRow)
5150
})
5251
})
53-
})()
54-
</script>
55-
</body>
56-
52+
</script>
53+
</body>
5754
</html>

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
"dist"
1919
],
2020
"devDependencies": {
21+
"@eslint/js": "^9.39.2",
2122
"@types/node": "^20.10.6",
22-
"@typescript-eslint/eslint-plugin": "^7.0.0",
23-
"@typescript-eslint/parser": "^7.0.0",
2423
"@vitest/coverage-v8": "^3.0.0",
25-
"eslint": "^8.18.0",
24+
"eslint": "^9.39.2",
25+
"eslint-config-prettier": "^10.1.8",
2626
"npm-run-all": "^4.1.5",
27+
"prettier": "^3.7.4",
2728
"typescript": "^5.3.3",
29+
"typescript-eslint": "^8.49.0",
2830
"vite": "^7.2.7",
2931
"vite-plugin-dts": "^4.5.4",
3032
"vitest": "^3.0.0"
@@ -33,7 +35,8 @@
3335
"dev": "vite",
3436
"build": "vite build",
3537
"test": "vitest",
36-
"lint": "eslint ./src --ext .ts,.tsx,.js",
38+
"lint": "eslint && prettier --check .",
39+
"format": "prettier --write .",
3740
"coverage": "vitest run --coverage",
3841
"ci": "run-s lint build coverage",
3942
"prepare": "npm run build"

src/astronomy/index.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ const modulus = (a: number, b: number): number => {
146146
}
147147

148148
const astro = (time: Date): AstroData => {
149-
const result: Partial<AstroData> = {}
149+
// This gets cast to `AstroData` later, but we build it up step by step here
150+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
151+
const result: any = {}
152+
150153
const polynomials: Record<string, number[]> = {
151154
s: coefficients.lunarLongitude,
152155
h: coefficients.solarLongitude,
@@ -161,12 +164,12 @@ const astro = (time: Date): AstroData => {
161164
// Polynomials are in T, that is Julian Centuries; we want our speeds to be
162165
// in the more convenient unit of degrees per hour.
163166
const dTdHour = 1 / (24 * 365.25 * 100)
164-
Object.keys(polynomials).forEach((name) => {
165-
;(result as any)[name] = {
167+
for (const name in polynomials) {
168+
result[name] = {
166169
value: modulus(polynomial(polynomials[name], T(time)), 360.0),
167170
speed: derivativePolynomial(polynomials[name], T(time)) * dTdHour
168171
}
169-
})
172+
}
170173

171174
// Some other parameters defined by Schureman which are dependent on the
172175
// parameters N, i, omega for use in node factor calculations. We don't need
@@ -183,13 +186,9 @@ const astro = (time: Date): AstroData => {
183186
}
184187
Object.keys(functions).forEach((name) => {
185188
const functionCall = functions[name]
186-
;(result as any)[name] = {
189+
result[name] = {
187190
value: modulus(
188-
functionCall(
189-
(result as any).N.value,
190-
(result as any).i.value,
191-
(result as any).omega.value
192-
),
191+
functionCall(result.N.value, result.i.value, result.omega.value),
193192
360.0
194193
),
195194
speed: null
@@ -204,16 +203,16 @@ const astro = (time: Date): AstroData => {
204203
speed: 15.0
205204
}
206205

207-
;(result as any)['T+h-s'] = {
208-
value: hour.value + (result as any).h.value - (result as any).s.value,
209-
speed: hour.speed + (result as any).h.speed - (result as any).s.speed
206+
result['T+h-s'] = {
207+
value: hour.value + result.h.value - result.s.value,
208+
speed: hour.speed + result.h.speed - result.s.speed
210209
}
211210

212211
// It is convenient to calculate Schureman's P here since several node
213212
// factors need it, although it could be argued that these
214213
// (along with I, xi, nu etc) belong somewhere else.
215-
;(result as any).P = {
216-
value: (result as any).p.value - ((result as any).xi.value % 360.0),
214+
result.P = {
215+
value: result.p.value - (result.xi.value % 360.0),
217216
speed: null
218217
}
219218

src/harmonics/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import prediction from './prediction.js'
22
import constituentModels from '../constituents/index.js'
33
import { d2r } from '../astronomy/constants.js'
4-
import type { Prediction } from './prediction.js'
4+
import type {
5+
HarmonicConstituent,
6+
InternalHarmonicConstituent,
7+
Prediction
8+
} from './prediction.js'
59

6-
export interface HarmonicConstituent {
7-
name: string
8-
amplitude?: number
9-
[key: string]: any
10-
}
10+
export type * from './prediction.js'
1111

1212
export interface HarmonicsOptions {
1313
harmonicConstituents: HarmonicConstituent[]
@@ -60,15 +60,17 @@ const harmonicsFactory = ({
6060
if (!Array.isArray(harmonicConstituents)) {
6161
throw new Error('Harmonic constituents are not an array')
6262
}
63-
const constituents: any[] = []
63+
const constituents: InternalHarmonicConstituent[] = []
6464
harmonicConstituents.forEach((constituent) => {
6565
if (typeof constituent.name === 'undefined') {
6666
throw new Error('Harmonic constituents must have a name property')
6767
}
68-
if (typeof constituentModels[constituent.name] !== 'undefined') {
69-
constituent._model = constituentModels[constituent.name]
70-
constituent._phase = d2r * constituent[phaseKey]
71-
constituents.push(constituent)
68+
if (constituentModels[constituent.name] !== undefined) {
69+
constituents.push({
70+
...constituent,
71+
_model: constituentModels[constituent.name],
72+
_phase: d2r * constituent[phaseKey]
73+
})
7274
}
7375
})
7476

src/harmonics/prediction.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ export interface Timeline {
1111
export interface HarmonicConstituent {
1212
name: string
1313
amplitude: number
14+
// This needs refactored to support generics with the `phaseKey` option
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
[key: string]: any
17+
}
18+
19+
export interface InternalHarmonicConstituent extends HarmonicConstituent {
1420
_phase: number
1521
_model: Constituent | CompoundConstituent
16-
[key: string]: any
1722
}
1823

1924
export interface TimelinePoint {
@@ -105,7 +110,7 @@ const getExtremeLabel = (
105110

106111
interface PredictionFactoryParams {
107112
timeline: Timeline
108-
constituents: HarmonicConstituent[]
113+
constituents: InternalHarmonicConstituent[]
109114
start: Date
110115
}
111116

0 commit comments

Comments
 (0)