mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
Add ESLint & Run it against the system (#4470)
This commit is contained in:
parent
43eee6b32e
commit
f789e02096
106 changed files with 1235 additions and 20242 deletions
|
|
@ -1,22 +1,22 @@
|
|||
import { SortBy, SortDirection, User } from "types";
|
||||
import { SortBy, SortDirection, User } from 'types';
|
||||
|
||||
export default class SortUtil {
|
||||
static sortByField(arr: any[], sortBy: SortBy): void {
|
||||
static sortByField(arr: any[], sortBy: SortBy): void {
|
||||
if (arr.length) {
|
||||
const field = SortUtil.resolveFieldChain(arr[0], sortBy.field);
|
||||
const fieldType = typeof field;
|
||||
|
||||
if (fieldType === "string") {
|
||||
if (fieldType === 'string') {
|
||||
SortUtil.sortByString(arr, sortBy);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fieldType === "number") {
|
||||
if (fieldType === 'number') {
|
||||
SortUtil.sortByNumber(arr, sortBy);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error("SortField must resolve to either a string or number");
|
||||
throw new Error('SortField must resolve to either a string or number');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,10 +26,10 @@ export default class SortUtil {
|
|||
for (let i = 0; i < sorts.length; i++) {
|
||||
const sortBy = sorts[i];
|
||||
const field = SortUtil.resolveFieldChain(arr[0], sortBy.field);
|
||||
|
||||
|
||||
const fieldType = typeof field;
|
||||
|
||||
if (fieldType === "string") {
|
||||
if (fieldType === 'string') {
|
||||
const result = SortUtil.stringComparator(a, b, sortBy);
|
||||
|
||||
if (result) {
|
||||
|
|
@ -37,7 +37,7 @@ export default class SortUtil {
|
|||
}
|
||||
}
|
||||
|
||||
if (fieldType === "number") {
|
||||
if (fieldType === 'number') {
|
||||
const result = SortUtil.numberComparator(a, b, sortBy);
|
||||
|
||||
if (result) {
|
||||
|
|
@ -45,7 +45,7 @@ export default class SortUtil {
|
|||
}
|
||||
}
|
||||
|
||||
throw new Error("SortField must resolve to either a string or number");
|
||||
throw new Error('SortField must resolve to either a string or number');
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -80,7 +80,7 @@ export default class SortUtil {
|
|||
private static userComparator(a, b, sortBy, sortByUserLevel = true) {
|
||||
if (sortByUserLevel) {
|
||||
const adminSortBy = {
|
||||
field: "userLevel",
|
||||
field: 'userLevel',
|
||||
order: SortDirection.DESC
|
||||
};
|
||||
|
||||
|
|
@ -116,9 +116,15 @@ export default class SortUtil {
|
|||
const bResolved = SortUtil.resolveFieldChain(b, field);
|
||||
|
||||
// Force empty strings to sort to bottom
|
||||
if (!aResolved && !bResolved) { return 0; }
|
||||
if (!aResolved) { return 1; }
|
||||
if (!bResolved) { return -1; }
|
||||
if (!aResolved && !bResolved) {
|
||||
return 0;
|
||||
}
|
||||
if (!aResolved) {
|
||||
return 1;
|
||||
}
|
||||
if (!bResolved) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (order === SortDirection.ASC) {
|
||||
return aResolved.localeCompare(bResolved);
|
||||
|
|
@ -128,13 +134,13 @@ export default class SortUtil {
|
|||
}
|
||||
|
||||
private static resolveFieldChain(obj: object, field: string) {
|
||||
const links = field.split(".");
|
||||
const links = field.split('.');
|
||||
|
||||
if (links.length > 1) {
|
||||
return links.reduce((obj, link) => {
|
||||
const parsed = parseInt(link, 10);
|
||||
|
||||
if (parsed.toLocaleString() === "NaN") {
|
||||
if (parsed.toLocaleString() === 'NaN') {
|
||||
return obj[link];
|
||||
} else {
|
||||
return obj[parsed];
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export { default as SortUtil} from "./SortUtil";
|
||||
export { default as SortUtil } from './SortUtil';
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
export { store } from "./store";
|
||||
export { store } from './store';
|
||||
|
||||
// Common
|
||||
export { SortUtil } from "./common";
|
||||
export { SortUtil } from './common';
|
||||
|
||||
// Server
|
||||
// Server
|
||||
|
||||
export {
|
||||
Selectors as ServerSelectors,
|
||||
Dispatch as ServerDispatch} from './server';
|
||||
export {
|
||||
Selectors as ServerSelectors,
|
||||
Dispatch as ServerDispatch } from './server';
|
||||
|
||||
export * from "store/server/server.interfaces";
|
||||
export * from 'store/server/server.interfaces';
|
||||
|
||||
export {
|
||||
Selectors as RoomsSelectors,
|
||||
Dispatch as RoomsDispatch } from 'store/rooms';
|
||||
export {
|
||||
Selectors as RoomsSelectors,
|
||||
Dispatch as RoomsDispatch } from 'store/rooms';
|
||||
|
||||
export * from "store/rooms/rooms.interfaces";
|
||||
export * from 'store/rooms/rooms.interfaces';
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export * from "./rooms.actions";
|
||||
export * from "./rooms.dispatch";
|
||||
export * from "./rooms.reducer";
|
||||
export * from "./rooms.selectors";
|
||||
export * from "./rooms.types";
|
||||
export * from './rooms.actions';
|
||||
export * from './rooms.dispatch';
|
||||
export * from './rooms.reducer';
|
||||
export * from './rooms.selectors';
|
||||
export * from './rooms.types';
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { Types } from "./rooms.types";
|
||||
import { Types } from './rooms.types';
|
||||
|
||||
export const Actions = {
|
||||
clearStore: () => ({
|
||||
type: Types.CLEAR_STORE
|
||||
}),
|
||||
|
||||
|
||||
updateRooms: rooms => ({
|
||||
type: Types.UPDATE_ROOMS,
|
||||
rooms
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { reset } from 'redux-form';
|
||||
import { Actions } from "./rooms.actions";
|
||||
import { store } from "store";
|
||||
import { Actions } from './rooms.actions';
|
||||
import { store } from 'store';
|
||||
|
||||
// const history = useHistory();
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ export const Dispatch = {
|
|||
clearStore: () => {
|
||||
store.dispatch(Actions.clearStore());
|
||||
},
|
||||
|
||||
|
||||
updateRooms: rooms => {
|
||||
store.dispatch(Actions.updateRooms(rooms));
|
||||
},
|
||||
|
|
@ -26,7 +26,7 @@ export const Dispatch = {
|
|||
if (message.name) {
|
||||
store.dispatch(reset('sayMessage'));
|
||||
}
|
||||
|
||||
|
||||
store.dispatch(Actions.addMessage(roomId, message));
|
||||
},
|
||||
|
||||
|
|
@ -45,4 +45,4 @@ export const Dispatch = {
|
|||
sortGames: (roomId, field, order) => {
|
||||
store.dispatch(Actions.sortGames(roomId, field, order));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { GameSortField, Room, SortBy, UserSortField } from "types";
|
||||
import { GameSortField, Room, SortBy, UserSortField } from 'types';
|
||||
|
||||
export interface RoomsState {
|
||||
rooms: RoomsStateRooms;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import * as _ from "lodash";
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { GameSortField, UserSortField, SortDirection } from "types";
|
||||
import { GameSortField, UserSortField, SortDirection } from 'types';
|
||||
|
||||
import { SortUtil } from "../common";
|
||||
import { SortUtil } from '../common';
|
||||
|
||||
import { RoomsState } from "./rooms.interfaces"
|
||||
import { MAX_ROOM_MESSAGES, Types } from "./rooms.types";
|
||||
import { RoomsState } from './rooms.interfaces'
|
||||
import { MAX_ROOM_MESSAGES, Types } from './rooms.types';
|
||||
|
||||
const initialState: RoomsState = {
|
||||
rooms: {},
|
||||
|
|
@ -22,7 +22,7 @@ const initialState: RoomsState = {
|
|||
};
|
||||
|
||||
export const roomsReducer = (state = initialState, action: any) => {
|
||||
switch(action.type) {
|
||||
switch (action.type) {
|
||||
case Types.CLEAR_STORE: {
|
||||
return {
|
||||
...initialState
|
||||
|
|
@ -37,7 +37,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
_.each(action.rooms, (room, order) => {
|
||||
const { roomId } = room;
|
||||
const existing = rooms[roomId] || {};
|
||||
|
||||
|
||||
const update = { ...room };
|
||||
delete update.gameList;
|
||||
delete update.gametypeList;
|
||||
|
|
@ -113,7 +113,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
const { roomId, message } = action;
|
||||
const { messages } = state;
|
||||
|
||||
let roomMessages = [ ...(messages[roomId] || []) ];
|
||||
let roomMessages = [...(messages[roomId] || [])];
|
||||
|
||||
if (roomMessages.length === MAX_ROOM_MESSAGES) {
|
||||
roomMessages.shift();
|
||||
|
|
@ -150,7 +150,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
}, {});
|
||||
|
||||
const gameUpdates = room.gameList
|
||||
// filter out closed games and remove from update map
|
||||
// filter out closed games and remove from update map
|
||||
.filter(game => {
|
||||
const gameUpdate = toUpdate[game.gameId];
|
||||
const closedGame = gameUpdate && gameUpdate.closed;
|
||||
|
|
@ -181,7 +181,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
_.each(toUpdate, game => gameUpdates.push(game));
|
||||
}
|
||||
|
||||
const gameList = [ ...gameUpdates ];
|
||||
const gameList = [...gameUpdates];
|
||||
|
||||
SortUtil.sortByField(gameList, sortGamesBy);
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
[roomId]: {
|
||||
...room,
|
||||
userList
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -225,7 +225,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
const { rooms } = state;
|
||||
|
||||
const room = { ...rooms[roomId] };
|
||||
const userList = room.userList.filter(user => user.name !== name);
|
||||
const userList = room.userList.filter(user => user.name !== name);
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
|
@ -234,7 +234,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
[roomId]: {
|
||||
...room,
|
||||
userList
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -242,7 +242,7 @@ export const roomsReducer = (state = initialState, action: any) => {
|
|||
const { field, order, roomId } = action;
|
||||
const { rooms } = state;
|
||||
|
||||
const gameList = [ ...rooms[roomId].gameList ];
|
||||
const gameList = [...rooms[roomId].gameList];
|
||||
|
||||
const sortGamesBy = {
|
||||
field, order
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as _ from "lodash";
|
||||
import { RoomsState } from "./rooms.interfaces";
|
||||
import * as _ from 'lodash';
|
||||
import { RoomsState } from './rooms.interfaces';
|
||||
|
||||
interface State {
|
||||
rooms: RoomsState
|
||||
|
|
@ -8,7 +8,7 @@ interface State {
|
|||
export const Selectors = {
|
||||
getRooms: ({ rooms }: State) => rooms.rooms,
|
||||
getRoom: ({ rooms }: State, id: number) =>
|
||||
_.find(rooms.rooms, ({roomId}) => roomId === id),
|
||||
_.find(rooms.rooms, ({ roomId }) => roomId === id),
|
||||
getJoined: ({ rooms }: State) => rooms.joined,
|
||||
getMessages: ({ rooms }: State) => rooms.messages,
|
||||
getSortGamesBy: ({ rooms: { sortGamesBy } }: State) => sortGamesBy,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
export const Types = {
|
||||
CLEAR_STORE: "[Rooms] Clear Store",
|
||||
UPDATE_ROOMS: "[Rooms] Update Rooms",
|
||||
JOIN_ROOM: "[Rooms] Join Room",
|
||||
LEAVE_ROOM: "[Rooms] Leave Room",
|
||||
ADD_MESSAGE: "[Rooms] Add Message",
|
||||
UPDATE_GAMES: "[Rooms] Update Games",
|
||||
USER_JOINED: "[Rooms] User Joined",
|
||||
USER_LEFT: "[Rooms] User Left",
|
||||
SORT_GAMES: "[Rooms] Sort Games"
|
||||
CLEAR_STORE: '[Rooms] Clear Store',
|
||||
UPDATE_ROOMS: '[Rooms] Update Rooms',
|
||||
JOIN_ROOM: '[Rooms] Join Room',
|
||||
LEAVE_ROOM: '[Rooms] Leave Room',
|
||||
ADD_MESSAGE: '[Rooms] Add Message',
|
||||
UPDATE_GAMES: '[Rooms] Update Games',
|
||||
USER_JOINED: '[Rooms] User Joined',
|
||||
USER_LEFT: '[Rooms] User Left',
|
||||
SORT_GAMES: '[Rooms] Sort Games'
|
||||
};
|
||||
|
||||
export const MAX_ROOM_MESSAGES = 1000;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { combineReducers } from "redux";
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
import { roomsReducer } from "./rooms";
|
||||
import { serverReducer } from "./server";
|
||||
import { reducer as formReducer } from "redux-form"
|
||||
import { roomsReducer } from './rooms';
|
||||
import { serverReducer } from './server';
|
||||
import { reducer as formReducer } from 'redux-form'
|
||||
|
||||
export default combineReducers({
|
||||
rooms: roomsReducer,
|
||||
server: serverReducer,
|
||||
|
||||
|
||||
form: formReducer
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export { Actions } from "./server.actions";
|
||||
export { Dispatch } from "./server.dispatch";
|
||||
export * from "./server.reducer";
|
||||
export { Selectors } from "./server.selectors";
|
||||
export * from "./server.types";
|
||||
export { Actions } from './server.actions';
|
||||
export { Dispatch } from './server.dispatch';
|
||||
export * from './server.reducer';
|
||||
export { Selectors } from './server.selectors';
|
||||
export * from './server.types';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Types } from "./server.types";
|
||||
import { Types } from './server.types';
|
||||
|
||||
export const Actions = {
|
||||
clearStore: () => ({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { reset } from 'redux-form';
|
||||
import { Actions } from "./server.actions";
|
||||
import { store } from "store";
|
||||
import { Actions } from './server.actions';
|
||||
import { store } from 'store';
|
||||
|
||||
export const Dispatch = {
|
||||
clearStore: () => {
|
||||
|
|
@ -62,4 +62,4 @@ export const Dispatch = {
|
|||
serverMessage: message => {
|
||||
store.dispatch(Actions.serverMessage(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Log, SortBy, User, UserSortField } from "types";
|
||||
import { Log, SortBy, User, UserSortField } from 'types';
|
||||
|
||||
export interface ServerConnectParams {
|
||||
host: string;
|
||||
|
|
@ -71,4 +71,4 @@ export interface ServerStateSortUsersBy extends SortBy {
|
|||
|
||||
export interface RequestPasswordSaltParams {
|
||||
user: string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { SortDirection, StatusEnum, UserSortField } from "types";
|
||||
import { SortDirection, StatusEnum, UserSortField } from 'types';
|
||||
|
||||
import { SortUtil } from "../common";
|
||||
import { SortUtil } from '../common';
|
||||
|
||||
import { ServerState } from "./server.interfaces"
|
||||
import { Types } from "./server.types";
|
||||
import { ServerState } from './server.interfaces'
|
||||
import { Types } from './server.types';
|
||||
|
||||
const initialState: ServerState = {
|
||||
buddyList: [],
|
||||
|
|
@ -32,7 +32,7 @@ const initialState: ServerState = {
|
|||
};
|
||||
|
||||
export const serverReducer = (state = initialState, action: any) => {
|
||||
switch(action.type) {
|
||||
switch (action.type) {
|
||||
case Types.CLEAR_STORE: {
|
||||
return {
|
||||
...initialState,
|
||||
|
|
@ -67,7 +67,7 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
const { user } = action;
|
||||
const { sortUsersBy } = state;
|
||||
|
||||
const buddyList = [ ...state.buddyList ];
|
||||
const buddyList = [...state.buddyList];
|
||||
|
||||
buddyList.push(user);
|
||||
SortUtil.sortUsersByField(buddyList, sortUsersBy);
|
||||
|
|
@ -103,7 +103,7 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
const { user } = action;
|
||||
const { sortUsersBy } = state;
|
||||
|
||||
const ignoreList = [ ...state.ignoreList ];
|
||||
const ignoreList = [...state.ignoreList];
|
||||
|
||||
ignoreList.push(user);
|
||||
SortUtil.sortUsersByField(ignoreList, sortUsersBy);
|
||||
|
|
@ -116,7 +116,7 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
case Types.REMOVE_FROM_IGNORE_LIST: {
|
||||
const { userName } = action;
|
||||
const ignoreList = state.ignoreList.filter(user => user.name !== userName);
|
||||
|
||||
|
||||
return {
|
||||
...state,
|
||||
ignoreList
|
||||
|
|
@ -125,7 +125,7 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
case Types.UPDATE_INFO: {
|
||||
const { name, version } = action.info;
|
||||
const { info } = state;
|
||||
|
||||
|
||||
return {
|
||||
...state,
|
||||
info: { ...info, name, version }
|
||||
|
|
@ -151,7 +151,7 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
}
|
||||
}
|
||||
case Types.UPDATE_USERS: {
|
||||
const users = [ ...action.users ];
|
||||
const users = [...action.users];
|
||||
const { sortUsersBy } = state;
|
||||
|
||||
|
||||
|
|
@ -174,7 +174,7 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
|
||||
return {
|
||||
...state,
|
||||
users
|
||||
users
|
||||
};
|
||||
}
|
||||
case Types.USER_LEFT: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { ServerState } from "./server.interfaces";
|
||||
import { ServerState } from './server.interfaces';
|
||||
|
||||
interface State {
|
||||
server: ServerState
|
||||
|
|
@ -15,4 +15,4 @@ export const Selectors = {
|
|||
getLogs: ({ server }: State) => server.logs,
|
||||
getBuddyList: ({ server }: State) => server.buddyList,
|
||||
getIgnoreList: ({ server }: State) => server.ignoreList
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
export const Types = {
|
||||
CLEAR_STORE: "[Server] Clear Store",
|
||||
CONNECTION_CLOSED: "[Server] Connection Closed",
|
||||
SERVER_MESSAGE: "[Server] Server Message",
|
||||
UPDATE_BUDDY_LIST: "[Server] Update Buddy List",
|
||||
ADD_TO_BUDDY_LIST: "[Server] Add to Buddy List",
|
||||
REMOVE_FROM_BUDDY_LIST: "[Server] Remove from Buddy List",
|
||||
UPDATE_IGNORE_LIST: "[Server] Update Ignore List",
|
||||
ADD_TO_IGNORE_LIST: "[Server] Add to Ignore List",
|
||||
REMOVE_FROM_IGNORE_LIST: "[Server] Remove from Ignore List",
|
||||
UPDATE_INFO: "[Server] Update Info",
|
||||
UPDATE_STATUS: "[Server] Update Status",
|
||||
UPDATE_USER: "[Server] Update User",
|
||||
UPDATE_USERS: "[Server] Update Users",
|
||||
USER_JOINED: "[Server] User Joined",
|
||||
USER_LEFT: "[Server] User Left",
|
||||
VIEW_LOGS: "[Server] View Logs",
|
||||
CLEAR_LOGS: "[Server] Clear Logs"
|
||||
CLEAR_STORE: '[Server] Clear Store',
|
||||
CONNECTION_CLOSED: '[Server] Connection Closed',
|
||||
SERVER_MESSAGE: '[Server] Server Message',
|
||||
UPDATE_BUDDY_LIST: '[Server] Update Buddy List',
|
||||
ADD_TO_BUDDY_LIST: '[Server] Add to Buddy List',
|
||||
REMOVE_FROM_BUDDY_LIST: '[Server] Remove from Buddy List',
|
||||
UPDATE_IGNORE_LIST: '[Server] Update Ignore List',
|
||||
ADD_TO_IGNORE_LIST: '[Server] Add to Ignore List',
|
||||
REMOVE_FROM_IGNORE_LIST: '[Server] Remove from Ignore List',
|
||||
UPDATE_INFO: '[Server] Update Info',
|
||||
UPDATE_STATUS: '[Server] Update Status',
|
||||
UPDATE_USER: '[Server] Update User',
|
||||
UPDATE_USERS: '[Server] Update Users',
|
||||
USER_JOINED: '[Server] User Joined',
|
||||
USER_LEFT: '[Server] User Left',
|
||||
VIEW_LOGS: '[Server] View Logs',
|
||||
CLEAR_LOGS: '[Server] Clear Logs'
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { createStore, applyMiddleware } from "redux";
|
||||
import thunk from "redux-thunk";
|
||||
import rootReducer from "./rootReducer";
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import rootReducer from './rootReducer';
|
||||
|
||||
const initialState = {};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue