Skip to content

Commit

Permalink
Small formatting tweaks prettier eslint (shakacode#1261)
Browse files Browse the repository at this point in the history
* Only config changes
* Ran nps format
* update packages
* run prettier & eslint
  • Loading branch information
justin808 authored Mar 28, 2020
1 parent c593e20 commit f6db0ee
Show file tree
Hide file tree
Showing 53 changed files with 1,112 additions and 943 deletions.
7 changes: 6 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
node_modules
node_modules/
package.json
tmp/
public/webpack/
coverage/
**/app/assets/webpack/
10 changes: 5 additions & 5 deletions book.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"url": "https://github.com/shakacode/react_on_rails/"
},
"sharing": {
"facebook": true,
"twitter": true,
"google": true,
"weibo": true,
"facebook": true,
"twitter": true,
"google": true,
"weibo": true,
"instapaper": true,
"vk": true
"vk": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ export default class HelloWorld extends React.Component {
render() {
return (
<div>
<h3>
Hello, {this.state.name}!
</h3>
<h3>Hello, {this.state.name}!</h3>
<hr />
<form >
<form>
<label htmlFor="name">
Say hello to:
<input
id="name"
type="text"
value={this.state.name}
onChange={(e) => this.updateName(e.target.value)}
/>
</label>
<input
id="name"
type="text"
value={this.state.name}
onChange={(e) => this.updateName(e.target.value)}
/>
</form>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ import React from 'react';

const HelloWorld = ({ name, updateName }) => (
<div>
<h3>
Hello, {name}!
</h3>
<h3>Hello, {name}!</h3>
<hr />
<form >
<form>
<label htmlFor="name">
Say hello to:
<input id="name" type="text" value={name} onChange={(e) => updateName(e.target.value)} />
</label>
<input
id="name"
type="text"
value={name}
onChange={(e) => updateName(e.target.value)}
/>
</form>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createStore } from 'redux';
import helloWorldReducer from '../reducers/helloWorldReducer';

const configureStore = (railsProps) => (
createStore(helloWorldReducer, railsProps)
);
const configureStore = (railsProps) => createStore(helloWorldReducer, railsProps);

export default configureStore;
12 changes: 6 additions & 6 deletions node_package/tests/Authenticity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ describe('authenticityToken', () => {
it('exists in ReactOnRails API', () => {
expect.assertions(1);
expect(typeof ReactOnRails.authenticityToken).toEqual('function');
})
});

it('can read Rails CSRF token from <meta>', () => {
expect.assertions(1);
const realToken = ReactOnRails.authenticityToken();
expect(realToken).toEqual(testToken);
})
})
});
});

describe('authenticityHeaders', () => {
expect.assertions(2);
it('exists in ReactOnRails API', () => {
expect.assertions(1);
expect(typeof ReactOnRails.authenticityHeaders).toEqual('function');
})
});

it('returns valid header with CSRF token', () => {
expect.assertions(1);
const realHeader = ReactOnRails.authenticityHeaders();
expect(realHeader).toEqual({ 'X-CSRF-Token': testToken, 'X-Requested-With': 'XMLHttpRequest' });
})
})
});
});
46 changes: 29 additions & 17 deletions node_package/tests/ComponentRegistry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ describe('ComponentRegistry', () => {
expect.assertions(1);
class C3 extends React.Component {
render() {
return (
<div>Wow!</div>
);
return <div>Wow!</div>;
}
}
ComponentRegistry.register({ C3 });
Expand Down Expand Up @@ -70,10 +68,18 @@ describe('ComponentRegistry', () => {
ComponentRegistry.register({ C6 });
const components = ComponentRegistry.components();
expect(components.size).toBe(6);
expect(components.get('C5')).toEqual(
{ name: 'C5', component: C5, generatorFunction: true, isRenderer: false });
expect(components.get('C6')).toEqual(
{ name: 'C6', component: C6, generatorFunction: true, isRenderer: false });
expect(components.get('C5')).toEqual({
name: 'C5',
component: C5,
generatorFunction: true,
isRenderer: false,
});
expect(components.get('C6')).toEqual({
name: 'C6',
component: C6,
generatorFunction: true,
isRenderer: false,
});
});

it('only detects a renderer function if it has three arguments', () => {
Expand All @@ -83,24 +89,30 @@ describe('ComponentRegistry', () => {
ComponentRegistry.register({ C7 });
ComponentRegistry.register({ C8 });
const components = ComponentRegistry.components();
expect(components.get('C7')).toEqual(
{ name: 'C7', component: C7, generatorFunction: true, isRenderer: false });
expect(components.get('C8')).toEqual(
{ name: 'C8', component: C8, generatorFunction: true, isRenderer: false });
expect(components.get('C7')).toEqual({
name: 'C7',
component: C7,
generatorFunction: true,
isRenderer: false,
});
expect(components.get('C8')).toEqual({
name: 'C8',
component: C8,
generatorFunction: true,
isRenderer: false,
});
});

it('throws error for retrieving unregistered component', () => {
expect.assertions(1);
expect(() => ComponentRegistry.get('foobar')).toThrow(
/Could not find component registered with name foobar/
/Could not find component registered with name foobar/,
);
});

it('throws error for setting null component', () => {
expect.assertions(1);
const C9 = null;
expect(() => ComponentRegistry.register({ C9 })).toThrow(
/Called register with null component named C9/
);
})
})
expect(() => ComponentRegistry.register({ C9 })).toThrow(/Called register with null component named C9/);
});
});
29 changes: 9 additions & 20 deletions node_package/tests/ReactOnRails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ describe('ReactOnRails', () => {
expect.assertions(1);
const R1 = createReactClass({
render() {
return (
<div> WORLD </div>
);
return <div> WORLD </div>;
},
});
ReactOnRails.register({ R1 });
Expand Down Expand Up @@ -46,33 +44,25 @@ describe('ReactOnRails', () => {
it('not specified has traceTurbolinks as false', () => {
ReactOnRails.resetOptions();
expect.assertions(1);
ReactOnRails.setOptions({ });
ReactOnRails.setOptions({});
const actual = ReactOnRails.option('traceTurbolinks');
expect(actual).toBe(false);
});

it('setOptions method throws error for invalid options', () => {
ReactOnRails.resetOptions();
expect.assertions(1);
expect(
() => ReactOnRails.setOptions({ foobar: true })
).toThrow(/Invalid option/);
expect(() => ReactOnRails.setOptions({ foobar: true })).toThrow(/Invalid option/);
});

it('registerStore throws if passed a falsey object (null, undefined, etc)', () => {
expect.assertions(3);

expect(
() => ReactOnRails.registerStore(null)
).toThrow(/null or undefined/);
expect(() => ReactOnRails.registerStore(null)).toThrow(/null or undefined/);

expect(
() => ReactOnRails.registerStore(undefined)
).toThrow(/null or undefined/);
expect(() => ReactOnRails.registerStore(undefined)).toThrow(/null or undefined/);

expect(
() => ReactOnRails.registerStore(false)
).toThrow(/null or undefined/);
expect(() => ReactOnRails.registerStore(false)).toThrow(/null or undefined/);
});

it('register store and getStoreGenerator allow registration', () => {
Expand All @@ -88,7 +78,7 @@ describe('ReactOnRails', () => {
ReactOnRails.registerStore({ storeGenerator });

const actual = ReactOnRails.getStoreGenerator('storeGenerator');
expect(actual).toEqual(storeGenerator)
expect(actual).toEqual(storeGenerator);

expect(ReactOnRails.storeGenerators()).toEqual(new Map([['storeGenerator', storeGenerator]]));
});
Expand Down Expand Up @@ -125,7 +115,6 @@ describe('ReactOnRails', () => {
return createStore(reducer, props);
}


const result = storeGenerator({});
ReactOnRails.setStore('storeGenerator', result);
const actual = new Map();
Expand All @@ -135,5 +124,5 @@ describe('ReactOnRails', () => {
ReactOnRails.clearHydratedStores();
const expected = new Map();
expect(ReactOnRails.stores()).toEqual(expected);
})
})
});
});
13 changes: 5 additions & 8 deletions node_package/tests/StoreRegistry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('', () => {
expect.assertions(2);
StoreRegistry.stores().clear();
expect(() => StoreRegistry.register({ storeGenerator: null })).toThrow(
/Called ReactOnRails.registerStores with a null or undefined as a value/
/Called ReactOnRails.registerStores with a null or undefined as a value/,
);
expect(() => StoreRegistry.register({ storeGenerator: undefined })).toThrow(
/Called ReactOnRails.registerStores with a null or undefined as a value/,
Expand Down Expand Up @@ -53,16 +53,13 @@ describe('', () => {
);
});

it('StoreRegistry returns undefined for retrieving unregistered store, ' +
'passing throwIfMissing = false',
() => {
it('StoreRegistry returns undefined for retrieving unregistered store, passing throwIfMissing = false', () => {
expect.assertions(1);
StoreRegistry.setStore('foobarX', {});
const actual = StoreRegistry.getStore('foobar', false);
const expected = undefined;
expect(actual).toEqual(expected);
},
);
});

it('StoreRegistry getStore, setStore', () => {
expect.assertions(1);
Expand Down Expand Up @@ -93,5 +90,5 @@ describe('', () => {
StoreRegistry.clearHydratedStores();
const expected = new Map();
expect(StoreRegistry.stores()).toEqual(expected);
})
})
});
});
11 changes: 5 additions & 6 deletions node_package/tests/buildConsoleReplay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ describe('consoleReplay', () => {
{ arguments: ['c', 'd'], level: 'warn' },
];
const actual = consoleReplay();
const expected =
'console.log.apply(console, ["a","b"]);\nconsole.warn.apply(console, ["c","d"]);';
const expected = 'console.log.apply(console, ["a","b"]);\nconsole.warn.apply(console, ["c","d"]);';
expect(actual).toEqual(expected);
});

Expand All @@ -58,8 +57,8 @@ console.warn.apply(console, ["other message","{\\"c\\":3,\\"d\\":4}"]);`;
console.history = [
{
arguments: [
'some message </script><script>alert(\'WTF\')</script>',
{ a: 'Wow</script><script>alert(\'WTF\')</script>', b: 2 },
"some message </script><script>alert('WTF')</script>",
{ a: "Wow</script><script>alert('WTF')</script>", b: 2 },
],
level: 'log',
},
Expand Down Expand Up @@ -89,5 +88,5 @@ console.warn.apply(console, ["other message","{\\"c\\":3,\\"d\\":4}"]);
</script>`;

expect(actual).toEqual(expected);
})
})
});
});
16 changes: 8 additions & 8 deletions node_package/tests/generatorFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('generatorFunction', () => {

const es5Component = createReactClass({
render() {
return (<div>ES5 React Component</div>);
return <div>ES5 React Component</div>;
},
});

Expand All @@ -27,7 +27,7 @@ describe('generatorFunction', () => {

class ES6Component extends React.Component {
render() {
return (<div>ES6 Component</div>);
return <div>ES6 Component</div>;
}
}

Expand All @@ -39,13 +39,13 @@ describe('generatorFunction', () => {

class ES6Component extends React.Component {
render() {
return (<div>ES6 Component</div>);
return <div>ES6 Component</div>;
}
}

class ES6ComponentChild extends ES6Component {
render() {
return (<div>ES6 Component Child</div>);
return <div>ES6 Component Child</div>;
}
}

Expand All @@ -56,7 +56,7 @@ describe('generatorFunction', () => {
expect.assertions(1);

/* eslint-disable react/prop-types */
const pureComponent = (props) => <h1>{ props.title }</h1>;
const pureComponent = (props) => <h1>{props.title}</h1>;
/* eslint-enable react/prop-types */

expect(generatorFunction(pureComponent)).toBe(true);
Expand All @@ -67,7 +67,7 @@ describe('generatorFunction', () => {

const foobarComponent = createReactClass({
render() {
return (<div>Component for Generator Function</div>);
return <div>Component for Generator Function</div>;
},
});

Expand All @@ -85,5 +85,5 @@ describe('generatorFunction', () => {
},
};
expect(generatorFunction(foobarComponent)).toBe(false);
})
})
});
});
Loading

0 comments on commit f6db0ee

Please sign in to comment.