Skip to content

Commit 73f16bf

Browse files
committed
Fix of ESLint errors + type prop added to <Button> component
Fix for #11
1 parent bb08939 commit 73f16bf

29 files changed

+171
-83
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
- Also most of NPM dependencies updated to their latest versions, which might
2727
demand some fixes in your code.
2828

29+
- Adds optional `type` prop to [`<Button>`](docs/button.md)
30+
2931
### v0.5.0
3032
All dependencies are force-updated to their latest versions. It might introduce
3133
breaking changes.

__tests__/server/renderer.jsx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ const TEST_WEBPACK_CONFIG = {
4040
},
4141
};
4242

43-
const testBuildInfo =
44-
JSON.parse(fs.readFileSync(`${TEST_CONTEXT}/.build-info`));
43+
const testBuildInfo = JSON.parse(
44+
fs.readFileSync(`${TEST_CONTEXT}/.build-info`),
45+
);
4546

4647
beforeAll(() => {
4748
Helmet.canUseDOM = false;
@@ -84,11 +85,11 @@ async function coreTest(webpackConfig, options) {
8485
}
8586
}
8687

87-
test('Base rendering of HTML template', () =>
88-
coreTest(TEST_WEBPACK_CONFIG, {}));
88+
test('Base rendering of HTML template',
89+
() => coreTest(TEST_WEBPACK_CONFIG, {}));
8990

90-
test('Config overriding for injection', () =>
91-
coreTest(TEST_WEBPACK_CONFIG, {
91+
test('Config overriding for injection',
92+
() => coreTest(TEST_WEBPACK_CONFIG, {
9293
beforeRender: async (res, sanitizedConfig) => {
9394
expect(res).toEqual(TEST_HTTP_REQUEST);
9495
expect(sanitizedConfig).toBeInstanceOf(Object);
@@ -102,22 +103,28 @@ test('Config overriding for injection', () =>
102103
},
103104
}));
104105

105-
test('Hemlet integration works', () =>
106-
coreTest(TEST_WEBPACK_CONFIG, {
106+
test('Hemlet integration works',
107+
() => coreTest(TEST_WEBPACK_CONFIG, {
107108
Application: () => (
108109
<div>
109-
<p>Hello World!</p>
110+
<p>
111+
Hello World!
112+
</p>
110113
<Helmet>
111-
<title>Test Page Title</title>
114+
<title>
115+
Test Page Title
116+
</title>
112117
<meta property="description" content="Test Page Description" />
113118
</Helmet>
114-
<p>Goodbye World!</p>
119+
<p>
120+
Goodbye World!
121+
</p>
115122
</div>
116123
),
117124
}));
118125

119-
test('Injection of additional JS scripts', () =>
120-
coreTest(TEST_WEBPACK_CONFIG, {
126+
test('Injection of additional JS scripts',
127+
() => coreTest(TEST_WEBPACK_CONFIG, {
121128
beforeRender: async () => ({
122129
extraScripts: [
123130
'<script>Dummy JS Sript</script>',
@@ -126,14 +133,18 @@ test('Injection of additional JS scripts', () =>
126133
}),
127134
}));
128135

129-
test('Server-side rendering (SSR); injection of CSS chunks & Redux state', () =>
130-
coreTest(TEST_WEBPACK_CONFIG, {
136+
test('Server-side rendering (SSR); injection of CSS chunks & Redux state',
137+
() => coreTest(TEST_WEBPACK_CONFIG, {
131138
Application: () => (
132139
<Route
133140
component={({ staticContext }) => {
134141
staticContext.chunks.push('test-chunk-a');
135142
staticContext.chunks.push('test-chunk-b');
136-
return <div>Hello Wold!</div>;
143+
return (
144+
<div>
145+
Hello Wold!
146+
</div>
147+
);
137148
}}
138149
/>
139150
),
@@ -148,7 +159,11 @@ test('Setting of response HTTP status the server-side rendering', () => {
148159
<Route
149160
component={({ staticContext }) => {
150161
staticContext.status = 404; // eslint-disable-line no-param-reassign
151-
return <div>404 Error Test</div>;
162+
return (
163+
<div>
164+
404 Error Test
165+
</div>
166+
);
152167
}}
153168
/>
154169
),

__tests__/server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jest.mock('webpack', () => {
1313
return mock;
1414
});
1515

16-
jest.mock('webpack-hot-middleware', () =>
17-
jest.fn(() => (req, res, next) => next()));
16+
jest.mock('webpack-hot-middleware',
17+
() => jest.fn(() => (req, res, next) => next()));
1818

1919
const TEST_CONTEXT = `${__dirname}/test_data`;
2020

__tests__/shared/actions/collection.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ afterAll(() => MockDate.reset());
1313

1414
test('Exports expected actions', () => expect(actions).toMatchSnapshot());
1515

16-
test('`addItems` payload creator', () =>
17-
expect(a.addItems({ id1: 'Item 1', id2: 'Item 2' })).toMatchSnapshot());
16+
test('`addItems` payload creator',
17+
() => expect(a.addItems({ id1: 'Item 1', id2: 'Item 2' })).toMatchSnapshot());
1818

1919
test('`bookItems` payload creator', () => {
2020
expect(a.bookItems('id1')).toMatchSnapshot();
@@ -33,8 +33,9 @@ test('`freeItems` payload creator', () => {
3333
expect(a.freeItems(['id1', 'id2', 'id3'])).toMatchSnapshot();
3434
});
3535

36-
test('`loadItemInit` payload creator', () =>
37-
expect(a.loadItemInit('operation-id', 'item-id')).toMatchSnapshot());
36+
test('`loadItemInit` payload creator',
37+
() => expect(a.loadItemInit('operation-id', 'item-id')).toMatchSnapshot());
3838

39-
test('`loadItemDone` payload creator', () =>
40-
expect(a.loadItemDone('operation-id', 'item-id', 'item')).toMatchSnapshot());
39+
test('`loadItemDone` payload creator', () => {
40+
expect(a.loadItemDone('operation-id', 'item-id', 'item')).toMatchSnapshot();
41+
});

__tests__/shared/actions/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
import actions from 'actions';
66

7-
test('Exports expected actions', () =>
8-
expect(actions).toMatchSnapshot());
7+
test('Exports expected actions',
8+
() => expect(actions).toMatchSnapshot());

__tests__/shared/components/Button.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,3 @@ describe('Matches snapshots', () => {
7676
));
7777
});
7878
});
79-

__tests__/shared/components/GenericLink.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
import GenericLink from 'components/GenericLink';
44
import PT from 'prop-types';
55
import React from 'react';
6-
import { findInDomByClass, renderDom, simulate, snapshot } from 'utils/jest';
6+
import {
7+
findInDomByClass,
8+
renderDom,
9+
simulate,
10+
snapshot,
11+
} from 'utils/jest';
712

813
function Link(props) {
14+
const { className, onClick } = props;
915
return (
1016
<button
11-
onClick={props.onClick}
12-
className={props.className}
17+
onClick={onClick}
18+
className={className}
19+
type="button"
1320
>
1421
{JSON.stringify(props)}
1522
</button>

__tests__/shared/components/ScalableRect.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import React from 'react';
33
import { snapshot } from 'utils/jest';
44

55
test('Snapshots match', () => {
6-
snapshot(<ScalableRect>CONTENT</ScalableRect>);
6+
snapshot((
7+
<ScalableRect>
8+
CONTENT
9+
</ScalableRect>
10+
));
711
snapshot((
812
<ScalableRect
913
className="CLASS_NAME"

__tests__/shared/components/__snapshots__/Button.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ exports[`Matches snapshots when active 1`] = `
55
className="BUTTON_CLASS ACTIVE_CLASS REGULAR_CLASS"
66
onClick={[Function]}
77
onMouseDown={null}
8+
type="button"
89
>
910
BUTTON
1011
</button>
@@ -15,6 +16,7 @@ exports[`Matches snapshots when active 2`] = `
1516
className="BUTTON_CLASS ACTIVE_CLASS"
1617
onClick={[Function]}
1718
onMouseDown={null}
19+
type="button"
1820
>
1921
BUTTON
2022
</button>

__tests__/shared/components/__snapshots__/GenericLink.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`Matches snapshots in a minimalistic example 1`] = `
44
<button
55
className={null}
66
onClick={[Function]}
7+
type="button"
78
>
89
{"to":"SOME/TEST/URL","className":null,"onMouseDown":null,"replace":false,"children":"LINK"}
910
</button>

config/babel/node-ssr.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ config.plugins = config.plugins.concat([
1717
['css-modules-transform', cssModulesTransformPluginOps],
1818
]);
1919

20-
const moduleResolverPluginOps
21-
= config.plugins.find(x => x[0] === 'module-resolver')[1];
20+
const moduleResolverPluginOps = config.plugins.find(
21+
x => x[0] === 'module-resolver',
22+
)[1];
2223

2324
moduleResolverPluginOps.transformFunctions = [
2425
'resolveWeak',
@@ -41,7 +42,7 @@ switch (process.env.BABEL_ENV) {
4142

4243
module.exports = (apt, ops = {}) => {
4344
const baseAssetsOutputPath = ops.baseAssetsOutputPath || '';
44-
transformAssetsPluginOptions.name
45-
= `${baseAssetsOutputPath}/images/[hash].[ext]`;
45+
transformAssetsPluginOptions.name = `${
46+
baseAssetsOutputPath}/images/[hash].[ext]`;
4647
return config;
4748
};

config/webpack/app-development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
const _ = require('lodash');
6-
const baseFactory = require('./app-base');
76
const webpack = require('webpack');
87
const webpackMerge = require('webpack-merge');
8+
const baseFactory = require('./app-base');
99

1010
/**
1111
* Creates a new development Webpack config, and performs some auxiliary

config/webpack/app-production.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* Production Webpack configuration for ReactJS applications.
33
*/
44

5-
const baseFactory = require('./app-base');
65
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
76
const webpack = require('webpack');
87
const webpackMerge = require('webpack-merge');
8+
const baseFactory = require('./app-base');
99

1010
/**
1111
* Creates a new production Webpack config, and performs some auxiliary

config/webpack/lib-base.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,3 @@ module.exports = function configFactory(ops) {
161161
},
162162
};
163163
};
164-

config/webpack/lib-development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Development Webpack configuration for ReactJS libraries.
33
*/
44

5-
const baseFactory = require('./lib-base');
65
const path = require('path');
6+
const baseFactory = require('./lib-base');
77

88
/**
99
* Creates a new Webpack config.

config/webpack/lib-production.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Development Webpack configuration for ReactJS libraries.
33
*/
44

5-
const baseFactory = require('./lib-base');
65
const path = require('path');
6+
const baseFactory = require('./lib-base');
77

88
/**
99
* Creates a new Webpack config.

docs/button.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ supposed to have the following fields:
6060
- **`to`** &mdash; *Object* or *String* &mdash; When specified, the button will
6161
be rendered as `<Link>` (if non-disabled), and it will point to the specified
6262
URL/location.
63+
- **`type`** &mdash; *String* &mdash; Optional. Button type. It will have
64+
effect only when Button is rendered as `<button>`.
6365

6466
### <a name="examples">Examples</a>
6567
First of all, you want to define button theme, here is a good example to start from:

src/client/index.jsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ import { BrowserRouter } from 'react-router-dom';
1616
* @param {Object} store Optional. Redux store.
1717
*/
1818
function render(Application, store) {
19-
let app = <BrowserRouter><Application /></BrowserRouter>;
20-
if (store) app = <Provider store={store}>{app}</Provider>;
19+
let app = (
20+
<BrowserRouter>
21+
<Application />
22+
</BrowserRouter>
23+
);
24+
if (store) {
25+
app = (
26+
<Provider store={store}>
27+
{app}
28+
</Provider>
29+
);
30+
}
2131
ReactDom.hydrate(app, document.getElementById('react-view'));
2232
}
2333

@@ -43,8 +53,8 @@ export default async function Launch({
4353
render(getApplication(), store);
4454

4555
if (moduleHot && applicationModulePath) {
46-
moduleHot.accept(applicationModulePath, () =>
47-
render(getApplication(), store));
56+
moduleHot.accept(applicationModulePath,
57+
() => render(getApplication(), store));
4858

4959
/* HMR of CSS code each time webpack hot middleware updates the code. */
5060
/* eslint-disable no-underscore-dangle */

src/server/renderer.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ export default function factory(webpackConfig, options) {
109109
</StaticRouter>
110110
);
111111

112-
if (store) App = <Provider store={store}>{App}</Provider>;
112+
if (store) {
113+
App = (
114+
<Provider store={store}>
115+
{App}
116+
</Provider>
117+
);
118+
}
113119

114120
App = ReactDOM.renderToString(App);
115121

0 commit comments

Comments
 (0)