Skip to content

Commit

Permalink
style: Auto format code using prettier before commit (dowjones#224)
Browse files Browse the repository at this point in the history
## What does it do?

Adds prettierrc and pre commit hooks to format code automatically. Cleans up eslintrc and switched to react-app lint rules
  • Loading branch information
mrchief authored Apr 13, 2019
1 parent 5036651 commit d7604e7
Show file tree
Hide file tree
Showing 40 changed files with 1,641 additions and 696 deletions.
15 changes: 8 additions & 7 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2" # required to adjust maintainability checks
version: '2' # required to adjust maintainability checks
checks:
argument-count:
config:
Expand Down Expand Up @@ -33,10 +33,11 @@ checks:
plugins:
eslint:
enabled: true
channel: "eslint-4"
channel: 'eslint-5'
exclude_patterns:
- "docs/"
- "snapshots/"
- "**/tests/*"
- "**/node_modules/"
- "**/*.test.js"
- 'docs/'
- 'snapshots/'
- '**/tests/*'
- '**/node_modules/'
- '**/*.test.js'
- 'postcss.config.js'
69 changes: 3 additions & 66 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,75 +1,12 @@
{
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"parser": "babel-eslint",
"extends": "airbnb",
"plugins": ["react", "jsx-a11y", "import"],
"env": {
"browser": true,
"node": true,
"jest": true,
"es6": true
},
"extends": ["react-app", "plugin:prettier/recommended"],
"rules": {
"arrow-parens": [2, "as-needed"],
"comma-dangle": ["warn", "never"],
"global-require": 0,
"import/no-extraneous-dependencies": [
2,
{
"devDependencies": true
}
],
"import/no-named-as-default": 0,
"import/prefer-default-export": 0,
"linebreak-style": 0,
"max-len": [
1,
150,
2,
{
"ignoreComments": true,
"ignoreTrailingComments": true,
"ignoreTemplateLiterals": true,
"ignoreStrings": true
}
],
"no-nested-ternary": 0,
"no-underscore-dangle": 0,
"no-console": 2,
"no-bitwise": [
2,
{
"allow": ["~"]
}
],
"no-param-reassign": 0,
"no-plusplus": 0,
"no-shadow": 0,
"no-unused-expressions": [2, { "allowShortCircuit": true }],
"object-curly-newline": 0,
"react/forbid-prop-types": 0,
"react/require-default-props": 0,
"prettier/prettier": ["error"],
"react/jsx-filename-extension": [
1,
{
"extensions": [".js", ".jsx"]
}
],
"react/jsx-wrap-multilines": 0,
"react/jsx-closing-tag-location": 0,
"react/sort-comp": 0,
"semi": [2, "never"],
"space-infix-ops": 0,
"jsx-a11y/anchor-is-valid": 0,
"jsx-a11y/label-has-for": 0,
"jsx-a11y/no-static-element-interactions": 0,
"jsx-a11y/click-events-have-key-events": 0
},
"globals": {
"document": true
]
}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/src/stories/utils/prism.js
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"singleQuote": true,
"semi": false,
"trailingComma": "es5"
}
14 changes: 7 additions & 7 deletions docs/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@ const stories = [
{ name: 'Simple Select', component: CodeSandbox('5xzn337wjn') },
{
name: 'Custom Select/Unselect All Buttons (HOC)',
component: CodeSandbox('n348v2qox0')
component: CodeSandbox('n348v2qox0'),
},
{
name: 'Internal Select All Checkbox (HOC)',
component: CodeSandbox('rjwqq86p1n')
component: CodeSandbox('rjwqq86p1n'),
},
{
name: 'Prevent re-render on parent render (HOC)',
component: CodeSandbox('v05klkn56l')
component: CodeSandbox('v05klkn56l'),
},
{ name: 'Tree Node Paths (HOC)', component: CodeSandbox('l765q6lmrq') }
{ name: 'Tree Node Paths (HOC)', component: CodeSandbox('l765q6lmrq') },
]

const App = () => (
<ReactStory
style={{
display: 'block',
width: '100%',
height: '100%'
height: '100%',
}}
pathPrefix="story/"
Story={props => (
<defaultProps.StoryWrapper
css={{
padding: 0,
display: 'flex',
flexDirection: 'column'
flexDirection: 'column',
}}
>
<div
{...props}
style={{
flex: '1 0 auto',
position: 'relative'
position: 'relative',
}}
/>
</defaultProps.StoryWrapper>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/CodeSandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default id => () => (
width: '100%',
height: '100%',
border: 0,
overflow: 'hidden'
overflow: 'hidden',
}}
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
title="Code Sandbox"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/stories/DefaultValues/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const Simple = () => (
<div>
<h1>Component with Default Values</h1>
<p>
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
is at least one user-selected value still present.
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 is at least one user-selected value still present.
</p>
<DropdownTreeSelect data={data} onChange={onChange} onAction={onAction} onNodeToggle={onNodeToggle} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/stories/Options/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Checkbox extends PureComponent {
label: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
checked: PropTypes.bool
checked: PropTypes.bool,
}

state = { isChecked: this.props.checked || false }
Expand Down
35 changes: 29 additions & 6 deletions docs/src/stories/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WithOptions extends PureComponent {
showPartiallySelected: false,
disabled: false,
readOnly: false,
hierarchical: false
hierarchical: false,
}
}

Expand All @@ -36,7 +36,15 @@ class WithOptions extends PureComponent {
}

render() {
const { clearSearchOnChange, keepTreeOnSearch, simpleSelect, showPartiallySelected, disabled, readOnly, hierarchical } = this.state
const {
clearSearchOnChange,
keepTreeOnSearch,
simpleSelect,
showPartiallySelected,
disabled,
readOnly,
hierarchical,
} = this.state

return (
<div>
Expand All @@ -47,13 +55,28 @@ class WithOptions extends PureComponent {
border: '1px solid #ccc',
borderRadius: '4px',
marginBottom: '20px',
padding: 10
padding: 10,
}}
>
<Checkbox label="Clear search on selection" value="clearSearchOnChange" checked={clearSearchOnChange} onChange={this.onOptionsChange} />
<Checkbox label="Keep tree on search" value="keepTreeOnSearch" checked={keepTreeOnSearch} onChange={this.onOptionsChange} />
<Checkbox
label="Clear search on selection"
value="clearSearchOnChange"
checked={clearSearchOnChange}
onChange={this.onOptionsChange}
/>
<Checkbox
label="Keep tree on search"
value="keepTreeOnSearch"
checked={keepTreeOnSearch}
onChange={this.onOptionsChange}
/>
<Checkbox label="Simple Select" value="simpleSelect" checked={simpleSelect} onChange={this.onOptionsChange} />
<Checkbox label="Show Partially Selected" value="showPartiallySelected" checked={showPartiallySelected} onChange={this.onOptionsChange} />
<Checkbox
label="Show Partially Selected"
value="showPartiallySelected"
checked={showPartiallySelected}
onChange={this.onOptionsChange}
/>
<Checkbox label="Disabled" value="disabled" checked={disabled} onChange={this.onOptionsChange} />
<Checkbox label="Read Only" value="readOnly" checked={readOnly} onChange={this.onOptionsChange} />
<Checkbox label="Hierarchical" value="hierarchical" checked={hierarchical} onChange={this.onOptionsChange} />
Expand Down
23 changes: 15 additions & 8 deletions docs/src/stories/Simple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@ const onBlur = () => {
console.log('onBlur')
}


const Simple = () => (
<div>
<h1>Basic component</h1>
<p>
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{' '}
<code>reboot.css</code> or <code>normalizer.css</code>.
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 <code>reboot.css</code> or <code>normalizer.css</code>.
</p>
<p>
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
Material Design (checkout the examples on left).
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 Material Design (checkout the examples on left).
</p>
<p>
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
looks OK here, you know what is messing things up).
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 looks OK here, you know what is messing things up).
</p>
<DropdownTreeSelect data={data} onChange={onChange} onAction={onAction} onNodeToggle={onNodeToggle} onFocus={onFocus} onBlur={onBlur} className="demo" />
<DropdownTreeSelect
data={data}
onChange={onChange}
onAction={onAction}
onNodeToggle={onNodeToggle}
onFocus={onFocus}
onBlur={onBlur}
className="demo"
/>
</div>
)

Expand Down
24 changes: 12 additions & 12 deletions docs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ const baseConfig = {
mode: 'development',
resolve: {
extensions: ['.js', '.css'],
modules: ['node_modules']
modules: ['node_modules'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
loader: 'babel-loader',
},
{
test: /\.css$/,
loader: 'style-loader!css-loader!postcss-loader'
loader: 'style-loader!css-loader!postcss-loader',
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: {
loader: 'url-loader',
options: { limit: 100000 }
}
options: { limit: 100000 },
},
},
{
test: /\.md$/,
use: 'raw-loader'
}
]
}
use: 'raw-loader',
},
],
},
}

module.exports = [
Expand All @@ -39,7 +39,7 @@ module.exports = [
entry: path.join(__dirname, 'src'),
output: {
path: __dirname,
filename: 'bundle.js'
}
}
filename: 'bundle.js',
},
},
]
Loading

0 comments on commit d7604e7

Please sign in to comment.