Skip to content

Commit 80206b8

Browse files
committed
use eslint
1 parent 1cf71fd commit 80206b8

12 files changed

+92
-26
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/demo/
2+
/dist/
3+
/*.js

.eslintrc.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://eslint.org/docs/user-guide/configuring
2+
3+
module.exports = {
4+
root: true,
5+
parserOptions: {
6+
parser: 'babel-eslint'
7+
},
8+
env: {
9+
browser: true,
10+
},
11+
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12+
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13+
extends: ['plugin:vue/essential'],
14+
// required to lint *.vue files
15+
plugins: [
16+
'vue'
17+
],
18+
// add your custom rules here
19+
rules: {
20+
// allow debugger during development
21+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
22+
'space-before-function-paren': ['error', 'always']
23+
}
24+
}

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@
4444
"devDependencies": {
4545
"autoprefixer": "^8.1.0",
4646
"babel-core": "^6.18.2",
47+
"babel-eslint": "^8.2.2",
4748
"babel-loader": "^7.1.4",
4849
"babel-preset-env": "^1.6.1",
4950
"babel-preset-stage-2": "^6.24.1",
5051
"css-loader": "^0.28.10",
52+
"eslint": "^4.18.2",
53+
"eslint-friendly-formatter": "^3.0.0",
54+
"eslint-loader": "^2.0.0",
55+
"eslint-plugin-vue": "^4.3.0",
5156
"file-loader": "^1.1.11",
5257
"gh-pages": "^1.1.0",
5358
"html-webpack-plugin": "^3.0.6",

src/components/aplayer-icon.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
export default {
2323
props: ['type'],
2424
computed: {
25-
viewBox() {
25+
viewBox () {
2626
return SVG[this.type][0]
2727
},
28-
d() {
28+
d () {
2929
return SVG[this.type][1]
3030
},
3131
},

src/components/aplayer-list.vue

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
ref="ol"
1010
:style="{maxHeight: listmaxheight || ''}"
1111
>
12-
<li v-for="(aMusic, index) of musicList"
13-
:class="{'aplayer-list-light': aMusic === currentMusic}"
14-
@click="$emit('selectsong', aMusic)"
12+
<li
13+
v-for="(aMusic, index) of musicList"
14+
:key="index"
15+
:class="{'aplayer-list-light': aMusic === currentMusic}"
16+
@click="$emit('selectsong', aMusic)"
1517
>
1618
<span class="aplayer-list-cur" :style="{background: theme}"></span>
1719
<span class="aplayer-list-index">{{ index + 1}}</span>
@@ -62,7 +64,6 @@
6264
height: 0 !important;
6365
}
6466
65-
6667
ol {
6768
list-style-type: none;
6869
margin: 0;

src/components/aplayer-lrc.vue

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:style="transformStyle">
66
<p
77
v-for="(line, index) of lrcLines"
8+
:key="index"
89
:class="{ 'aplayer-lrc-current': index === currentLineIndex }"
910
>
1011
{{ line[1] }}
@@ -17,7 +18,16 @@
1718
import {parseLrc} from '../utils'
1819
1920
export default {
20-
props: ['currentMusic', 'playStat'],
21+
props: {
22+
currentMusic: {
23+
type: Object,
24+
required: true
25+
},
26+
playStat: {
27+
type: Object,
28+
required: true
29+
}
30+
},
2131
data () {
2232
return {
2333
displayLrc: '',

src/components/aplayer-thumbnail.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
6969
this.$emit('dragend')
7070
},
71-
onClick() {
71+
onClick () {
7272
if (!this.hasMovedSinceMouseDown) {
7373
this.$emit('toggleplay')
7474
}

src/demo/App.vue

+17-16
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
preload="metadata"
3636
mode="circulation"
3737
:music="{
38-
title: 'secret base~君がくれたもの~',
39-
author: 'Silent Siren',
40-
url: 'https://storage.googleapis.com/gh-pages-static/secretbase.mp3',
41-
pic: 'https://p3.music.126.net/HJYMPi7BLKFfSvA2T3OUmg==/3316127069531628.jpg?param=90y90'
42-
}"
38+
title: 'secret base~君がくれたもの~',
39+
author: 'Silent Siren',
40+
url: 'https://storage.googleapis.com/gh-pages-static/secretbase.mp3',
41+
pic: 'https://p3.music.126.net/HJYMPi7BLKFfSvA2T3OUmg==/3316127069531628.jpg?param=90y90'
42+
}"
4343
/>
4444

4545
<h3>With lyrics</h3>
@@ -49,12 +49,13 @@
4949
showlrc
5050
mode="circulation"
5151
:music="{
52-
title: 'Another Love',
53-
author: 'Tom Odell',
54-
url: 'https://storage.googleapis.com/gh-pages-static/anotherlove.mp3',
55-
pic: 'https://y.gtimg.cn/music/photo_new/T002R90x90M000002sJhjf0PwjRN.jpg?max_age=2592000',
56-
lrc: 'https://storage.googleapis.com/gh-pages-static/another-love.lrc'
57-
}"/>
52+
title: 'Another Love',
53+
author: 'Tom Odell',
54+
url: 'https://storage.googleapis.com/gh-pages-static/anotherlove.mp3',
55+
pic: 'https://y.gtimg.cn/music/photo_new/T002R90x90M000002sJhjf0PwjRN.jpg?max_age=2592000',
56+
lrc: 'https://storage.googleapis.com/gh-pages-static/another-love.lrc'
57+
}"
58+
/>
5859
<h3>With playlist</h3>
5960
<aplayer
6061
mutex
@@ -72,11 +73,11 @@
7273
theme="#e6d0b2"
7374
mode="circulation"
7475
:music="{
75-
title: 'secret base~君がくれたもの~',
76-
author: 'Silent Siren',
77-
url: 'https://storage.googleapis.com/gh-pages-static/secretbase.mp3',
78-
pic: 'https://p3.music.126.net/HJYMPi7BLKFfSvA2T3OUmg==/3316127069531628.jpg?param=90y90'
79-
}"
76+
title: 'secret base~君がくれたもの~',
77+
author: 'Silent Siren',
78+
url: 'https://storage.googleapis.com/gh-pages-static/secretbase.mp3',
79+
pic: 'https://p3.music.126.net/HJYMPi7BLKFfSvA2T3OUmg==/3316127069531628.jpg?param=90y90'
80+
}"
8081
/>
8182
</div>
8283
</div>

src/utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ export function warn (message) {
6161
return console.warn(`[vue-aplayer] ${message}`)
6262
}
6363

64-
export function deprecatedProp(name, sinceVersion, alternative) {
64+
export function deprecatedProp (name, sinceVersion, alternative) {
6565
return warn(`'${name}' is deprecated since v${sinceVersion}, and will be removed in future releases, use '${alternative}' instead`)
6666
}
67+
6768
export function getElementViewLeft (element) {
6869
let actualLeft = element.offsetLeft
6970
let current = element.offsetParent
@@ -75,6 +76,7 @@ export function getElementViewLeft (element) {
7576
elementScrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft
7677
return actualLeft - elementScrollLeft
7778
}
79+
7880
export function getElementViewTop (element) {
7981
let actualTop = element.offsetTop
8082
let current = element.offsetParent

src/vue-aplayer.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
}
203203
},
204204
computed: {
205-
enableFloat() {
205+
enableFloat () {
206206
return this.float && !this.isMobile
207207
},
208208
floatStyleObj () {

webpack.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ module.exports = {
1313

1414
module: {
1515
rules: [
16+
{
17+
test: /\.(js|vue)$/,
18+
loader: 'eslint-loader',
19+
enforce: 'pre',
20+
include: [path.resolve(__dirname, 'src')],
21+
options: {
22+
formatter: require('eslint-friendly-formatter'),
23+
emitWarning: true
24+
}
25+
},
1626
{
1727
test: /\.vue$/,
1828
loader: 'vue-loader',

webpack.demo.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ module.exports = {
1111

1212
module: {
1313
rules: [
14+
{
15+
test: /\.(js|vue)$/,
16+
loader: 'eslint-loader',
17+
enforce: 'pre',
18+
include: [path.resolve(__dirname, 'src')],
19+
options: {
20+
formatter: require('eslint-friendly-formatter'),
21+
emitWarning: true
22+
}
23+
},
1424
{
1525
test: /\.vue$/,
1626
loader: 'vue-loader',

0 commit comments

Comments
 (0)