Skip to content

Commit de5cd9b

Browse files
authored
chore: add eslint (vuejs#282)
* chore: add eslint * chore: lint on ci
1 parent d45b38c commit de5cd9b

19 files changed

+913
-62
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ jobs:
3939
at: ~/
4040
- run: yarn example
4141

42+
lint:
43+
<<: *defaults
44+
steps:
45+
- attach_workspace:
46+
at: ~/
47+
- run: yarn lint
48+
4249
test:
4350
<<: *defaults
4451
steps:
@@ -57,6 +64,9 @@ workflows:
5764
- example-build:
5865
requires:
5966
- install
67+
- lint:
68+
requires:
69+
- install
6070
- test:
6171
requires:
6272
- install

.eslintignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/dist/
2+
/lib/
3+
node_modules/
4+
5+
/test/test.build.js
6+
/example/build.js
7+
8+
# TOOD: remove after fixed decorator indent issue
9+
# https://github.com/eslint/typescript-eslint-parser/issues/438
10+
/example
11+
/test

.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['plugin:vue-libs/recommended'],
4+
parserOptions: {
5+
parser: 'typescript-eslint-parser'
6+
},
7+
rules: {
8+
'no-unused-vars': 'off',
9+
'no-undef': 'off'
10+
}
11+
}

build/dev-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fs.watch('test/test.build.js', () => {
88
run('mocha --reporter min test/test.build.js')
99
})
1010

11-
function run(command) {
11+
function run (command) {
1212
const [name, ...args] = command.split(' ')
1313
spawn(`node_modules/.bin/${name}`, args, {
1414
shell: true,

example/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class App extends AppProps {
8282
}
8383
8484
// direct dispatch example
85-
incrementIfOdd() {
85+
incrementIfOdd () {
8686
this.$store.dispatch('incrementIfOdd')
8787
}
8888
}

example/src/components/Hello.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
</template>
44

55
<script lang="ts">
6-
import Vue from 'vue'
7-
import Component from '../../../lib/index'
6+
import Vue from 'vue'
7+
import Component from '../../../lib/index'
88
9-
@Component
10-
export default class Hello extends Vue {
11-
helloTimes: number = 0
9+
@Component
10+
export default class Hello extends Vue {
11+
helloTimes: number = 0
1212
13-
sayHello () {
14-
this.helloTimes++
15-
}
13+
sayHello () {
14+
this.helloTimes++
1615
}
16+
}
1717
</script>
1818

example/src/components/World.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Component from '../../../lib/index'
33

44
@Component
55
export default class World extends Vue {
6-
render(h: CreateElement) {
6+
render (h: CreateElement) {
77
return <p>This is rendered via TSX</p>
88
}
99
}

example/src/shims-tsx.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue, { VNode } from "vue"
1+
import Vue, { VNode } from 'vue'
22

33
declare global {
44
namespace JSX {

example/src/store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
2-
import Vuex from "vuex"
2+
import Vuex from 'vuex'
33

4-
interface CounterState{
4+
interface CounterState {
55
count: number
66
}
77

@@ -20,4 +20,4 @@ const mutations = {
2020
export default new Vuex.Store({
2121
state,
2222
mutations
23-
})
23+
})

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"example": "npm run build && webpack --config example/webpack.config.js",
1717
"dev": "webpack --config example/webpack.config.js --watch",
1818
"dev:test": "node build/dev-test.js",
19+
"lint": "eslint --ext js,jsx,ts,tsx,vue .",
1920
"test": "npm run build && webpack --config test/webpack.config.js && mocha test/test.build.js",
2021
"release": "bash build/release.sh"
2122
},
@@ -48,6 +49,8 @@
4849
"babel-plugin-transform-vue-jsx": "^4.0.1",
4950
"chai": "^4.1.2",
5051
"css-loader": "^1.0.0",
52+
"eslint": "^5.7.0",
53+
"eslint-plugin-vue-libs": "^3.0.0",
5154
"mocha": "^5.0.1",
5255
"reflect-metadata": "^0.1.12",
5356
"rimraf": "^2.6.2",
@@ -56,6 +59,7 @@
5659
"testdouble": "^3.5.0",
5760
"ts-loader": "^5.2.1",
5861
"typescript": "^3.1.1",
62+
"typescript-eslint-parser": "^20.0.0",
5963
"uglify-js": "^3.3.10",
6064
"vue": "^2.5.13",
6165
"vue-loader": "^15.4.2",

src/component.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export function componentFactory (
3939
}
4040
const descriptor = Object.getOwnPropertyDescriptor(proto, key)!
4141
if (descriptor.value !== void 0) {
42-
4342
// methods
4443
if (typeof descriptor.value === 'function') {
4544
(options.methods || (options.methods = {}))[key] = descriptor.value
@@ -51,7 +50,6 @@ export function componentFactory (
5150
}
5251
})
5352
}
54-
5553
} else if (descriptor.get || descriptor.set) {
5654
// computed properties
5755
(options.computed || (options.computed = {}))[key] = {
@@ -138,7 +136,6 @@ function forwardStaticMembers (
138136
// we can check equality of them and exclude it if they have the same reference.
139137
// If it is a primitive value, it will be forwarded for safety.
140138
if (!hasProto) {
141-
142139
// Only `cid` is explicitly exluded from property forwarding
143140
// because we cannot detect whether it is a inherited property or not
144141
// on the no `__proto__` environment even though the property is reserved.
@@ -149,18 +146,18 @@ function forwardStaticMembers (
149146
const superDescriptor = Object.getOwnPropertyDescriptor(Super, key)
150147

151148
if (
152-
!isPrimitive(descriptor.value)
153-
&& superDescriptor
154-
&& superDescriptor.value === descriptor.value
149+
!isPrimitive(descriptor.value) &&
150+
superDescriptor &&
151+
superDescriptor.value === descriptor.value
155152
) {
156153
return
157154
}
158155
}
159156

160157
// Warn if the users manually declare reserved properties
161158
if (
162-
process.env.NODE_ENV !== 'production'
163-
&& reservedPropertyNames.indexOf(key) >= 0
159+
process.env.NODE_ENV !== 'production' &&
160+
reservedPropertyNames.indexOf(key) >= 0
164161
) {
165162
warn(
166163
`Static property name '${key}' declared on class '${Original.name}' ` +

src/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function collectDataFromConstructor (vm: Vue, Component: VueClass<Vue>) {
2020
if (key.charAt(0) !== '_') {
2121
Object.defineProperty(this, key, {
2222
get: () => vm[key],
23-
set: value => vm[key] = value,
23+
set: value => { vm[key] = value },
2424
configurable: true
2525
})
2626
}

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ function Component (options: ComponentOptions<Vue> | VueClass<Vue>): any {
1515
}
1616
}
1717

18-
namespace Component {
19-
export function registerHooks (keys: string[]): void {
20-
$internalHooks.push(...keys)
21-
}
18+
Component.registerHooks = function registerHooks (keys: string[]): void {
19+
$internalHooks.push(...keys)
2220
}
2321

2422
export default Component

src/reflect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function copyReflectionMetadata (
2020
})
2121
}
2222

23-
function forwardMetadata(to: object, from: object, propertyKey?: string): void {
23+
function forwardMetadata (to: object, from: object, propertyKey?: string): void {
2424
const metaKeys = propertyKey
2525
? Reflect.getOwnMetadataKeys(from, propertyKey)
2626
: Reflect.getOwnMetadataKeys(from)

src/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { VueClass, DecoratedClass } from './declarations'
33

44
export const noop = () => {}
55

6-
export const hasProto = { __proto__: [] } instanceof Array
6+
const fakeArray = { __proto__: [] }
7+
export const hasProto = fakeArray instanceof Array
78

89
export interface VueDecorator {
910
// Class decorator
@@ -43,7 +44,7 @@ export function mixins (...Ctors: VueClass<Vue>[]): VueClass<Vue> {
4344

4445
export function isPrimitive (value: any): boolean {
4546
const type = typeof value
46-
return value == null || (type !== "object" && type !== "function")
47+
return value == null || (type !== 'object' && type !== 'function')
4748
}
4849

4950
export function warn (message: string): void {

test/.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+
mocha: true
4+
}
5+
}

test/test-babel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('vue-class-component with Babel', () => {
4040
const getterDecorator = (value) => () => {
4141
return {
4242
enumerable: true,
43-
get() {
44-
return value;
43+
get () {
44+
return value
4545
}
4646
}
4747
}

test/test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import 'reflect-metadata';
1+
import 'reflect-metadata'
22
import Component, { createDecorator, mixins } from '../lib'
33
import { expect } from 'chai'
44
import * as td from 'testdouble'
55
import Vue, { ComputedOptions } from 'vue'
66

77
describe('vue-class-component', () => {
8-
98
it('hooks', () => {
109
let created = false
1110
let destroyed = false
@@ -72,21 +71,19 @@ describe('vue-class-component', () => {
7271
const getterDecorator = (value: any) => (_: any, __: any): any => {
7372
return {
7473
enumerable: true,
75-
get() {
76-
return value;
74+
get () {
75+
return value
7776
}
7877
}
7978
}
8079

8180
@Component
8281
class MyComp extends Vue {
83-
8482
@valueDecorator('field1')
8583
field1!: string
8684

8785
@getterDecorator('field2')
8886
field2!: string
89-
9087
}
9188

9289
const c = new MyComp()
@@ -347,7 +344,7 @@ describe('vue-class-component', () => {
347344
class MyComp extends Vue {
348345
static myValue = 52
349346

350-
static myFunc() {
347+
static myFunc () {
351348
return 42
352349
}
353350
}

0 commit comments

Comments
 (0)