Fix lints

This commit is contained in:
Eric Eastwood 2022-02-15 21:33:31 -06:00
parent 6c1cf6d46a
commit 166857e0de
19 changed files with 74 additions and 42 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
node_modules/
dist/

View File

@ -86,11 +86,7 @@
],
"node/no-missing-require": "error",
"node/no-missing-import": "error",
"node/no-unsupported-features": [
"error",
{
"version": 10
}
]
"node/no-unsupported-features/es-syntax": "error",
"node/no-unsupported-features/es-builtins": "error"
}
}

View File

@ -24,3 +24,8 @@ the messages from a Matrix homeserver.
Re-using Hydrogen gets us pretty and native(to Element) looking styles and keeps
the maintenance burden of supporting more event types in Hydrogen.
## Prerequisites
- Node.js v17
- We only need v17 because it includes `require('crypto').webcrypto`

View File

@ -3,8 +3,15 @@
"version": "0.0.0",
"scripts": {
"start-dev": "node server/start-dev.js",
"lint": "eslint **/*.js",
"nodemon": "nodemon",
"vite": "vite"
"vite": "vite",
"eslint": "eslint",
"prettier": "prettier"
},
"engines" : {
"node" : ">=17.0.0"
},
"devDependencies": {
"eslint": "^8.8.0",

15
public/js/.eslintrc.json Normal file
View File

@ -0,0 +1,15 @@
{
"env": {
"browser": true,
"commonjs": false,
"node": false
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"node/no-unsupported-features/es-syntax": "off",
"node/no-unsupported-features/es-builtins": "off"
}
}

View File

@ -1,5 +0,0 @@
function asdf() {
console.log('asdfasdfasdfasdf');
}
module.exports = asdf;

View File

@ -1,9 +1,2 @@
import asdf from './asdf';
asdf();
import mounted from 'matrix-public-archive-shared/hydrogen-vm-render-script';
console.log('mounted', mounted);
// import mounted2 from '../../shared/hydrogen-vm-render-script';
// console.log('mounted2', mounted2);

View File

@ -1,3 +1,5 @@
'use strict';
const assert = require('assert');
const urlJoin = require('./lib/url-join');

View File

@ -1,3 +1,5 @@
'use strict';
const assert = require('assert');
const urlJoin = require('./lib/url-join');

View File

@ -1,3 +1,5 @@
'use strict';
// Simple middleware for handling exceptions inside of async express routes and
// passing them to your express error handlers.
//

View File

@ -1,3 +1,5 @@
'use strict';
const assert = require('assert');
const fetch = require('node-fetch');

View File

@ -1,3 +1,5 @@
'use strict';
const path = require('path');
// via https://javascript.plainenglish.io/how-to-safely-concatenate-url-with-node-js-f6527b623d5

View File

@ -1,3 +1,5 @@
'use strict';
const assert = require('assert');
const vm = require('vm');
const path = require('path');

View File

@ -14,9 +14,7 @@ const config = require('../../config.json');
const basePath = config.basePath;
assert(basePath);
function parseArchiveRangeFromReq(req, res) {
const roomIdOrAlias = req.params.roomIdOrAlias;
function parseArchiveRangeFromReq(req) {
const yyyy = parseInt(req.params.yyyy, 10);
// Month is the only zero-based index in this group
const mm = parseInt(req.params.mm, 10) - 1;
@ -39,23 +37,6 @@ function parseArchiveRangeFromReq(req, res) {
if (Number.isNaN(fromHour) || fromHour < 0 || fromHour > 23) {
throw new StatusError(404, 'From hour can only be in range 0-23');
}
// Currently we force the range to always be 1 hour
// If the format isn't correct, redirect to the correct hour range
if (toHour !== fromHour + 1) {
res.redirect(
urlJoin(
basePath,
roomIdOrAlias,
'date',
req.params.yyyy,
req.params.mm,
req.params.dd,
`${fromHour}-${fromHour + 1}`
)
);
return;
}
}
const fromTimestamp = Date.UTC(yyyy, mm, dd, fromHour);
@ -70,6 +51,8 @@ function parseArchiveRangeFromReq(req, res) {
yyyy,
mm,
dd,
fromHour,
toHour,
};
}
@ -104,7 +87,24 @@ function installRoutes(app) {
const roomIdOrAlias = req.params.roomIdOrAlias;
assert(roomIdOrAlias.startsWith('!') || roomIdOrAlias.startsWith('#'));
const { fromTimestamp, toTimestamp } = parseArchiveRangeFromReq(req, res);
const { fromTimestamp, fromHour, toHour } = parseArchiveRangeFromReq(req);
// Currently we force the range to always be 1 hour
// If the format isn't correct, redirect to the correct hour range
if (toHour !== fromHour + 1) {
res.redirect(
urlJoin(
basePath,
roomIdOrAlias,
'date',
req.params.yyyy,
req.params.mm,
req.params.dd,
`${fromHour}-${fromHour + 1}`
)
);
return;
}
const [roomData, { events, stateEventMap }] = await Promise.all([
fetchRoomData(roomIdOrAlias),

View File

@ -1,4 +1,5 @@
'use strict';
const path = require('path');
const nodemon = require('nodemon');
const { build } = require('vite');

View File

@ -1,3 +1,5 @@
'use strict';
const { TemplateView } = require('hydrogen-view-sdk');
// Month in JavaScript is 0-indexed (January is 0, February is 1, etc),

View File

@ -1,3 +1,5 @@
'use strict';
const { TemplateView } = require('hydrogen-view-sdk');
const CalendarView = require('matrix-public-archive-shared/CalendarView');

View File

@ -12,8 +12,8 @@ const {
encodeKey,
encodeEventIdKey,
Timeline,
TimelineView,
RoomView,
// TimelineView,
// RoomView,
RoomViewModel,
ViewModel,
} = require('hydrogen-view-sdk');

View File

@ -1,3 +1,5 @@
'use strict';
function assert(value, message) {
console.assert(value, message);
if (!value) {