Skip to content

Commit cdbf45a

Browse files
authored
Merge pull request #9 from rschamp/lint
eslint-config-scratch: React + ES6 Edition
2 parents 547ed55 + 97b0f26 commit cdbf45a

31 files changed

+381
-330
lines changed

.eslintrc

Lines changed: 0 additions & 25 deletions
This file was deleted.

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
env: {
3+
node: true
4+
}
5+
};

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"start": "webpack-dev-server --port $npm_package_config_port --content-base=./build",
1919
"test": "npm run lint && npm run build"
2020
},
21+
"eslintConfig": {
22+
"extends": ["scratch"]
23+
},
2124
"author": "Massachusetts Institute of Technology",
2225
"license": "BSD-3-Clause",
2326
"homepage": "https://github.com/LLK/scratch-gui#readme",
@@ -31,14 +34,15 @@
3134
},
3235
"devDependencies": {
3336
"babel-core": "6.14.0",
34-
"babel-eslint": "6.1.2",
37+
"babel-eslint": "7.0.0",
3538
"babel-loader": "6.2.5",
3639
"babel-plugin-transform-object-rest-spread": "6.16.0",
3740
"babel-preset-es2015": "6.14.0",
3841
"babel-preset-react": "6.11.1",
3942
"copy-webpack-plugin": "3.0.1",
4043
"eslint": "3.5.0",
41-
"eslint-plugin-react": "6.2.1",
44+
"eslint-config-scratch": "^1.0.0",
45+
"eslint-plugin-react": "6.4.1",
4246
"gh-pages": "0.11.0",
4347
"html-webpack-plugin": "2.22.0",
4448
"husky": "0.11.9",
@@ -50,6 +54,7 @@
5054
"react": "15.3.2",
5155
"react-dom": "15.3.2",
5256
"react-modal": "1.5.2",
57+
"react-style-proptype": "1.2.0",
5358
"scratch-blocks": "latest",
5459
"scratch-render": "latest",
5560
"scratch-vm": "latest",

src/.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
env: {
3+
node: false,
4+
browser: true
5+
},
6+
extends: ['scratch/es6', 'scratch/react']
7+
};

src/components/blocks.js renamed to src/components/blocks.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class BlocksComponent extends React.Component {
88
} = this.props;
99
return (
1010
<div
11-
ref={componentRef}
1211
className="scratch-blocks"
12+
ref={componentRef}
1313
style={{
1414
position: 'absolute',
1515
top: 0,

src/components/costume-canvas.js renamed to src/components/costume-canvas.jsx

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,54 @@ class CostumeCanvas extends React.Component {
1616
componentDidUpdate (prevProps) {
1717
if (prevProps.url !== this.props.url) {
1818
this.load();
19-
} else {
20-
if (prevProps.width !== this.props.width ||
21-
prevProps.height !== this.props.height ||
22-
prevProps.direction !== this.props.direction) {
23-
this.draw();
24-
}
19+
} else if (
20+
prevProps.width !== this.props.width ||
21+
prevProps.height !== this.props.height ||
22+
prevProps.direction !== this.props.direction
23+
) {
24+
this.draw();
2525
}
2626
}
2727
draw () {
28-
if (!this.refs.costumeCanvas) {
28+
if (!this.canvas) {
2929
return;
3030
}
31+
3132
// Draw the costume to the rendered canvas.
3233
const img = this.img;
33-
const context = this.refs.costumeCanvas.getContext('2d');
34+
const context = this.canvas.getContext('2d');
35+
3436
// Scale to fit.
3537
let scale;
38+
3639
// Choose the larger dimension to scale by.
3740
if (img.width > img.height) {
38-
scale = this.refs.costumeCanvas.width / img.width;
41+
scale = this.canvas.width / img.width;
3942
} else {
40-
scale = this.refs.costumeCanvas.height / img.height;
43+
scale = this.canvas.height / img.height;
4144
}
45+
4246
// Rotate by the Scratch-value direction.
4347
const angle = (-90 + this.props.direction) * Math.PI / 180;
48+
4449
// Rotation origin point will be center of the canvas.
45-
const contextTranslateX = this.refs.costumeCanvas.width / 2;
46-
const contextTranslateY = this.refs.costumeCanvas.height / 2;
50+
const contextTranslateX = this.canvas.width / 2;
51+
const contextTranslateY = this.canvas.height / 2;
52+
4753
// First, clear the canvas.
4854
context.clearRect(0, 0,
49-
this.refs.costumeCanvas.width, this.refs.costumeCanvas.height);
55+
this.canvas.width, this.canvas.height);
56+
5057
// Translate the context to the center of the canvas,
5158
// then rotate canvas drawing by `angle`.
5259
context.translate(contextTranslateX, contextTranslateY);
5360
context.rotate(angle);
5461
context.drawImage(img,
5562
0, 0, img.width, img.height,
56-
-(scale * img.width / 2), -(scale * img.height / 2),
63+
-(scale * img.width / 2), -(scale * img.height / 2),
5764
scale * img.width,
5865
scale * img.height);
66+
5967
// Reset the canvas rotation and translation to 0, (0, 0).
6068
context.rotate(-angle);
6169
context.translate(-contextTranslateX, -contextTranslateY);
@@ -72,8 +80,8 @@ class CostumeCanvas extends React.Component {
7280
url: url
7381
}, (err, response, body) => {
7482
if (!err) {
75-
svgToImage(body, (err, img) => {
76-
if (!err) {
83+
svgToImage(body, (svgErr, img) => {
84+
if (!svgErr) {
7785
this.img = img;
7886
this.draw();
7987
}
@@ -84,7 +92,7 @@ class CostumeCanvas extends React.Component {
8492

8593
} else {
8694
// Raster graphics: create Image and draw it.
87-
let img = new Image();
95+
const img = new Image();
8896
img.src = url;
8997
img.onload = () => {
9098
this.img = img;
@@ -93,11 +101,13 @@ class CostumeCanvas extends React.Component {
93101
}
94102
}
95103
render () {
96-
return <canvas
97-
ref='costumeCanvas'
98-
width={this.props.width}
99-
height={this.props.height}
100-
/>;
104+
return (
105+
<canvas
106+
height={this.props.height}
107+
width={this.props.width}
108+
ref={this._getCanvas} // eslint-disable-line react/jsx-sort-props
109+
/>
110+
);
101111
}
102112
}
103113

@@ -108,10 +118,10 @@ CostumeCanvas.defaultProps = {
108118
};
109119

110120
CostumeCanvas.propTypes = {
111-
url: React.PropTypes.string,
112-
width: React.PropTypes.number,
121+
direction: React.PropTypes.number,
113122
height: React.PropTypes.number,
114-
direction: React.PropTypes.number
123+
url: React.PropTypes.string,
124+
width: React.PropTypes.number
115125
};
116126

117127
module.exports = CostumeCanvas;
File renamed without changes.
File renamed without changes.

src/components/library-item.js renamed to src/components/library-item.jsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
const bindAll = require('lodash.bindall');
12
const React = require('react');
3+
const stylePropType = require('react-style-proptype');
24

3-
const CostumeCanvas = require('./costume-canvas');
5+
const CostumeCanvas = require('./costume-canvas.jsx');
46

57
class LibraryItem extends React.Component {
8+
constructor (props) {
9+
super(props);
10+
bindAll(this, ['handleClick']);
11+
}
12+
handleClick (e) {
13+
this.props.onSelect(this.props.id);
14+
e.preventDefault();
15+
}
616
render () {
7-
let style = (this.props.selected) ?
17+
const style = (this.props.selected) ?
818
this.props.selectedGridTileStyle : this.props.gridTileStyle;
919
return (
10-
<div style={style} onClick={() => this.props.onSelect(this.props.id)}>
20+
<div
21+
style={style}
22+
onClick={this.handleClick}
23+
>
1124
<CostumeCanvas url={this.props.iconURL} />
1225
<p>{this.props.name}</p>
1326
</div>
@@ -37,13 +50,13 @@ LibraryItem.defaultProps = {
3750
};
3851

3952
LibraryItem.propTypes = {
40-
name: React.PropTypes.string,
53+
gridTileStyle: stylePropType,
4154
iconURL: React.PropTypes.string,
42-
gridTileStyle: React.PropTypes.object,
43-
selectedGridTileStyle: React.PropTypes.object,
44-
selected: React.PropTypes.bool,
55+
id: React.PropTypes.number,
56+
name: React.PropTypes.string,
4557
onSelect: React.PropTypes.func,
46-
id: React.PropTypes.number
58+
selected: React.PropTypes.bool,
59+
selectedGridTileStyle: stylePropType
4760
};
4861

4962
module.exports = LibraryItem;

src/components/library.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)