From 7d15057699e84b9ee66909f7b6464617d6f71826 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 21 Jun 2020 20:50:39 -0500 Subject: [PATCH] chore: lint --- package.json | 3 +++ src/client/resource.jsx | 19 ++++++++++++++---- src/client/resources/entity/entity.jsx | 5 +++++ .../resources/entity/entity.resource.js | 1 + src/client/resources/entity/state.js | 20 ++++++++++++++----- src/client/resources/entity/trait-pane.jsx | 8 ++++++++ src/client/resources/entity/trait-tab.jsx | 5 +++++ src/client/resources/entity/traits.jsx | 1 + src/client/store.js | 4 ++-- yarn.lock | 7 ++++++- 10 files changed, 61 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c89173a..af34f2d 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,8 @@ "ansi-html": "0.0.7", "classnames": "2.2.6", "contempo": "1.x", + "debug": "^4.1.1", + "deepmerge": "^4.2.2", "express": "^4.17.1", "express-session": "^1.17.1", "express-socket.io-session": "^1.3.5", @@ -44,6 +46,7 @@ "react-markdown": "^4.3.1", "react-redux": "^7.2.0", "react-tabs": "^3.1.1", + "redux": "^4.0.5", "scwp": "1.x", "socket.io-redis": "^5.3.0", "source-map-support": "^0.5.11" diff --git a/src/client/resource.jsx b/src/client/resource.jsx index 6a11f9b..03c2d9f 100644 --- a/src/client/resource.jsx +++ b/src/client/resource.jsx @@ -1,5 +1,6 @@ import './app.scss'; +import PropTypes from 'prop-types'; import React from 'react'; import {all} from './resources.scwp'; @@ -10,11 +11,21 @@ const Resource = (props) => { const { uri, } = props; - const resource = resources.find((resource) => uri.match(resource.matcher)); - const {Component} = resource - ? resource - : {Component: () =>
No loader for `{uri}`.
}; + const resource = resources.find((r) => uri.match(r.matcher)); + const { + Component = () => ( +
+ No loader for ` + {uri} + `. +
+ ), + } = resource || {}; return
; }; +Resource.propTypes = { + uri: PropTypes.string.isRequired, +}; + export default Resource; diff --git a/src/client/resources/entity/entity.jsx b/src/client/resources/entity/entity.jsx index 7effb0e..7c49a2c 100644 --- a/src/client/resources/entity/entity.jsx +++ b/src/client/resources/entity/entity.jsx @@ -1,6 +1,7 @@ import {compose} from '@avocado/core'; import {Entity} from '@avocado/entity'; import contempo from 'contempo'; +import PropTypes from 'prop-types'; import React, {useEffect} from 'react'; import {useDispatch, useSelector} from 'react-redux'; @@ -35,4 +36,8 @@ const EntityComponent = (props) => { ); }; +EntityComponent.propTypes = { + uri: PropTypes.string.isRequired, +}; + export default decorate(EntityComponent); diff --git a/src/client/resources/entity/entity.resource.js b/src/client/resources/entity/entity.resource.js index 923bf99..43b1df6 100644 --- a/src/client/resources/entity/entity.resource.js +++ b/src/client/resources/entity/entity.resource.js @@ -4,5 +4,6 @@ export default { keys: ['entity', 'entities'], matcher: /\.entity\.json$/, Component: EntityComponent, + // eslint-disable-next-line global-require state: require('./state'), }; diff --git a/src/client/resources/entity/state.js b/src/client/resources/entity/state.js index 99975e0..ef385bd 100644 --- a/src/client/resources/entity/state.js +++ b/src/client/resources/entity/state.js @@ -1,3 +1,4 @@ +/* eslint-disable no-param-reassign */ import {normalize, schema} from 'normalizr'; import { createAsyncThunk, @@ -15,7 +16,7 @@ export const fetchEntity = createAsyncThunk( const json = await data.json(); const {entities} = normalize(json, entitySchema); return entities; - } + }, ); const adapter = createEntityAdapter({ @@ -28,8 +29,8 @@ export const { selectIds: selectEntityIds, selectEntities: selectEntityEntities, selectAll: selectAllEntities, - selectTotal: selectTotalEntities -} = adapter.getSelectors((state) => state.entities) + selectTotal: selectTotalEntities, +} = adapter.getSelectors((state) => state.entities); export const selectEntityUris = createSelector( (state) => state.entities, @@ -41,13 +42,21 @@ export const selectEntityByUri = createSelector( selectEntityUris, (_, uri) => uri, ({entities}, uris, uri) => entities[uris[uri]], -) +); const slice = createSlice({ name: 'entities', initialState: adapter.getInitialState({uris: {}}), reducers: { - setTraitProperty: (state, {payload: {target, trait, type, key, value}}) => { + setTraitProperty: (state, { + payload: { + target, + trait, + type, + key, + value, + }, + }) => { const {traits} = state.entities[target]; traits[trait] = traits[trait] || {}; traits[trait][type] = traits[trait][type] || {}; @@ -59,6 +68,7 @@ const slice = createSlice({ [fetchEntity.fulfilled]: (state, action) => { adapter.upsertMany(state, action.payload.entities); Object.entries(action.payload.entities) + // eslint-disable-next-line no-return-assign .forEach(([id, entity]) => state.uris[entity.uri] = id); }, }, diff --git a/src/client/resources/entity/trait-pane.jsx b/src/client/resources/entity/trait-pane.jsx index 50a3415..5e0f84e 100644 --- a/src/client/resources/entity/trait-pane.jsx +++ b/src/client/resources/entity/trait-pane.jsx @@ -1,6 +1,7 @@ import {mapObject} from '@avocado/core'; import {lookupTrait} from '@avocado/entity'; import {all as allTraitComponents} from '@avocado/entity/trait/trait-components.scwp'; +import PropTypes from 'prop-types'; import React, {useMemo} from 'react'; import {useDispatch} from 'react-redux'; @@ -84,4 +85,11 @@ const TraitPane = (props) => { ); }; +TraitPane.propTypes = { + context: PropTypes.shape({}).isRequired, + target: PropTypes.string.isRequired, + trait: PropTypes.shape({}).isRequired, + type: PropTypes.string.isRequired, +}; + export default TraitPane; diff --git a/src/client/resources/entity/trait-tab.jsx b/src/client/resources/entity/trait-tab.jsx index 1228232..3901fc7 100644 --- a/src/client/resources/entity/trait-tab.jsx +++ b/src/client/resources/entity/trait-tab.jsx @@ -1,3 +1,4 @@ +import PropTypes from 'prop-types'; import React from 'react'; const TraitTab = (props) => { @@ -11,4 +12,8 @@ const TraitTab = (props) => { ); }; +TraitTab.propTypes = { + type: PropTypes.string.isRequired, +}; + export default TraitTab; diff --git a/src/client/resources/entity/traits.jsx b/src/client/resources/entity/traits.jsx index 8b9a9f9..e9ded5d 100644 --- a/src/client/resources/entity/traits.jsx +++ b/src/client/resources/entity/traits.jsx @@ -76,6 +76,7 @@ const Traits = (props) => { Traits.propTypes = { context: PropTypes.shape({}).isRequired, + target: PropTypes.string.isRequired, traits: PropTypes.shape({}).isRequired, }; diff --git a/src/client/store.js b/src/client/store.js index 4d5a750..275b28b 100644 --- a/src/client/store.js +++ b/src/client/store.js @@ -8,8 +8,8 @@ import {all} from './resources.scwp'; const resources = Object.values(all()).map((M) => M.default); const reducerMap = resources.reduce( - (r, {keys, state: {'default': reducer}}) => ({...r, [keys[1]]: reducer}), - {} + (r, {keys, state: {default: reducer}}) => ({...r, [keys[1]]: reducer}), + {}, ); export default function createStore(options = {}) { diff --git a/yarn.lock b/yarn.lock index 1c1ee28..40321d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3346,6 +3346,11 @@ deepmerge@^2.2.1: resolved "https://npm.i12e.cha0s.io/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170" integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA== +deepmerge@^4.2.2: + version "4.2.2" + resolved "https://npm.i12e.cha0s.io/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" + integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== + default-gateway@^4.2.0: version "4.2.0" resolved "https://npm.i12e.cha0s.io/default-gateway/-/default-gateway-4.2.0.tgz#167104c7500c2115f6dd69b0a536bb8ed720552b" @@ -7796,7 +7801,7 @@ redux-thunk@^2.3.0: resolved "https://npm.i12e.cha0s.io/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622" integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw== -redux@^4.0.0: +redux@^4.0.0, redux@^4.0.5: version "4.0.5" resolved "https://npm.i12e.cha0s.io/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==