Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ESLint and add Stylistic Formatting #305

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"extends": ["eslint:recommended", "plugin:@stylistic/all-extends"],
"ignorePatterns": ["node_modules", "*example.js"],
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
},
"rules": {
"curly": "error",
"no-implicit-coercion": "error",
"no-unused-vars": [
"error",
{
"vars": "all",
"args": "none",
"ignoreRestSiblings": false
}
]
],
"@stylistic/array-bracket-newline": ["error", "consistent"],
"@stylistic/array-element-newline": ["error", "consistent"],
"@stylistic/arrow-parens": "off",
"@stylistic/comma-dangle": ["error", "always-multiline"],
"@stylistic/dot-location": ["error", "property"],
"@stylistic/function-call-argument-newline": ["error", "consistent"],
"@stylistic/function-paren-newline": "off",
"@stylistic/indent": ["error", "tab"],
"@stylistic/indent-binary-ops": ["error", "tab"],
"@stylistic/max-len": "off",
"@stylistic/multiline-ternary": ["error", "always-multiline"],
"@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 1 }],
"@stylistic/no-mixed-operators": "off",
"@stylistic/no-tabs": "off",
"@stylistic/object-property-newline": "off",
"@stylistic/one-var-declaration-per-line": "off",
"@stylistic/operator-linebreak": ["error", "before"],
"@stylistic/padded-blocks": "off",
"@stylistic/quote-props": ["error", "consistent-as-needed"],
"@stylistic/quotes": ["error", "single"]
},
"overrides": [
{
Expand Down
18 changes: 9 additions & 9 deletions docs/profile-boilerplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ const products = [
bitmasks: [16],
name: 'ACME Commuter Rail',
short: 'CR',
default: true
default: true,
},
{
id: 'metro',
mode: 'train',
bitmasks: [8],
name: 'Foo Bar Metro',
short: 'M',
default: true
}
]
default: true,
},
];

const transformReqBody = (body) => {
// get these from the recorded app requests
// body.client = { … }
// body.ver = …
// body.auth = { … }
// body.lang = …
return body
}
return body;
};

const insaProfile = {
// locale: …,
Expand All @@ -37,9 +37,9 @@ const insaProfile = {
products: products,

trip: false,
radar: false
}
radar: false,
};

export {
insaProfile,
}
};
20 changes: 11 additions & 9 deletions format/address.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
import {formatLocationIdentifier} from './location-identifier.js';
import {formatCoord} from './coord.js';

const formatAddress = (a) => {
if (a.type !== 'location' || !a.latitude || !a.longitude || !a.address) {
throw new TypeError('invalid address')
throw new TypeError('invalid address');
}

const data = {
A: '2', // address?
O: a.address,
X: formatCoord(a.longitude),
Y: formatCoord(a.latitude)
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,
lid: formatLocationIdentifier(data)
}
}
lid: formatLocationIdentifier(data),
};
};

export {
formatAddress,
}
};
4 changes: 2 additions & 2 deletions format/coord.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatCoord = x => Math.round(x * 1000000)
const formatCoord = x => Math.round(x * 1000000);

export {
formatCoord,
}
};
29 changes: 16 additions & 13 deletions format/date.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import {DateTime, IANAZone} from 'luxon'
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
import {DateTime, IANAZone} from 'luxon';
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 {
timezone = new IANAZone(profile.timezone)
timezones.set(profile, timezone)
let timezone;
if (timezones.has(profile)) {
timezone = timezones.get(profile);
} else {
timezone = new IANAZone(profile.timezone);
timezones.set(profile, timezone);
}

return DateTime.fromMillis(+when, {
locale: profile.locale,
zone: timezone
}).toFormat('yyyyMMdd')
}
return DateTime
.fromMillis(Number(when), {
locale: profile.locale,
zone: timezone,
})
.toFormat('yyyyMMdd');
};

export {
formatDate,
}
};
8 changes: 4 additions & 4 deletions format/filters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const bike = {type: 'BC', mode: 'INC'}
const bike = {type: 'BC', mode: 'INC'};

const accessibility = {
none: {type: 'META', mode: 'INC', meta: 'notBarrierfree'},
partial: {type: 'META', mode: 'INC', meta: 'limitedBarrierfree'},
complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'}
}
complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'},
};

export {
bike,
accessibility,
}
};
8 changes: 4 additions & 4 deletions format/lines-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const formatLinesReq = (ctx, query) => {
meth: 'LineMatch',
req: {
input: query,
}
}
}
},
};
};

export {
formatLinesReq,
}
};
14 changes: 10 additions & 4 deletions format/location-filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const formatLocationFilter = (stops, addresses, poi) => {
if (stops && addresses && poi) return 'ALL'
return (stops ? 'S' : '') + (addresses ? 'A' : '') + (poi ? 'P' : '')
}
if (stops && addresses && poi) {
return 'ALL';
}
return (
(stops ? 'S' : '')
+ (addresses ? 'A' : '')
+ (poi ? 'P' : '')
);
};

export {
formatLocationFilter,
}
};
16 changes: 9 additions & 7 deletions format/location-identifier.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const sep = '@'
const sep = '@';

const formatLocationIdentifier = (data) => {
let str = ''
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?
str += key + '=' + data[key] + sep; // todo: escape, but how?
}

return str
}
return str;
};

export {
formatLocationIdentifier,
}
};
26 changes: 17 additions & 9 deletions format/location.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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)
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(`invalid ${name}.type: ${l.type}`);
}
throw new TypeError(name + ': valid station, address or poi required.')
}
throw new TypeError(name + ': valid station, address or poi required.');
};

export {
formatLocation,
}
};
16 changes: 9 additions & 7 deletions format/locations-req.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const formatLocationsReq = (ctx, query) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
cfg: {polyEnc: 'GPA'},
meth: 'LocMatch',
req: {input: {
loc: {
type: profile.formatLocationFilter(opt.stops, opt.addresses, opt.poi),
name: opt.fuzzy ? query + '?' : query
name: opt.fuzzy
? query + '?'
: query,
},
maxLoc: opt.results,
field: 'S' // todo: what is this?
}}
}
}
field: 'S', // todo: what is this?
}},
};
};

export {
formatLocationsReq,
}
};
20 changes: 10 additions & 10 deletions format/nearby-req.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatNearbyReq = (ctx, location) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
cfg: {polyEnc: 'GPA'},
Expand All @@ -8,21 +8,21 @@ const formatNearbyReq = (ctx, location) => {
ring: {
cCrd: {
x: profile.formatCoord(location.longitude),
y: profile.formatCoord(location.latitude)
y: profile.formatCoord(location.latitude),
},
maxDist: opt.distance || -1,
minDist: 0
minDist: 0,
},
locFltrL: [
profile.formatProductsFilter(ctx, opt.products || {}),
],
getPOIs: !!opt.poi,
getStops: !!opt.stops,
maxLoc: opt.results
}
}
}
getPOIs: Boolean(opt.poi),
getStops: Boolean(opt.stops),
maxLoc: opt.results,
},
};
};

export {
formatNearbyReq,
}
};
16 changes: 8 additions & 8 deletions format/poi.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
import {formatLocationIdentifier} from './location-identifier.js';
import {formatCoord} from './coord.js';

const formatPoi = (p) => {
// todo: use Number.isFinite()!
if (p.type !== 'location' || !p.latitude || !p.longitude || !p.id || !p.name) {
throw new TypeError('invalid POI')
throw new TypeError('invalid POI');
}

return {
Expand All @@ -15,11 +15,11 @@ const formatPoi = (p) => {
O: p.name,
L: p.id,
X: formatCoord(p.longitude),
Y: formatCoord(p.latitude)
})
}
}
Y: formatCoord(p.latitude),
}),
};
};

export {
formatPoi,
}
};
Loading
Loading