Skip to content

Commit 6c8f63b

Browse files
committed
cleanup(prettier): start using prettier
- Install all the plugins needed to run prettier with eslint - Update eslintrc - Add `lint` and `eslint-check` commands To keep things pretty: `yarn lint`
1 parent b89ce8d commit 6c8f63b

File tree

6 files changed

+441
-357
lines changed

6 files changed

+441
-357
lines changed

.eslintrc

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
2-
"extends": "eslint-config-rackt",
3-
"env": {
4-
"browser": true,
5-
"mocha": true,
6-
"node": true
7-
},
2+
"parser": "babel-eslint",
83
"rules": {
9-
"valid-jsdoc": 2,
10-
"react/jsx-uses-react": 1,
11-
"react/jsx-no-undef": 2,
12-
"react/wrap-multilines": 2,
13-
"comma-dangle": [2, "always-multiline"],
14-
"quotes": [2, "double"]
4+
"prettier/prettier": ["error", { "trailingComma": "es5", "semi": false }],
5+
"react/jsx-uses-vars": "error",
6+
"react/jsx-uses-react": "error",
157
},
168
"plugins": [
17-
"react"
18-
]
9+
"prettier",
10+
"react",
11+
],
12+
"extends": [
13+
"eslint:recommended",
14+
"prettier",
15+
"prettier/react",
16+
],
17+
"globals": {
18+
"document": true,
19+
},
1920
}

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"dev:dist": "NODE_ENV=production webpack --watch",
1717
"dev:lib": "babel ./src --out-dir ./lib --stage 0 --watch",
1818
"test": "echo \"Error: no test specified\" && exit 1",
19+
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
20+
"lint": "eslint --ext=js,jsx --fix src",
1921
"prepublish": "npm run build"
2022
},
2123
"files": [
@@ -28,15 +30,17 @@
2830
"devDependencies": {
2931
"babel": "^6.5.2",
3032
"babel-cli": "^6.7.7",
31-
"babel-eslint": "^6.0.3",
33+
"babel-eslint": "^7.2.3",
3234
"babel-loader": "^6.2.4",
3335
"babel-plugin-transform-object-assign": "^6.8.0",
3436
"babel-preset-es2015": "^6.6.0",
3537
"babel-preset-react": "^6.5.0",
3638
"babel-preset-stage-2": "^6.5.0",
37-
"eslint": "^2.8.0",
39+
"eslint": "^4.5.0",
3840
"eslint-config-rackt": "^1.1.1",
39-
"eslint-plugin-react": "^5.0.1",
41+
"eslint-plugin-prettier": "^2.2.0",
42+
"eslint-plugin-react": "^7.3.0",
43+
"prettier": "^1.6.1",
4044
"react": "^15.0.1",
4145
"webpack": "^1.13.0"
4246
},
@@ -51,6 +55,7 @@
5155
]
5256
},
5357
"dependencies": {
58+
"eslint-config-prettier": "^2.3.0",
5459
"prop-types": "^15.5.10"
5560
}
5661
}

src/forms.jsx

+9-22
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { whitelistProps } from "./utils"
66
export const FormTag = React.createClass({
77
propTypes: {
88
url: PropTypes.string.isRequired,
9-
method: PropTypes.oneOf([ "get", "post", "put", "patch", "delete" ]),
9+
method: PropTypes.oneOf(["get", "post", "put", "patch", "delete"]),
1010
csrfToken: PropTypes.string,
1111
children: PropTypes.node,
1212
},
@@ -27,7 +27,8 @@ export const FormTag = React.createClass({
2727
fakedHTTPMethod = this.props.method
2828
}
2929

30-
const csrfToken = this.props.csrfToken ||
30+
const csrfToken =
31+
this.props.csrfToken ||
3132
document.querySelector("head meta[name='csrf-token']").content
3233

3334
return (
@@ -36,30 +37,20 @@ export const FormTag = React.createClass({
3637
acceptCharset="UTF-8"
3738
action={this.props.url}
3839
method={browserHTTPMethod}
39-
>
40+
>
4041
{fakedHTTPMethod && (
41-
<HiddenFieldTag
42-
name="_method"
43-
value={fakedHTTPMethod}
44-
/>
42+
<HiddenFieldTag name="_method" value={fakedHTTPMethod} />
4543
)}
4644
{csrfToken && (
47-
<HiddenFieldTag
48-
name="authenticity_token"
49-
value={csrfToken}
50-
/>
45+
<HiddenFieldTag name="authenticity_token" value={csrfToken} />
5146
)}
52-
<HiddenFieldTag
53-
name="utf8"
54-
value="&#x2713;"
55-
/>
47+
<HiddenFieldTag name="utf8" value="&#x2713;" />
5648
{this.props.children}
5749
</form>
5850
)
5951
},
6052
})
6153

62-
6354
export const FormFor = React.createClass({
6455
propTypes: {
6556
name: PropTypes.string,
@@ -77,16 +68,12 @@ export const FormFor = React.createClass({
7768

7869
getChildContext() {
7970
return {
80-
railsFormNamespaces: this.props.name ? [ this.props.name ] : [],
71+
railsFormNamespaces: this.props.name ? [this.props.name] : [],
8172
}
8273
},
8374

8475
render() {
85-
return (
86-
<FormTag {...this.props}>
87-
{this.props.children}
88-
</FormTag>
89-
)
76+
return <FormTag {...this.props}>{this.props.children}</FormTag>
9077
},
9178
})
9279

src/tags.jsx

+26-60
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { whitelistProps } from "./utils"
22

3-
export const CheckBoxTag = ({ checkedValue = 1, uncheckedValue = 0, ...props }) => {
3+
export const CheckBoxTag = ({
4+
checkedValue = 1,
5+
uncheckedValue = 0,
6+
...props
7+
}) => {
48
return (
59
<span>
610
<HiddenFieldTag name={props.name} value={uncheckedValue} />
@@ -9,86 +13,48 @@ export const CheckBoxTag = ({ checkedValue = 1, uncheckedValue = 0, ...props })
913
)
1014
}
1115

12-
export const ColorFieldTag = (props) => (
13-
<input type="color" {...props} />
14-
)
16+
export const ColorFieldTag = props => <input type="color" {...props} />
1517

16-
export const DateFieldTag = (props) => (
17-
<input type="date" {...props} />
18-
)
18+
export const DateFieldTag = props => <input type="date" {...props} />
1919

20-
export const DatetimeFieldTag = (props) => (
21-
<input type="datetime" {...props} />
22-
)
20+
export const DatetimeFieldTag = props => <input type="datetime" {...props} />
2321

24-
export const DatetimeLocalFieldTag = (props) => (
22+
export const DatetimeLocalFieldTag = props => (
2523
<input type="datetime-local" {...props} />
2624
)
2725

28-
export const EmailFieldTag = (props) => (
29-
<input type="email" {...props} />
30-
)
26+
export const EmailFieldTag = props => <input type="email" {...props} />
3127

32-
export const HiddenFieldTag = (props) => (
28+
export const HiddenFieldTag = props => (
3329
<input type="hidden" readOnly {...props} />
3430
)
3531

36-
export const LabelTag = (props) => (
37-
<label {...whitelistProps(props)} />
38-
)
32+
export const LabelTag = props => <label {...whitelistProps(props)} />
3933

40-
export const MonthFieldTag = (props) => (
41-
<input type="month" {...props} />
42-
)
34+
export const MonthFieldTag = props => <input type="month" {...props} />
4335

44-
export const NumberFieldTag = (props) => (
45-
<input type="number" {...props} />
46-
)
36+
export const NumberFieldTag = props => <input type="number" {...props} />
4737

48-
export const PasswordFieldTag = (props) => (
49-
<input type="password" {...props} />
50-
)
38+
export const PasswordFieldTag = props => <input type="password" {...props} />
5139

52-
export const RadioTag = (props) => (
53-
<input type="radio" {...props} />
54-
)
40+
export const RadioTag = props => <input type="radio" {...props} />
5541

56-
export const RangeFieldTag = (props) => (
57-
<input type="range" {...props} />
58-
)
42+
export const RangeFieldTag = props => <input type="range" {...props} />
5943

60-
export const SearchFieldTag = (props) => (
61-
<input type="search" {...props} />
62-
)
44+
export const SearchFieldTag = props => <input type="search" {...props} />
6345

64-
export const SelectTag = (props) => (
65-
<select {...whitelistProps(props)} />
66-
)
46+
export const SelectTag = props => <select {...whitelistProps(props)} />
6747

68-
export const SubmitTag = (props) => (
69-
<input type="submit" {...props} />
70-
)
48+
export const SubmitTag = props => <input type="submit" {...props} />
7149

72-
export const TelephoneFieldTag = (props) => (
73-
<input type="tel" {...props} />
74-
)
50+
export const TelephoneFieldTag = props => <input type="tel" {...props} />
7551

76-
export const TextAreaTag = (props) => (
77-
<textarea {...whitelistProps(props)} />
78-
)
52+
export const TextAreaTag = props => <textarea {...whitelistProps(props)} />
7953

80-
export const TextFieldTag = (props) => (
81-
<input type="text" {...props} />
82-
)
54+
export const TextFieldTag = props => <input type="text" {...props} />
8355

84-
export const TimeFieldTag = (props) => (
85-
<input type="time" {...props} />
86-
)
56+
export const TimeFieldTag = props => <input type="time" {...props} />
8757

88-
export const UrlFieldTag = (props) => (
89-
<input type="url" {...props} />
90-
)
58+
export const UrlFieldTag = props => <input type="url" {...props} />
9159

92-
export const WeekFieldTag = (props) => (
93-
<input type="week" {...props} />
94-
)
60+
export const WeekFieldTag = props => <input type="week" {...props} />

src/utils.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@ import React from "react"
22
import PropTypes from "prop-types"
33

44
export const nameWithContext = (Lower, prop = "name") => {
5-
const getDisplayName = (component) => component.displayName || component.name || "Component"
5+
const getDisplayName = component =>
6+
component.displayName || component.name || "Component"
67

7-
const buildInputName = (namespaces, name = "") => (
8-
[ ...namespaces, name ].map((field, index) => ( index === 0 ? field : `[${field}]` )).join("")
9-
)
8+
const buildInputName = (namespaces, name = "") =>
9+
[...namespaces, name]
10+
.map((field, index) => (index === 0 ? field : `[${field}]`))
11+
.join("")
1012

1113
const higher = (props, context) => {
12-
const replacedProp = buildInputName(context.railsFormNamespaces, props[prop])
14+
const replacedProp = buildInputName(
15+
context.railsFormNamespaces,
16+
props[prop]
17+
)
1318
const replacedProps = Object.assign({}, props, { [prop]: replacedProp })
1419
return <Lower {...replacedProps} />
1520
}
1621

1722
higher.displayName = getDisplayName(Lower).replace(/Tag$/, "")
18-
higher.contextTypes = { railsFormNamespaces: PropTypes.arrayOf(PropTypes.string) }
23+
higher.contextTypes = {
24+
railsFormNamespaces: PropTypes.arrayOf(PropTypes.string),
25+
}
1926

2027
return higher
2128
}
2229

2330
export const whitelistProps = (props, ...omit) => {
24-
const alwaysOmit = [ "key", "ref", ...omit ]
31+
const alwaysOmit = ["key", "ref", ...omit]
2532
const cloned = { ...props }
26-
alwaysOmit.forEach((key) => delete cloned[key])
33+
alwaysOmit.forEach(key => delete cloned[key])
2734
return cloned
2835
}

0 commit comments

Comments
 (0)