Skip to content

Commit ba51f4b

Browse files
author
Tomáš Vojtášek
committed
Use airbnb eslint config
1 parent bca8d3c commit ba51f4b

37 files changed

+813
-1270
lines changed

.eslintrc.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1+
const prettierConfig = require('./.prettierrc.js')
2+
13
module.exports = {
24
parser: 'babel-eslint',
5+
parserOptions: {
6+
ecmaVersion: 2017,
7+
sourceType: 'module',
8+
ecmaFeatures: {
9+
jsx: true
10+
}
11+
},
312
env: {
413
browser: true,
514
es6: true,
6-
node: true,
15+
node: true
16+
},
17+
extends: ['airbnb', 'prettier', 'prettier/react'],
18+
plugins: ['prettier'],
19+
rules: {
20+
'prettier/prettier': [2, prettierConfig],
21+
'no-param-reassign': 0,
22+
'no-underscore-dangle': 0,
23+
'no-plusplus': 0,
24+
'no-restricted-syntax': 0,
25+
'import/prefer-default-export': 0,
26+
'react/prefer-stateless-function': 0,
27+
'react/destructuring-assignment': 0,
28+
'import/no-extraneous-dependencies': [
29+
'error',
30+
{ devDependencies: ['stories/**/*'] }
31+
]
732
},
8-
plugins: ['prettier', 'react'],
9-
extends: ['prettier', 'plugin:react/recommended', 'eslint:recommended'],
1033
settings: {
1134
react: {
1235
version: 'detect'

.prettierrc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
2-
trailingComma: "es5",
3-
tabWidth: 2,
2+
printWidth: 80,
3+
trailingComma: 'none',
44
semi: false,
5-
singleQuote: true
6-
}
5+
singleQuote: true,
6+
jsxBracketSameLine: true
7+
}

README.md

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ React Canvas provides a set of standard React components that abstract the under
5656

5757
### <Gradient>
5858

59-
**Gradient** can be used to set the background of a group or surface.
59+
**Gradient** can be used to set the background of a group or surface.
6060
```javascript
6161
render() {
6262
...
6363
return (
6464
<Group style={this.getStyle()}>
65-
<Gradient style={this.getGradientStyle()}
65+
<Gradient style={this.getGradientStyle()}
6666
colorStops={this.getGradientColors()} />
6767
</Group>
6868
);
@@ -73,11 +73,7 @@ React Canvas provides a set of standard React components that abstract the under
7373
{ color: "#000", position: 1 }
7474
]
7575
}
76-
```
77-
78-
### &lt;ListView&gt;
79-
80-
**ListView** is a touch scrolling container that renders a list of elements in a column. Think of it like UITableView for the web. It leverages many of the same optimizations that make table views on iOS and list views on Android fast.
76+
```
8177

8278
## Events
8379

@@ -142,47 +138,6 @@ var MyComponent = React.createClass({
142138
});
143139
```
144140

145-
## ListView
146-
147-
Many mobile interfaces involve an infinitely long scrolling list of items. React Canvas provides the ListView component to do just that.
148-
149-
Because ListView virtualizes elements outside of the viewport, passing children to it is different than a normal React component where children are declared in render().
150-
151-
The `numberOfItemsGetter`, `itemHeightGetter` and `itemGetter` props are all required.
152-
153-
```javascript
154-
var ListView = ReactCanvas.ListView;
155-
156-
var MyScrollingListView = React.createClass({
157-
158-
render: function () {
159-
return (
160-
<ListView
161-
numberOfItemsGetter={this.getNumberOfItems}
162-
itemHeightGetter={this.getItemHeight}
163-
itemGetter={this.renderItem} />
164-
);
165-
},
166-
167-
getNumberOfItems: function () {
168-
// Return the total number of items in the list
169-
},
170-
171-
getItemHeight: function () {
172-
// Return the height of a single item
173-
},
174-
175-
renderItem: function (index) {
176-
// Render the item at the given index, usually a <Group>
177-
},
178-
179-
});
180-
```
181-
182-
See the [timeline example](examples/timeline/app.js) for a more complete example.
183-
184-
Currently, ListView requires that each item is of the same height. Future versions will support variable height items.
185-
186141
## Text sizing
187142

188143
React Canvas provides the `measureText` function for computing text metrics.

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@
3030
"alea": "^0.0.9",
3131
"babel-cli": "^6.26.0",
3232
"babel-core": "^6.26.3",
33-
"babel-eslint": "^8.2.3",
33+
"babel-eslint": "^10.0.1",
3434
"babel-preset-env": "^1.7.0",
3535
"babel-preset-react": "^6.24.1",
3636
"babel-preset-stage-2": "^6.24.1",
3737
"babel-runtime": "^6.26.0",
3838
"d3-scale": "^1.0.6",
39-
"eslint": "^5.16.0",
39+
"eslint": "5.3.0",
40+
"eslint-config-airbnb": "17.1.0",
4041
"eslint-config-prettier": "^4.3.0",
42+
"eslint-plugin-import": "^2.14.0",
43+
"eslint-plugin-jsx-a11y": "^6.1.1",
4144
"eslint-plugin-prettier": "^3.1.0",
42-
"eslint-plugin-react": "^7.13.0",
45+
"eslint-plugin-react": "^7.11.0",
4346
"lodash.range": "^3.2.0",
4447
"prettier": "^1.17.1",
4548
"react": "^16.8.6",
@@ -57,7 +60,6 @@
5760
"multi-key-cache": "^1.0.2",
5861
"prop-types": "^15.6.1",
5962
"react-reconciler": "^0.20.4",
60-
"scheduler": "^0.14.0",
61-
"scroller": "https://github.com/mjohnston/scroller"
63+
"scheduler": "^0.14.0"
6264
}
6365
}

src/Canvas.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
// Note that this class intentionally does not use PooledClass.
42
// DrawingUtils manages <canvas> pooling for more fine-grained control.
53

@@ -19,13 +17,13 @@ function Canvas(width, height, scale) {
1917
}
2018

2119
Object.assign(Canvas.prototype, {
22-
getRawCanvas: function() {
20+
getRawCanvas() {
2321
return this._canvas
2422
},
2523

26-
getContext: function() {
24+
getContext() {
2725
return this._canvas.getContext('2d')
28-
},
26+
}
2927
})
3028

3129
// PooledClass:

src/CanvasComponent.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export default class CanvasComponent {
1111
this.subscriptions = new Map()
1212
this.listeners = new Map()
1313
this.node = new RenderLayer(this)
14-
this._layerId = LAYER_GUID++
14+
this._layerId = LAYER_GUID
15+
LAYER_GUID += 1
1516
}
1617

1718
putEventListener = (type, listener) => {
18-
const subscriptions = this.subscriptions
19-
const listeners = this.listeners
19+
const { listeners, subscriptions } = this
2020

2121
let isListenerDifferent = false
2222
if (listeners.get(type) !== listener) {
@@ -49,6 +49,7 @@ export default class CanvasComponent {
4949
let style = emptyObject
5050

5151
if (props.style) {
52+
// eslint-disable-next-line prefer-destructuring
5253
style = props.style
5354
layer._originalStyle = style
5455
} else {
@@ -59,7 +60,7 @@ export default class CanvasComponent {
5960
layer.frame = make(0, 0, 0, 0)
6061
}
6162

62-
const frame = layer.frame
63+
const { frame } = layer
6364
const l = style.left || 0
6465
const t = style.top || 0
6566
const w = style.width || 0

src/CanvasRenderer.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
import React from 'react'
22
import invariant from 'invariant'
3+
import ReactFiberReconciler from 'react-reconciler'
4+
import {
5+
unstable_now as now,
6+
unstable_shouldYield as shouldYield,
7+
unstable_scheduleCallback as scheduleDeferredCallback,
8+
unstable_cancelCallback as cancelDeferredCallback
9+
} from 'scheduler'
310
import { emptyObject } from './utils'
411
import Gradient from './Gradient'
512
import Text from './Text'
613
import Group from './Group'
714
import { RawImage } from './Image'
8-
import ReactFiberReconciler from 'react-reconciler'
915
import CanvasComponent from './CanvasComponent'
1016
import { getClosestInstanceFromNode } from './ReactDOMComponentTree'
11-
import {
12-
unstable_now as now,
13-
unstable_shouldYield as shouldYield,
14-
unstable_scheduleCallback as scheduleDeferredCallback,
15-
unstable_cancelCallback as cancelDeferredCallback,
16-
} from 'scheduler'
1717

1818
const UPDATE_SIGNAL = {}
1919
const MAX_POOLED_COMPONENTS_PER_TYPE = 1024
2020

2121
const componentConstructors = {
22-
Gradient: Gradient,
23-
Text: Text,
24-
Group: Group,
25-
RawImage: RawImage,
22+
Gradient,
23+
Text,
24+
Group,
25+
RawImage
2626
}
2727

2828
const componentPool = {}
2929

3030
const freeComponentToPool = component => {
31-
const type = component.type
31+
const { type } = component
3232

3333
if (!(component.type in componentPool)) {
3434
componentPool[type] = []
@@ -44,7 +44,7 @@ const freeComponentToPool = component => {
4444
const freeComponentAndChildren = c => {
4545
if (!(c instanceof CanvasComponent)) return
4646

47-
const children = c.getLayer().children
47+
const { children } = c.getLayer()
4848

4949
for (let i = 0; i < children.length; i++) {
5050
const childLayer = children[i]
@@ -66,7 +66,7 @@ const CanvasHostConfig = {
6666
child.getLayer().inject(parentInstance.getLayer())
6767
},
6868

69-
createInstance(type, props /*, internalInstanceHandle*/) {
69+
createInstance(type, props /* , internalInstanceHandle */) {
7070
let instance
7171

7272
const pool = componentPool[type]
@@ -85,11 +85,13 @@ const CanvasHostConfig = {
8585
return instance
8686
},
8787

88-
createTextInstance(text /*, rootContainerInstance, internalInstanceHandle*/) {
88+
createTextInstance(
89+
text /* , rootContainerInstance, internalInstanceHandle */
90+
) {
8991
return text
9092
},
9193

92-
finalizeInitialChildren(/*domElement, type, props*/) {
94+
finalizeInitialChildren(/* domElement, type, props */) {
9395
return false
9496
},
9597

@@ -101,19 +103,19 @@ const CanvasHostConfig = {
101103
// Noop
102104
},
103105

104-
prepareUpdate(/*domElement, type, oldProps, newProps*/) {
106+
prepareUpdate(/* domElement, type, oldProps, newProps */) {
105107
return UPDATE_SIGNAL
106108
},
107109

108110
resetAfterCommit() {
109111
// Noop
110112
},
111113

112-
resetTextContent(/*domElement*/) {
114+
resetTextContent(/* domElement */) {
113115
// Noop
114116
},
115117

116-
shouldDeprioritizeSubtree(/*type, props*/) {
118+
shouldDeprioritizeSubtree(/* type, props */) {
117119
return false
118120
},
119121

@@ -197,11 +199,11 @@ const CanvasHostConfig = {
197199
parentLayer.invalidateLayout()
198200
},
199201

200-
commitTextUpdate(/*textInstance, oldText, newText*/) {
202+
commitTextUpdate(/* textInstance, oldText, newText */) {
201203
// Noop
202204
},
203205

204-
commitMount(/*instance, type, newProps*/) {
206+
commitMount(/* instance, type, newProps */) {
205207
// Noop
206208
},
207209

@@ -210,7 +212,7 @@ const CanvasHostConfig = {
210212
instance.applyLayerProps(oldProps, newProps)
211213
instance.getLayer().invalidateLayout()
212214
}
213-
},
215+
}
214216
}
215217

216218
const CanvasRenderer = ReactFiberReconciler(CanvasHostConfig)
@@ -222,7 +224,7 @@ CanvasRenderer.injectIntoDevTools({
222224
rendererPackageName: 'react-canvas',
223225
getInspectorDataForViewTag: (...args) => {
224226
console.log(args) // eslint-disable-line no-console
225-
},
227+
}
226228
})
227229

228230
const registerComponentConstructor = (name, ctor) => {

0 commit comments

Comments
 (0)