Skip to content

Commit d7604e7

Browse files
authored
style: Auto format code using prettier before commit (dowjones#224)
## What does it do? Adds prettierrc and pre commit hooks to format code automatically. Cleans up eslintrc and switched to react-app lint rules
1 parent 5036651 commit d7604e7

40 files changed

+1641
-696
lines changed

.codeclimate.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "2" # required to adjust maintainability checks
1+
version: '2' # required to adjust maintainability checks
22
checks:
33
argument-count:
44
config:
@@ -33,10 +33,11 @@ checks:
3333
plugins:
3434
eslint:
3535
enabled: true
36-
channel: "eslint-4"
36+
channel: 'eslint-5'
3737
exclude_patterns:
38-
- "docs/"
39-
- "snapshots/"
40-
- "**/tests/*"
41-
- "**/node_modules/"
42-
- "**/*.test.js"
38+
- 'docs/'
39+
- 'snapshots/'
40+
- '**/tests/*'
41+
- '**/node_modules/'
42+
- '**/*.test.js'
43+
- 'postcss.config.js'

.eslintrc.json

+3-66
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,12 @@
11
{
2-
"parserOptions": {
3-
"ecmaFeatures": {
4-
"jsx": true
5-
}
6-
},
7-
"parser": "babel-eslint",
8-
"extends": "airbnb",
9-
"plugins": ["react", "jsx-a11y", "import"],
10-
"env": {
11-
"browser": true,
12-
"node": true,
13-
"jest": true,
14-
"es6": true
15-
},
2+
"extends": ["react-app", "plugin:prettier/recommended"],
163
"rules": {
17-
"arrow-parens": [2, "as-needed"],
18-
"comma-dangle": ["warn", "never"],
19-
"global-require": 0,
20-
"import/no-extraneous-dependencies": [
21-
2,
22-
{
23-
"devDependencies": true
24-
}
25-
],
26-
"import/no-named-as-default": 0,
27-
"import/prefer-default-export": 0,
28-
"linebreak-style": 0,
29-
"max-len": [
30-
1,
31-
150,
32-
2,
33-
{
34-
"ignoreComments": true,
35-
"ignoreTrailingComments": true,
36-
"ignoreTemplateLiterals": true,
37-
"ignoreStrings": true
38-
}
39-
],
40-
"no-nested-ternary": 0,
41-
"no-underscore-dangle": 0,
42-
"no-console": 2,
43-
"no-bitwise": [
44-
2,
45-
{
46-
"allow": ["~"]
47-
}
48-
],
49-
"no-param-reassign": 0,
50-
"no-plusplus": 0,
51-
"no-shadow": 0,
52-
"no-unused-expressions": [2, { "allowShortCircuit": true }],
53-
"object-curly-newline": 0,
54-
"react/forbid-prop-types": 0,
55-
"react/require-default-props": 0,
4+
"prettier/prettier": ["error"],
565
"react/jsx-filename-extension": [
576
1,
587
{
598
"extensions": [".js", ".jsx"]
609
}
61-
],
62-
"react/jsx-wrap-multilines": 0,
63-
"react/jsx-closing-tag-location": 0,
64-
"react/sort-comp": 0,
65-
"semi": [2, "never"],
66-
"space-infix-ops": 0,
67-
"jsx-a11y/anchor-is-valid": 0,
68-
"jsx-a11y/label-has-for": 0,
69-
"jsx-a11y/no-static-element-interactions": 0,
70-
"jsx-a11y/click-events-have-key-events": 0
71-
},
72-
"globals": {
73-
"document": true
10+
]
7411
}
7512
}

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/src/stories/utils/prism.js

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 120,
3+
"singleQuote": true,
4+
"semi": false,
5+
"trailingComma": "es5"
6+
}

docs/src/App.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,40 @@ const stories = [
2525
{ name: 'Simple Select', component: CodeSandbox('5xzn337wjn') },
2626
{
2727
name: 'Custom Select/Unselect All Buttons (HOC)',
28-
component: CodeSandbox('n348v2qox0')
28+
component: CodeSandbox('n348v2qox0'),
2929
},
3030
{
3131
name: 'Internal Select All Checkbox (HOC)',
32-
component: CodeSandbox('rjwqq86p1n')
32+
component: CodeSandbox('rjwqq86p1n'),
3333
},
3434
{
3535
name: 'Prevent re-render on parent render (HOC)',
36-
component: CodeSandbox('v05klkn56l')
36+
component: CodeSandbox('v05klkn56l'),
3737
},
38-
{ name: 'Tree Node Paths (HOC)', component: CodeSandbox('l765q6lmrq') }
38+
{ name: 'Tree Node Paths (HOC)', component: CodeSandbox('l765q6lmrq') },
3939
]
4040

4141
const App = () => (
4242
<ReactStory
4343
style={{
4444
display: 'block',
4545
width: '100%',
46-
height: '100%'
46+
height: '100%',
4747
}}
4848
pathPrefix="story/"
4949
Story={props => (
5050
<defaultProps.StoryWrapper
5151
css={{
5252
padding: 0,
5353
display: 'flex',
54-
flexDirection: 'column'
54+
flexDirection: 'column',
5555
}}
5656
>
5757
<div
5858
{...props}
5959
style={{
6060
flex: '1 0 auto',
61-
position: 'relative'
61+
position: 'relative',
6262
}}
6363
/>
6464
</defaultProps.StoryWrapper>

docs/src/CodeSandbox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default id => () => (
1212
width: '100%',
1313
height: '100%',
1414
border: 0,
15-
overflow: 'hidden'
15+
overflow: 'hidden',
1616
}}
1717
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
1818
title="Code Sandbox"

docs/src/stories/DefaultValues/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const Simple = () => (
2020
<div>
2121
<h1>Component with Default Values</h1>
2222
<p>
23-
Default Values get applied when there is no other user based selection. User can select more values and unselect default values as long as there
24-
is at least one user-selected value still present.
23+
Default Values get applied when there is no other user based selection. User can select more values and unselect
24+
default values as long as there is at least one user-selected value still present.
2525
</p>
2626
<DropdownTreeSelect data={data} onChange={onChange} onAction={onAction} onNodeToggle={onNodeToggle} />
2727
</div>

docs/src/stories/Options/Checkbox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Checkbox extends PureComponent {
66
label: PropTypes.string.isRequired,
77
value: PropTypes.string.isRequired,
88
onChange: PropTypes.func.isRequired,
9-
checked: PropTypes.bool
9+
checked: PropTypes.bool,
1010
}
1111

1212
state = { isChecked: this.props.checked || false }

docs/src/stories/Options/index.js

+29-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WithOptions extends PureComponent {
1717
showPartiallySelected: false,
1818
disabled: false,
1919
readOnly: false,
20-
hierarchical: false
20+
hierarchical: false,
2121
}
2222
}
2323

@@ -36,7 +36,15 @@ class WithOptions extends PureComponent {
3636
}
3737

3838
render() {
39-
const { clearSearchOnChange, keepTreeOnSearch, simpleSelect, showPartiallySelected, disabled, readOnly, hierarchical } = this.state
39+
const {
40+
clearSearchOnChange,
41+
keepTreeOnSearch,
42+
simpleSelect,
43+
showPartiallySelected,
44+
disabled,
45+
readOnly,
46+
hierarchical,
47+
} = this.state
4048

4149
return (
4250
<div>
@@ -47,13 +55,28 @@ class WithOptions extends PureComponent {
4755
border: '1px solid #ccc',
4856
borderRadius: '4px',
4957
marginBottom: '20px',
50-
padding: 10
58+
padding: 10,
5159
}}
5260
>
53-
<Checkbox label="Clear search on selection" value="clearSearchOnChange" checked={clearSearchOnChange} onChange={this.onOptionsChange} />
54-
<Checkbox label="Keep tree on search" value="keepTreeOnSearch" checked={keepTreeOnSearch} onChange={this.onOptionsChange} />
61+
<Checkbox
62+
label="Clear search on selection"
63+
value="clearSearchOnChange"
64+
checked={clearSearchOnChange}
65+
onChange={this.onOptionsChange}
66+
/>
67+
<Checkbox
68+
label="Keep tree on search"
69+
value="keepTreeOnSearch"
70+
checked={keepTreeOnSearch}
71+
onChange={this.onOptionsChange}
72+
/>
5573
<Checkbox label="Simple Select" value="simpleSelect" checked={simpleSelect} onChange={this.onOptionsChange} />
56-
<Checkbox label="Show Partially Selected" value="showPartiallySelected" checked={showPartiallySelected} onChange={this.onOptionsChange} />
74+
<Checkbox
75+
label="Show Partially Selected"
76+
value="showPartiallySelected"
77+
checked={showPartiallySelected}
78+
onChange={this.onOptionsChange}
79+
/>
5780
<Checkbox label="Disabled" value="disabled" checked={disabled} onChange={this.onOptionsChange} />
5881
<Checkbox label="Read Only" value="readOnly" checked={readOnly} onChange={this.onOptionsChange} />
5982
<Checkbox label="Hierarchical" value="hierarchical" checked={hierarchical} onChange={this.onOptionsChange} />

docs/src/stories/Simple/index.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,30 @@ const onBlur = () => {
2323
console.log('onBlur')
2424
}
2525

26-
2726
const Simple = () => (
2827
<div>
2928
<h1>Basic component</h1>
3029
<p>
31-
This is a basic example of the component. Note that there are no external styles in this page, not even <code>reset.css</code> or{' '}
32-
<code>reboot.css</code> or <code>normalizer.css</code>.
30+
This is a basic example of the component. Note that there are no external styles in this page, not even{' '}
31+
<code>reset.css</code> or <code>reboot.css</code> or <code>normalizer.css</code>.
3332
</p>
3433
<p>
35-
The idea is to showcase the component at its barest minimum. Of course, its easy to style it, using popular frameworks such as Bootstrap or
36-
Material Design (checkout the examples on left).
34+
The idea is to showcase the component at its barest minimum. Of course, its easy to style it, using popular
35+
frameworks such as Bootstrap or Material Design (checkout the examples on left).
3736
</p>
3837
<p>
39-
As a side effect, it also helps rule out issues arising out of using custom frameworks (if something doesn&apos;t look right in your app but
40-
looks OK here, you know what is messing things up).
38+
As a side effect, it also helps rule out issues arising out of using custom frameworks (if something doesn&apos;t
39+
look right in your app but looks OK here, you know what is messing things up).
4140
</p>
42-
<DropdownTreeSelect data={data} onChange={onChange} onAction={onAction} onNodeToggle={onNodeToggle} onFocus={onFocus} onBlur={onBlur} className="demo" />
41+
<DropdownTreeSelect
42+
data={data}
43+
onChange={onChange}
44+
onAction={onAction}
45+
onNodeToggle={onNodeToggle}
46+
onFocus={onFocus}
47+
onBlur={onBlur}
48+
className="demo"
49+
/>
4350
</div>
4451
)
4552

docs/webpack.config.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ const baseConfig = {
55
mode: 'development',
66
resolve: {
77
extensions: ['.js', '.css'],
8-
modules: ['node_modules']
8+
modules: ['node_modules'],
99
},
1010
module: {
1111
rules: [
1212
{
1313
test: /\.(js|jsx)$/,
1414
exclude: /node_modules/,
15-
loader: 'babel-loader'
15+
loader: 'babel-loader',
1616
},
1717
{
1818
test: /\.css$/,
19-
loader: 'style-loader!css-loader!postcss-loader'
19+
loader: 'style-loader!css-loader!postcss-loader',
2020
},
2121
{
2222
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
2323
use: {
2424
loader: 'url-loader',
25-
options: { limit: 100000 }
26-
}
25+
options: { limit: 100000 },
26+
},
2727
},
2828
{
2929
test: /\.md$/,
30-
use: 'raw-loader'
31-
}
32-
]
33-
}
30+
use: 'raw-loader',
31+
},
32+
],
33+
},
3434
}
3535

3636
module.exports = [
@@ -39,7 +39,7 @@ module.exports = [
3939
entry: path.join(__dirname, 'src'),
4040
output: {
4141
path: __dirname,
42-
filename: 'bundle.js'
43-
}
44-
}
42+
filename: 'bundle.js',
43+
},
44+
},
4545
]

0 commit comments

Comments
 (0)