Skip to content

Commit

Permalink
Add ruele '"curly": "error"'
Browse files Browse the repository at this point in the history
  • Loading branch information
KristjanESPERANTO committed Dec 10, 2023
1 parent 37e9e48 commit 300a3e4
Show file tree
Hide file tree
Showing 54 changed files with 637 additions and 228 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ignoreRestSiblings": false
}
],
"curly": "error",
"@stylistic/array-bracket-newline": ["error", "consistent"],
"@stylistic/array-element-newline": ["error", "consistent"],
"@stylistic/arrow-parens": "off",
Expand Down
4 changes: 3 additions & 1 deletion format/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const formatAddress = (a) => {
X: formatCoord(a.longitude),
Y: formatCoord(a.latitude),
}
if (a.id) data.L = a.id
if (a.id) {
data.L = a.id
}
return {
type: 'A', // address
name: a.address,
Expand Down
5 changes: 3 additions & 2 deletions format/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
// todo: change to `(profile) => (when) => {}`
const formatDate = (profile, when) => {
let timezone
if (timezones.has(profile)) timezone = timezones.get(profile)
else {
if (timezones.has(profile)) {
timezone = timezones.get(profile)
} else {
timezone = new IANAZone(profile.timezone)
timezones.set(profile, timezone)
}
Expand Down
4 changes: 3 additions & 1 deletion format/location-filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const formatLocationFilter = (stops, addresses, poi) => {
if (stops && addresses && poi) return 'ALL'
if (stops && addresses && poi) {
return 'ALL'
}
return (stops
? 'S'
: '') + (addresses
Expand Down
4 changes: 3 additions & 1 deletion format/location-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const sep = '@'
const formatLocationIdentifier = (data) => {
let str = ''
for (let key in data) {
if (!Object.prototype.hasOwnProperty.call(data, key)) continue
if (!Object.prototype.hasOwnProperty.call(data, key)) {
continue
}

str += key + '=' + data[key] + sep // todo: escape, but how?
}
Expand Down
16 changes: 12 additions & 4 deletions format/location.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const formatLocation = (profile, l, name = 'location') => {
if ('string' === typeof l) return profile.formatStation(l)
if ('string' === typeof l) {
return profile.formatStation(l)
}
if ('object' === typeof l && !Array.isArray(l)) {
if (l.type === 'station' || l.type === 'stop') {
return profile.formatStation(l.id)
}
if (l.poi) return profile.formatPoi(l)
if ('string' === typeof l.address) return profile.formatAddress(l)
if (!l.type) throw new TypeError(`missing ${name}.type`)
if (l.poi) {
return profile.formatPoi(l)
}
if ('string' === typeof l.address) {
return profile.formatAddress(l)
}
if (!l.type) {
throw new TypeError(`missing ${name}.type`)
}
throw new TypeError(`invalid ${name}.type: ${l.type}`)
}
throw new TypeError(name + ': valid station, address or poi required.')
Expand Down
20 changes: 15 additions & 5 deletions format/products-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import isObj from 'lodash/isObject.js'
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k)

const formatProductsFilter = (ctx, filter) => {
if (!isObj(filter)) throw new TypeError('products filter must be an object')
if (!isObj(filter)) {
throw new TypeError('products filter must be an object')
}
const {profile} = ctx

const byProduct = {}
Expand All @@ -16,12 +18,20 @@ const formatProductsFilter = (ctx, filter) => {

let res = 0, products = 0
for (let product in filter) {
if (!hasProp(filter, product) || filter[product] !== true) continue
if (!byProduct[product]) throw new TypeError('unknown product ' + product)
if (!hasProp(filter, product) || filter[product] !== true) {
continue
}
if (!byProduct[product]) {
throw new TypeError('unknown product ' + product)
}
products++
for (let bitmask of byProduct[product].bitmasks) res = res | bitmask
for (let bitmask of byProduct[product].bitmasks) {
res = res | bitmask
}
}
if (products === 0) {
throw new Error('no products used')
}
if (products === 0) throw new Error('no products used')

return {
type: 'PROD',
Expand Down
8 changes: 6 additions & 2 deletions format/remarks-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ const formatRemarksReq = (ctx) => {
const req = {
himFltrL,
}
if (profile.remarksGetPolyline) req.getPolyline = !!opt.polylines
if (profile.remarksGetPolyline) {
req.getPolyline = !!opt.polylines
}
// todo: stLoc, dirLoc
// todo: comp, dept, onlyHimId, onlyToday
// todo: dailyB, dailyE
// see https://github.com/marudor/BahnhofsAbfahrten/blob/46a74957d68edc15713112df44e1a25150f5a178/src/types/HAFAS/HimSearch.ts#L3-L18

if (opt.results !== null) req.maxNum = opt.results
if (opt.results !== null) {
req.maxNum = opt.results
}
if (opt.from !== null) {
req.dateB = profile.formatDate(profile, opt.from)
req.timeB = profile.formatTime(profile, opt.from)
Expand Down
8 changes: 6 additions & 2 deletions format/station-board-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ const formatStationBoardReq = (ctx, station, type) => {
? 10000
: opt.results
}
if (profile.departuresGetPasslist) req.getPasslist = !!opt.stopovers
if (profile.departuresStbFltrEquiv) req.stbFltrEquiv = !opt.includeRelatedStations
if (profile.departuresGetPasslist) {
req.getPasslist = !!opt.stopovers
}
if (profile.departuresStbFltrEquiv) {
req.stbFltrEquiv = !opt.includeRelatedStations
}

return {
meth: 'StationBoard',
Expand Down
5 changes: 3 additions & 2 deletions format/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
// todo: change to `(profile) => (when) => {}`
const formatTime = (profile, when) => {
let timezone
if (timezones.has(profile)) timezone = timezones.get(profile)
else {
if (timezones.has(profile)) {
timezone = timezones.get(profile)
} else {
timezone = new IANAZone(profile.timezone)
timezones.set(profile, timezone)
}
Expand Down
Loading

0 comments on commit 300a3e4

Please sign in to comment.