Skip to content

Commit b910451

Browse files
committed
chore: client: storage: lint
1 parent e695124 commit b910451

File tree

8 files changed

+46
-84
lines changed

8 files changed

+46
-84
lines changed

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@putout/plugin-nodejs": "^17.0.0",
2525
"@putout/plugin-types": "^8.0.0",
2626
"@putout/plugin-variables": "^1.3.1",
27+
"acorn-private-methods": "^1.0.0",
2728
"acorn-stage3": "^4.0.0",
2829
"assert": "^2.0.0",
2930
"autoprefixer": "^10.0.1",

client/src/app.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1+
import PropTypes from 'prop-types';
2+
import PubSub from 'pubsub-js';
3+
import React from 'react';
4+
import createSagaMiddleware from 'redux-saga';
5+
import {Provider, connect} from 'react-redux';
6+
import {
7+
createStore,
8+
applyMiddleware,
9+
compose,
10+
} from 'redux';
11+
import {enableBatching} from 'redux-batched-actions';
12+
import {createRoot} from 'react-dom/client';
113
import * as LocalStorage from './components/LocalStorage';
214
import ASTOutputContainer from './containers/ASTOutputContainer';
315
import CodeEditorContainer from './containers/CodeEditorContainer';
416
import ErrorMessageContainer from './containers/ErrorMessageContainer';
517
import GistBanner from './components/GistBanner';
618
import LoadingIndicatorContainer from './containers/LoadingIndicatorContainer';
719
import PasteDropTargetContainer from './containers/PasteDropTargetContainer';
8-
import PropTypes from 'prop-types';
9-
import PubSub from 'pubsub-js';
10-
import React from 'react';
1120
import SettingsDialogContainer from './containers/SettingsDialogContainer';
1221
import ShareDialogContainer from './containers/ShareDialogContainer';
1322
import SplitPane from './components/SplitPane';
1423
import ToolbarContainer from './containers/ToolbarContainer';
1524
import TransformerContainer from './containers/TransformerContainer';
16-
import createSagaMiddleware from 'redux-saga';
1725
import debounce from './utils/debounce';
1826
import saga from './store/sagas';
19-
import {
20-
Provider,
21-
connect,
22-
} from 'react-redux';
2327
import {
2428
astexplorer,
2529
persist,
2630
revive,
2731
} from './store/reducers';
28-
import {
29-
createStore,
30-
applyMiddleware,
31-
compose,
32-
} from 'redux';
3332
import {
3433
canSaveTransform,
3534
getRevision,
3635
} from './store/selectors';
37-
import {enableBatching} from 'redux-batched-actions';
3836
import {loadSnippet} from './store/actions';
39-
import {createRoot} from 'react-dom/client';
4037
import * as gist from './storage/gist';
4138
import * as parse from './storage/parse';
4239
import StorageHandler from './storage';
@@ -106,9 +103,8 @@ store.subscribe(debounce(() => {
106103
const state = store.getState();
107104

108105
// We are not persisting the state while looking at an existing revision
109-
if (!getRevision(state)) {
106+
if (!getRevision(state))
110107
LocalStorage.writeState(persist(state));
111-
}
112108
}));
113109
sagaMiddleware.run(saga, new StorageHandler([gist, parse]));
114110
store.dispatch({
@@ -126,14 +122,12 @@ global.onhashchange = () => {
126122
store.dispatch(loadSnippet());
127123
};
128124

129-
if (location.hash.length > 1) {
125+
if (location.hash.length > 1)
130126
store.dispatch(loadSnippet());
131-
}
132127

133128
global.onbeforeunload = () => {
134129
const state = store.getState();
135130

136-
if (canSaveTransform(state)) {
131+
if (canSaveTransform(state))
137132
return 'You have unsaved transform code. Do you really want to leave?';
138-
}
139133
};

client/src/containers/ToolbarContainer.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {connect} from 'react-redux';
2+
import Toolbar from '../components/Toolbar';
3+
import * as selectors from '../store/selectors';
4+
import {logEvent} from '../utils/logger';
25
import {
36
save,
47
selectCategory,
@@ -10,9 +13,6 @@ import {
1013
reset,
1114
setKeyMap,
1215
} from '../store/actions';
13-
import Toolbar from '../components/Toolbar';
14-
import * as selectors from '../store/selectors';
15-
import {logEvent} from '../utils/logger';
1616

1717
function mapStateToProps(state) {
1818
const parser = selectors.getParser(state);
@@ -52,25 +52,22 @@ function mapDispatchToProps(dispatch) {
5252
onTransformChange: (transformer) => {
5353
dispatch(transformer ? selectTransformer(transformer) : hideTransformer());
5454

55-
if (transformer) {
55+
if (transformer)
5656
logEvent('tool', 'select', transformer.id);
57-
}
5857
},
5958
onKeyMapChange: (keyMap) => {
6059
dispatch(setKeyMap(keyMap));
6160

62-
if (keyMap) {
61+
if (keyMap)
6362
logEvent('keyMap', keyMap);
64-
}
6563
},
6664
onSave: () => dispatch(save(false)),
6765
onFork: () => dispatch(save(true)),
6866
onNew: () => {
69-
if (global.location.hash) {
67+
if (global.location.hash)
7068
global.location.hash = '';
71-
} else {
69+
else
7270
dispatch(reset());
73-
}
7471
},
7572
};
7673
}

client/src/storage/gist.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import {getParserByID} from '../parsers';
55
function getIDAndRevisionFromHash() {
66
const match = global.location.hash.match(/^#\/gist\/([^/]+)(?:\/[^/]+)?/);
77

8-
if (match) {
8+
if (match)
99
return {
1010
id: match[1],
1111
rev: match[2],
1212
};
13-
}
1413

1514
return null;
1615
}
@@ -20,9 +19,8 @@ function fetchSnippet(snippetID, revisionID = 'latest') {
2019
method: 'GET',
2120
})
2221
.then((response) => {
23-
if (response.ok) {
22+
if (response.ok)
2423
return response.json();
25-
}
2624

2725
switch(response.status) {
2826
case 404:
@@ -35,9 +33,7 @@ function fetchSnippet(snippetID, revisionID = 'latest') {
3533
.then((response) => new Revision(response));
3634
}
3735

38-
export function owns(snippet) {
39-
return snippet instanceof Revision;
40-
}
36+
export const owns = (snippet) => snippet instanceof Revision;
4137

4238
export function matchesURL() {
4339
return getIDAndRevisionFromHash() !== null;
@@ -46,9 +42,8 @@ export function matchesURL() {
4642
export function fetchFromURL() {
4743
const data = getIDAndRevisionFromHash();
4844

49-
if (!data) {
45+
if (!data)
5046
return Promise.resolve(null);
51-
}
5247

5348
return fetchSnippet(data.id, data.rev);
5449
}
@@ -65,9 +60,8 @@ export function create(data) {
6560
body: JSON.stringify(data),
6661
})
6762
.then((response) => {
68-
if (response.ok) {
63+
if (response.ok)
6964
return response.json();
70-
}
7165

7266
throw Error('Unable to create snippet.');
7367
})
@@ -94,9 +88,8 @@ export function update(revision, data) {
9488
body: JSON.stringify(data),
9589
})
9690
.then((response) => {
97-
if (response.ok) {
91+
if (response.ok)
9892
return response.json();
99-
}
10093

10194
throw Error('Unable to update snippet.');
10295
})
@@ -116,9 +109,8 @@ export function fork(revision, data) {
116109
body: JSON.stringify(data),
117110
})
118111
.then((response) => {
119-
if (response.ok) {
112+
if (response.ok)
120113
return response.json();
121-
}
122114

123115
throw Error('Unable to fork snippet.');
124116
})
@@ -161,9 +153,8 @@ class Revision {
161153
}
162154

163155
getCode() {
164-
if (this._code == null) {
156+
if (this._code == null)
165157
this._code = getSource(this._config, this._gist) || '';
166-
}
167158

168159
return this._code;
169160
}

client/src/storage/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ export default class StorageHandler {
99

1010
_owns(revision) {
1111
for (const backend of this._backends) {
12-
if (backend.owns(revision)) {
12+
if (backend.owns(revision))
1313
return backend;
14-
}
1514
}
1615

1716
return null;
@@ -22,19 +21,16 @@ export default class StorageHandler {
2221
}
2322

2423
fetchFromURL() {
25-
if (/^#?\/?$/.test(global.location.hash)) {
24+
if (/^#?\/?$/.test(global.location.hash))
2625
return Promise.resolve(null);
27-
}
2826

2927
for (const backend of this._backends) {
30-
if (backend.matchesURL()) {
28+
if (backend.matchesURL())
3129
return backend.fetchFromURL();
32-
}
3330
}
3431

3532
return Promise.reject(Error('Unknown URL format.'));
3633
}
37-
3834
/**
3935
* Create a new snippet.
4036
*/
@@ -43,7 +39,6 @@ export default class StorageHandler {
4339
._first()
4440
.create(data);
4541
}
46-
4742
/**
4843
* Update an existing snippet.
4944
*/
@@ -52,7 +47,6 @@ export default class StorageHandler {
5247
._first()
5348
.update(revision, data);
5449
}
55-
5650
/**
5751
* Fork existing snippet.
5852
*/

client/src/storage/parse.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@ import {
88
function getIDAndRevisionFromHash() {
99
const match = global.location.hash.match(/^#\/(?!gist\/)([^/]+)(?:\/(latest|\d*))?/);
1010

11-
if (match) {
11+
if (match)
1212
return {
1313
id: match[1],
1414
rev: match[2] || 0,
1515
};
16-
}
1716

1817
return null;
1918
}
2019

2120
function fetchSnippet(snippetID, revisionID = 'latest') {
2221
return api(`/parse/${snippetID}/${revisionID}`)
2322
.then((response) => {
24-
if (response.ok) {
23+
if (response.ok)
2524
return response.json();
26-
}
2725

2826
switch(response.status) {
2927
case 404:
@@ -36,27 +34,23 @@ function fetchSnippet(snippetID, revisionID = 'latest') {
3634
.then((response) => new Revision(response));
3735
}
3836

39-
export function owns(snippet) {
40-
return snippet instanceof Revision;
41-
}
37+
export const owns = (snippet) => snippet instanceof Revision;
4238

4339
export function matchesURL() {
4440
return getIDAndRevisionFromHash() !== null;
4541
}
4642

4743
export function updateHash(revision) {
4844
const rev = revision.getRevisionID();
49-
const newHash = '/' + revision.getSnippetID() + (rev ? `/${rev}` : '');
5045

51-
global.location.hash = newHash;
46+
global.location.hash = '/' + revision.getSnippetID() + (rev ? `/${rev}` : '');
5247
}
5348

5449
export function fetchFromURL() {
5550
const urlParameters = getIDAndRevisionFromHash();
5651

57-
if (urlParameters) {
52+
if (urlParameters)
5853
return fetchSnippet(urlParameters.id, urlParameters.rev);
59-
}
6054

6155
return Promise.resolve(null);
6256
}
@@ -111,9 +105,8 @@ class Revision {
111105
getTransformCode() {
112106
const {transform} = this._data;
113107

114-
if (transform) {
108+
if (transform)
115109
return transform;
116-
}
117110

118111
if (this._data.toolID) {
119112
// Default transforms where never stored
@@ -126,9 +119,8 @@ class Revision {
126119
getParserID() {
127120
const transformerID = this.getTransformerID();
128121

129-
if (transformerID) {
122+
if (transformerID)
130123
return getTransformerByID(transformerID).defaultParserID;
131-
}
132124

133125
return this._data.parserID;
134126
}
@@ -143,9 +135,8 @@ class Revision {
143135
getParserSettings() {
144136
const {settings} = this._data;
145137

146-
if (!settings) {
138+
if (!settings)
147139
return null;
148-
}
149140

150141
const parserSettings = settings[this.getParserID()];
151142

client/src/utils/debounce.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export default function debounce(f, timeout = 100) {
77
lastThis = this;
88
lastArgs = args;
99

10-
if (timer) {
10+
if (timer)
1111
return;
12-
}
1312

1413
timer = setTimeout(() => {
1514
timer = null;
1615
f.apply(lastThis, lastArgs);
1716
}, timeout);
1817
};
1918
}
20-

0 commit comments

Comments
 (0)