Skip to content

Commit d98bd15

Browse files
author
Olivier FAURE
committed
👕 Add eslint with standard-js
1 parent 57cf8d8 commit d98bd15

File tree

4 files changed

+75
-45
lines changed

4 files changed

+75
-45
lines changed

.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
sourceType: 'module'
5+
},
6+
// https://github.com/feross/standard/blob/master/RULES.md
7+
extends: 'standard',
8+
// required to lint *.vue files
9+
plugins: [
10+
'html',
11+
'promise'
12+
],
13+
// add your custom rules here
14+
'rules': {
15+
// allow paren-less arrow functions
16+
'arrow-parens': 0,
17+
// allow debugger during development
18+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
19+
},
20+
env: {
21+
"browser": true,
22+
"node": true
23+
}
24+
}

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@
66
"author": "Olivier FAURE <olivier.faure@epitech.eu>",
77
"license": "MIT",
88
"main": "index.js",
9+
"scripts": {
10+
"lint": "eslint --ext .js,.vue src"
11+
},
912
"dependencies": {
1013
"idle-js": "^0.1.0"
1114
},
1215
"devDependencies": {
16+
"eslint": "^3.19.0",
17+
"eslint-config-standard": "^5.1.0",
18+
"eslint-friendly-formatter": "^2.0.5",
19+
"eslint-loader": "^1.3.0",
20+
"eslint-plugin-html": "^1.3.0",
21+
"eslint-plugin-promise": "^1.0.8",
22+
"eslint-plugin-standard": "^1.3.2",
23+
"eslint-plugin-import": "^2.3.0",
24+
"eslint-plugin-node": "^5.0.0",
1325
"vue": "^2.3.3",
1426
"vuex": "^2.3.1"
1527
}

src/Idle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Sprite from './Sprite'
1717
1818
export default {
1919
components: {
20-
Sprite
20+
Sprite
2121
},
2222
onIdle () {
2323
this.$refs.sprite.play()

src/Sprite.vue

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script>
88
export default {
99
name: 'sprite',
10-
props:{
10+
props: {
1111
spriteSrc: {
1212
type: String,
1313
default: ''
@@ -16,55 +16,54 @@ export default {
1616
type: String,
1717
default: 'sprite'
1818
},
19-
spriteW:{
20-
type:Number,
21-
default:1
19+
spriteW: {
20+
type: Number,
21+
default: 1
2222
},
23-
spriteH:{
24-
type:Number,
25-
default:1
23+
spriteH: {
24+
type: Number,
25+
default: 1
2626
},
27-
spriteSpeed:{
28-
type:Number,
29-
default:1
27+
spriteSpeed: {
28+
type: Number,
29+
default: 1
3030
}
3131
},
32-
data(){
33-
return{
34-
visible:true,
35-
frameIndex :0,
36-
tickCount: 0,
37-
frameLength:0,
38-
ticksPerFrame:0,
32+
data () {
33+
return {
34+
visible: true,
35+
frameIndex: 0,
36+
tickCount: 0,
37+
frameLength: 0,
38+
ticksPerFrame: 0,
3939
numberOfFrames: 0,
4040
frameRate: 20,
41-
ctx:'',
42-
canvas :'',
43-
mySprite:'',
44-
animationFrameId:-1
41+
ctx: '',
42+
canvas: '',
43+
mySprite: '',
44+
animationFrameId: -1
4545
}
4646
},
47-
mounted(){
47+
mounted () {
4848
let vm = this
4949
this.$nextTick(() => {
5050
vm.mySprite = new Image()
51-
vm.mySprite.onload = (e)=>{
51+
vm.mySprite.onload = e => {
5252
vm.spriteInit(e.target)
5353
}
5454
vm.mySprite.src = vm.spriteSrc
5555
})
5656
},
57-
methods:{
58-
spriteInit(img){
57+
methods: {
58+
spriteInit (img) {
5959
this.canvas = this.$el.querySelector(`#${this.spriteId}`)
6060
this.ctx = this.canvas.getContext('2d')
6161
this.ticksPerFrame = this.spriteSpeed
6262
this.frameLength = img.width
6363
this.numberOfFrames = img.width / this.spriteW
6464
this.spriteLoop()
65-
6665
},
67-
spriteUpdate(){
66+
spriteUpdate () {
6867
this.tickCount ++
6968
if (this.tickCount > this.ticksPerFrame) {
7069
this.tickCount = 0
@@ -77,30 +76,25 @@ export default {
7776
}
7877
}
7978
},
80-
spriteRender(){
81-
this.ctx.clearRect(0, 0, this.spriteW, this.spriteH);
82-
// Draw the animation
83-
var toDraw = this.frameIndex * this.spriteW
84-
this.ctx.drawImage(
85-
this.mySprite,
86-
toDraw ,
87-
0,
88-
this.spriteW,
89-
this.spriteH,
90-
0,
91-
0,
92-
this.spriteW,
93-
this.spriteH)
79+
spriteRender () {
80+
this.ctx.clearRect(0, 0, this.spriteW, this.spriteH)
81+
// Draw the animation
82+
const toDraw = this.frameIndex * this.spriteW
83+
this.ctx.drawImage(
84+
this.mySprite,
85+
toDraw, 0, this.spriteW, this.spriteH,
86+
0, 0, this.spriteW, this.spriteH
87+
)
9488
},
95-
spriteLoop(){
89+
spriteLoop () {
9690
this.animationFrameId = window.requestAnimationFrame(this.spriteLoop)
9791
this.spriteUpdate()
9892
this.spriteRender()
9993
},
100-
stop(){
94+
stop () {
10195
window.cancelAnimationFrame(this.animationFrameId)
10296
},
103-
play(){
97+
play () {
10498
this.spriteLoop()
10599
}
106100
}

0 commit comments

Comments
 (0)