Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/biome'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Jan 15, 2024
2 parents f1f0d78 + d682b70 commit e142c48
Show file tree
Hide file tree
Showing 68 changed files with 390 additions and 317 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ node_modules: package.json pnpm-lock.yaml
.NOTPARALLEL: node_modules

lint: | node_modules
$(NODE_BIN)/jshint $(LINT_SRC)
$(NODE_BIN)/biome lint $(LINT_SRC)

test: | node_modules
node --test $(TESTS)
Expand Down
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(cookieParser());
app.use(cachify);
app.use((req, res, next) => {
app.use((_req, res, next) => {
cachify.helpers().then(fns => {
res.locals.cachify = fns.cachify;
next();
Expand Down Expand Up @@ -72,13 +72,13 @@ app.data = require('./lib/routes/data')();
require('./lib/routes')(app);

app.run = function run() {
app.data.init(function (err) {
app.data.init(err => {
if (err) {
console.error(err);
process.exit(1);
return;
}
http.createServer(app).listen(app.get('port'), function () {
http.createServer(app).listen(app.get('port'), () => {
console.log(`Running on: http://localhost:${app.get('port')}`);
});
});
Expand Down
64 changes: 64 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.1/schema.json",
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": false
},
"files": {
"ignore": [
"bin/generate",
"test/resorts/example",
"test/replay"
]
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingComma": "none",
"arrowParentheses": "asNeeded"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"all": true
},
"complexity": {
"noForEach": "off",
"useLiteralKeys": "off"
},
"style": {
"noParameterAssign": "off"
},
"performance": {
"noDelete": "off"
},
"suspicious": {
"noAssignInExpressions": "off"
}
}
},
"overrides": [
{
"include": [
"**/sw.template.js"
],
"linter": {
"rules": {
"correctness": {
"noUndeclaredVariables": "off"
}
}
},
"javascript": {
"globals": [
"options"
]
}
}
]
}
4 changes: 1 addition & 3 deletions lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ function checkNames(requested, valid, all) {
if (typeof requested === 'string') {
requested = requested.split(',');
}
return requested.filter(function (item) {
return valid[item];
});
return requested.filter((item) => valid[item]);
}
2 changes: 1 addition & 1 deletion lib/cli/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const dirs = require('./dirs');
module.exports = curl;

function curl(url, resortId) {
const dst = path.join(dirs.test, 'example', resortId + '.html');
const dst = path.join(dirs.test, 'example', `${resortId}.html`);
const dstStream = fs.createWriteStream(dst);

console.log('Fetching %s to %s...', url.host + url.pathname, dst);
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ function fetchExample(resortId) {
let resort;

try {
resort = require('../resorts/' + resortId + '/resort.json');
resort = require(`../resorts/${resortId}/resort.json`);
curl(resort.dataUrl || resort.api || resort.url, resortId);
done = true;
} catch (e) {
} catch {
console.error(resortId, 'is not a valid resort ID');
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/for-each-resort.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = forEachResort;

function forEachResort(fn) {
console.log('Reading:', lib);
readdir(lib, { withFileTypes: true }, function (err, dirents) {
readdir(lib, { withFileTypes: true }, (err, dirents) => {
if (err) {
console.error(err);
process.exit(1);
Expand Down
14 changes: 6 additions & 8 deletions lib/cli/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ program

if (program.json) {
fname = path.resolve(program.json);
fs.readFile(fname, function (err, data) {
let conf;
fs.readFile(fname, (err, data) => {
if (err) {
console.error(err);
process.exit(-1);
}
conf = JSON.parse(data);
const conf = JSON.parse(data);
conf.id = path.basename(fname, '.json');
if (conf.url) {
conf.host = conf.url.host;
Expand All @@ -87,11 +86,10 @@ if (program.json) {
function generate(resort) {
console.log('Generating files for %s', resort.name);
const resortDir = path.join(dirs.lib, resort.id);
let json;

fs.mkdirSync(resortDir);
copy(path.join(dirs.templates, 'index.js'), path.join(resortDir, 'index.js'), resort);
json = {
const json = {
name: resort.name,
url: {
host: resort.host,
Expand All @@ -104,7 +102,7 @@ function generate(resort) {
json.opening = resort.opening;
}
write(path.join(resortDir, 'resort.json'), json);
copy(path.join(dirs.templates, 'test.js'), path.join(dirs.test, resort.id + '.js'), resort);
copy(path.join(dirs.templates, 'test.js'), path.join(dirs.test, `${resort.id}.js`), resort);
curl(json.url, resort.id);
}

Expand All @@ -116,7 +114,7 @@ function write(dst, json) {

function copy(src, dst, params) {
console.log('Generating %s...', dst);
fs.readFile(src, 'utf8', function (err, data) {
fs.readFile(src, 'utf8', (_err, data) => {
data = template(data)(params);
fs.writeFileSync(dst, data);
});
Expand All @@ -137,7 +135,7 @@ function execute(conf) {
schema[2].before = splitHost;
conf = conf || {};
prompt.override = conf;
prompt.addProperties(conf, schema, function (err) {
prompt.addProperties(conf, schema, (err) => {
if (err) {
console.error(err);
process.exit(-1);
Expand Down
11 changes: 5 additions & 6 deletions lib/cli/noaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,36 @@ function noaaForResort(resortId, { overwrite }) {

const { ll } = descriptor;
const url = `https://api.weather.gov/points/${points(ll)}`;
console.log(`Trying: `, url);
superagent(url)
.accept('application/geo+json')
.set('User-Agent', userAgent)
.then(function (res) {
.then((res) => {
const { body: { properties: { gridId, gridX, gridY } } } = res;
const noaa = `${gridId}/${gridX},${gridY}`;
if (overwrite) {
descriptor.noaa = noaa;
writeDescriptor(resortId, descriptor);
}
console.log(resortId, noaa);
}, function (e) {
}, (e) => {
console.error('Cannot find NOAA station for:', resortId, e.response.text);
});
}

function descriptorPath(resortId, absolute) {
let p = `../resorts/${resortId}/resort.json`;
const p = `../resorts/${resortId}/resort.json`;
return absolute ? resolve(__dirname, p) : p;
}

function writeDescriptor(resortId, descriptor) {
const filename = descriptorPath(resortId, true);
writeFileSync(filename, JSON.stringify(descriptor, null, 2) + '\n');
writeFileSync(filename, `${JSON.stringify(descriptor, null, 2)}\n`);
}

function readDescriptor(resortId) {
try {
return require(`../resorts/${resortId}/resort.json`);
} catch (e) {
} catch {
console.error(resortId, 'is not a valid resort ID');
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/client/resort/snow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports.type = 'snow';
// .notice= resort.snow.notice

function renderField(div, field, snow) {
const el = div.querySelector('.' + field);
const el = div.querySelector(`.${field}`);
const value = snow[field];
el.querySelector('.value').innerHTML = value || '';
el.classList.toggle('hidden', !value);
Expand Down
9 changes: 3 additions & 6 deletions lib/client/resort/webcams.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ function render(div, webcams) {

function refresh() {
cams.forEach(it => {
let imgs;
let i;
let fn;
imgs = it.node.querySelectorAll('img');
fn = swap.bind(null, imgs, it);
for (i = 0; i < imgs.length; i++) {
const imgs = it.node.querySelectorAll('img');
const fn = swap.bind(null, imgs, it);
for (let i = 0; i < imgs.length; i++) {
imgs[i].onload = fn;
}
imgs[it.inactive].setAttribute('src', imgs[it.active].getAttribute('src'));
Expand Down
2 changes: 1 addition & 1 deletion lib/client/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function state(nodes, st, keys) {

function read() {
const text = cookie.get(cookieName);
return text && text.length ? text.split(',') : [];
return text?.length ? text.split(',') : [];
}

function write(arr) {
Expand Down
18 changes: 7 additions & 11 deletions lib/embed/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*global document, window */

function el(attrs) {
const attrStr = Object.keys(attrs).map(function (attr) {
return attr + '="' + attrs[attr] + '"';
}).join(' ');
const attrStr = Object.keys(attrs).map((attr) => `${attr}="${attrs[attr]}"`).join(' ');

return ['<iframe ',
attrStr,
Expand All @@ -12,12 +10,10 @@ function el(attrs) {
}

function addWidget(parent, resort, style) {
let query;
let html;
query = style ? '?style=' + encodeURIComponent(style) : '';
html = el({
'class': 'lift-status ' + resort,
src: 'https://liftie.info/widget/resort/' + resort + query,
const query = style ? `?style=${encodeURIComponent(style)}` : '';
let html = el({
'class': `lift-status ${resort}`,
src: `https://liftie.info/widget/resort/${resort}${query}`,
scrolling: 'no'
});
html += '<p class="liftie-link">Lift status by <a href="https://liftie.info" target="_blank">Liftie</a></p>';
Expand All @@ -33,9 +29,9 @@ function receiveMessage(event) {
if (!event.data.height) {
return;
}
const iframe = document.querySelector('.liftie-widget[data-resort="' + event.data.resort + '"] iframe');
const iframe = document.querySelector(`.liftie-widget[data-resort="${event.data.resort}"] iframe`);
if (iframe) {
iframe.style.height = event.data.height + 'px';
iframe.style.height = `${event.data.height}px`;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function fetch(resort, fn) {
}
debug("Fetch lift status for %s", resort.id);
const rfau = resort._rfau;
rfau.fn(rfau.url, resort._parseFn, function (err, data) {
Promise.resolve(data).then(function (data, err) {
rfau.fn(rfau.url, resort._parseFn, (_err, data) => {
Promise.resolve(data).then((data, err) => {
if (err || !data) {
data = {};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/pipe.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const request = require('./request');
const parseHtml = require('./parser').html;

module.exports = function (url, parse, fn) {
module.exports = (url, parse, fn) => {
request(url)
.buffer(true)
.on('error', fn)
.end(function (err, res) {
.end((err, res) => {
if (err && !url.ignoreErrors) {
console.error('Error', url, err.status);
return fn(err.status);
Expand Down
2 changes: 1 addition & 1 deletion lib/lifts/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const superagent = require('superagent');

const userAgent = 'Mozilla/5.0 (compatible; Liftie/1.0; +https://liftie.info)';

module.exports = function ({ host, pathname, query, http2 }) {
module.exports = ({ host, pathname, query, http2 }) => {

const req = superagent
.agent()
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function rest(url, parse, fn) {
.on('error', fn);

request.then(
function (res) {
(res) => {
let { body, text } = res;
if (url.html) {
return parseHtml(body, parse, fn);
Expand All @@ -44,7 +44,7 @@ function rest(url, parse, fn) {
fn(null, parse(body));
}
},
function ({ status }) {
({ status }) => {
fn(status);
}
);
Expand Down
Loading

0 comments on commit e142c48

Please sign in to comment.