fix 75 eslint warnings,

rename files with jsx code to .jsx,
fix ChatModal export
This commit is contained in:
HF 2020-01-03 13:00:24 +01:00
parent 2c9b2c64a9
commit 11a9c11631
69 changed files with 54 additions and 45 deletions

View File

@ -3,6 +3,11 @@
"plugin:flowtype/recommended",
"airbnb"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"flowtype",
"react",

View File

@ -11,10 +11,9 @@
"scripts": {
"build": "babel-node tools/run build",
"clean": "babel-node tools/run clean",
"lint:js": "eslint src",
"lint": "eslint --ext .jsx --ext .js src",
"lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"",
"lint:staged": "lint-staged",
"lint": "yarn run lint:js && yarn run lint:css"
"lint:staged": "lint-staged"
},
"author": "HF <hf@example.com>",
"browserslist": [

View File

@ -57,6 +57,6 @@ export type Action =
export type PromiseAction = Promise<Action>;
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
export type GetState = () => State;
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;

View File

@ -1,5 +1,7 @@
/*
* Chat input field
*
* @flow
*/
import React from 'react';

View File

@ -4,13 +4,10 @@
*/
import React from 'react';
import { connect } from 'react-redux';
import Modal from './Modal';
import Chat from './Chat';
import type { State } from '../reducers';
const textStyle = {
color: 'hsla(218, 5%, 47%, .6)',
@ -36,3 +33,4 @@ const ChatModal = () => (
</Modal>
);
export default ChatModal;

View File

@ -9,7 +9,7 @@ import HelpButton from './HelpButton';
import SettingsButton from './SettingsButton';
import LogInButton from './LogInButton';
import DownloadButton from './DownloadButton';
import MinecraftTPButton from './MinecraftTPButton.js';
import MinecraftTPButton from './MinecraftTPButton';
import MinecraftButton from './MinecraftButton';
const Menu = ({ menuOpen, minecraftname, messages, canvasId }) => (

View File

@ -17,7 +17,7 @@ export const TILE_FOLDER = path.join(__dirname, `./${TILE_FOLDER_REL}`);
export const ASSET_SERVER = process.env.ASSET_SERVER || '.';
// Proxycheck
export const USE_PROXYCHECK = parseInt(process.env.USE_PROXYCHECK) || false;
export const USE_PROXYCHECK = parseInt(process.env.USE_PROXYCHECK, 10) || false;
export const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6380';
// Database
@ -80,7 +80,7 @@ export const ads = {
export const RECAPTCHA_SECRET = process.env.RECAPTCHA_SECRET || false;
export const RECAPTCHA_SITEKEY = process.env.RECAPTCHA_SITEKEY || false;
// time on which to display captcha in minutes
export const RECAPTCHA_TIME = parseInt(process.env.RECAPTCHA_TIME) || 30;
export const RECAPTCHA_TIME = parseInt(process.env.RECAPTCHA_TIME, 10) || 30;
export const SESSION_SECRET = process.env.SESSION_SECRET || 'dummy';

View File

@ -43,7 +43,7 @@ export function setPixel(
*/
async function draw(
user: User,
canvasId: string,
canvasId: number,
x: number,
y: number,
color: ColorIndex,

View File

@ -32,7 +32,7 @@ class CanvasUpdater {
firstZoomtileWidth: number;
canvasTileFolder: string;
constructor(id) {
constructor(id: number) {
this.updateZoomlevelTiles = this.updateZoomlevelTiles.bind(this);
this.TileLoadingQueues = [];
@ -162,7 +162,7 @@ export function startAllCanvasLoops() {
if (!fs.existsSync(`${TILE_FOLDER}`)) fs.mkdirSync(`${TILE_FOLDER}`);
const ids = Object.keys(canvases);
for (let i = 0; i < ids.length; i += 1) {
const updater = new CanvasUpdater(ids[i]);
const updater = new CanvasUpdater(parseInt(ids[i], 10));
CanvasUpdaters[ids[i]] = updater;
}
}

View File

@ -15,6 +15,13 @@ export function mod(n: number, m: number): number {
return ((n % m) + m) % m;
}
export function sum(values: Array<number>): number {
let total = 0;
// TODO map reduce
values.forEach(value => total += value);
return total;
}
export function distMax([x1, y1]: Cell, [x2, y2]: Cell): number {
return Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
}

View File

@ -72,7 +72,7 @@ router.use('/', express.static(TILE_FOLDER, {
/*
* catch File Not Found: Send empty tile
*/
router.use('/:c([0-9]+)/:z([0-9]+)/:x([0-9]+)/:y([0-9]+).png', async (req: Request, res: Response, next) => {
router.use('/:c([0-9]+)/:z([0-9]+)/:x([0-9]+)/:y([0-9]+).png', async (req: Request, res: Response) => {
const { c: paramC } = req.params;
const c = parseInt(paramC, 10);
res.set({

View File

@ -2,6 +2,8 @@
* save the chat history
* TODO:
* This should really be saved in redis
*
* @flow
*/
class ChatHistory {

View File

@ -1,5 +1,6 @@
/*
* keypress actions
* @flow
*/
import keycode from 'keycode';

View File

@ -1,11 +0,0 @@
/**
*
* @flow
*/
export function sum(values: Array<number>): number {
let total = 0;
// TODO map reduce
values.forEach(value => total += value);
return total;
}

View File

@ -1,7 +1,20 @@
/*
* check if IP is from cloudflare
* @flow
*/
// 3rd
const Address4 = require('ip-address').Address4;
const Address6 = require('ip-address').Address6;
import { Address4, Address6 } from 'ip-address';
// returns undefined | Address4 | Address6
function intoAddress(str) {
if (typeof str === 'string') str = str.trim();
let ip = new Address6(str);
if (ip.v4 && !ip.valid) {
ip = new Address4(str);
}
if (!ip.valid) return null;
return ip;
}
const cloudflareIps = [
'103.21.244.0/22',
@ -27,21 +40,12 @@ const cloudflareIps = [
'2a06:98c0::/29',
].map(intoAddress);
// returns undefined | Address4 | Address6
function intoAddress(str) {
if (typeof str === 'string') str = str.trim();
let ip = new Address6(str);
if (ip.v4 && !ip.valid) {
ip = new Address4(str);
}
if (!ip.valid) return;
return ip;
}
// returns bool
export function isCloudflareIp(testIpString: string): boolean {
function isCloudflareIp(testIpString: string): boolean {
if (!testIpString) return false;
const testIp = intoAddress(testIpString);
if (!testIp) return false;
return cloudflareIps.some(cf => testIp.isInSubnet(cf));
}
export default isCloudflareIp;

View File

@ -4,7 +4,7 @@
* hook it up to some timer function that causes the least load
* @flow
*/
import { HOUR, MINUTE } from '../core/constants';
import { HOUR } from '../core/constants';
import logger from '../core/logger';

View File

@ -3,9 +3,7 @@
* @flow
*/
import dns from 'dns';
import { isCloudflareIp } from './cloudflareip';
import nodeIp from 'ip';
import isCloudflareIp from './cloudflareip';
import logger from '../core/logger';

View File

@ -23,10 +23,14 @@ const config = {
pathinfo: isVerbose,
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
module: {
rules: [
{
test: /\.jsx?$/,
test: /\.(js|jsx)$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, '../src'),