Skip to content

Commit

Permalink
chore: add eslint (#282)
Browse files Browse the repository at this point in the history
* chore: add eslint

* chore: lint on ci
  • Loading branch information
ktsn committed Oct 13, 2018
1 parent d45b38c commit de5cd9b
Show file tree
Hide file tree
Showing 19 changed files with 913 additions and 62 deletions.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Expand Up @@ -39,6 +39,13 @@ jobs:
at: ~/
- run: yarn example

lint:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn lint

test:
<<: *defaults
steps:
Expand All @@ -57,6 +64,9 @@ workflows:
- example-build:
requires:
- install
- lint:
requires:
- install
- test:
requires:
- install
11 changes: 11 additions & 0 deletions .eslintignore
@@ -0,0 +1,11 @@
/dist/
/lib/
node_modules/

/test/test.build.js
/example/build.js

# TOOD: remove after fixed decorator indent issue
# https://github.com/eslint/typescript-eslint-parser/issues/438
/example
/test
11 changes: 11 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,11 @@
module.exports = {
root: true,
extends: ['plugin:vue-libs/recommended'],
parserOptions: {
parser: 'typescript-eslint-parser'
},
rules: {
'no-unused-vars': 'off',
'no-undef': 'off'
}
}
2 changes: 1 addition & 1 deletion build/dev-test.js
Expand Up @@ -8,7 +8,7 @@ fs.watch('test/test.build.js', () => {
run('mocha --reporter min test/test.build.js')
})

function run(command) {
function run (command) {
const [name, ...args] = command.split(' ')
spawn(`node_modules/.bin/${name}`, args, {
shell: true,
Expand Down
2 changes: 1 addition & 1 deletion example/src/App.vue
Expand Up @@ -82,7 +82,7 @@ export default class App extends AppProps {
}
// direct dispatch example
incrementIfOdd() {
incrementIfOdd () {
this.$store.dispatch('incrementIfOdd')
}
}
Expand Down
16 changes: 8 additions & 8 deletions example/src/components/Hello.vue
Expand Up @@ -3,16 +3,16 @@
</template>

<script lang="ts">
import Vue from 'vue'
import Component from '../../../lib/index'
import Vue from 'vue'
import Component from '../../../lib/index'
@Component
export default class Hello extends Vue {
helloTimes: number = 0
@Component
export default class Hello extends Vue {
helloTimes: number = 0
sayHello () {
this.helloTimes++
}
sayHello () {
this.helloTimes++
}
}
</script>

2 changes: 1 addition & 1 deletion example/src/components/World.tsx
Expand Up @@ -3,7 +3,7 @@ import Component from '../../../lib/index'

@Component
export default class World extends Vue {
render(h: CreateElement) {
render (h: CreateElement) {
return <p>This is rendered via TSX</p>
}
}
2 changes: 1 addition & 1 deletion example/src/shims-tsx.d.ts
@@ -1,4 +1,4 @@
import Vue, { VNode } from "vue"
import Vue, { VNode } from 'vue'

declare global {
namespace JSX {
Expand Down
6 changes: 3 additions & 3 deletions example/src/store.ts
@@ -1,7 +1,7 @@
import Vue from 'vue'
import Vuex from "vuex"
import Vuex from 'vuex'

interface CounterState{
interface CounterState {
count: number
}

Expand All @@ -20,4 +20,4 @@ const mutations = {
export default new Vuex.Store({
state,
mutations
})
})
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -16,6 +16,7 @@
"example": "npm run build && webpack --config example/webpack.config.js",
"dev": "webpack --config example/webpack.config.js --watch",
"dev:test": "node build/dev-test.js",
"lint": "eslint --ext js,jsx,ts,tsx,vue .",
"test": "npm run build && webpack --config test/webpack.config.js && mocha test/test.build.js",
"release": "bash build/release.sh"
},
Expand Down Expand Up @@ -48,6 +49,8 @@
"babel-plugin-transform-vue-jsx": "^4.0.1",
"chai": "^4.1.2",
"css-loader": "^1.0.0",
"eslint": "^5.7.0",
"eslint-plugin-vue-libs": "^3.0.0",
"mocha": "^5.0.1",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
Expand All @@ -56,6 +59,7 @@
"testdouble": "^3.5.0",
"ts-loader": "^5.2.1",
"typescript": "^3.1.1",
"typescript-eslint-parser": "^20.0.0",
"uglify-js": "^3.3.10",
"vue": "^2.5.13",
"vue-loader": "^15.4.2",
Expand Down
13 changes: 5 additions & 8 deletions src/component.ts
Expand Up @@ -39,7 +39,6 @@ export function componentFactory (
}
const descriptor = Object.getOwnPropertyDescriptor(proto, key)!
if (descriptor.value !== void 0) {

// methods
if (typeof descriptor.value === 'function') {
(options.methods || (options.methods = {}))[key] = descriptor.value
Expand All @@ -51,7 +50,6 @@ export function componentFactory (
}
})
}

} else if (descriptor.get || descriptor.set) {
// computed properties
(options.computed || (options.computed = {}))[key] = {
Expand Down Expand Up @@ -138,7 +136,6 @@ function forwardStaticMembers (
// we can check equality of them and exclude it if they have the same reference.
// If it is a primitive value, it will be forwarded for safety.
if (!hasProto) {

// Only `cid` is explicitly exluded from property forwarding
// because we cannot detect whether it is a inherited property or not
// on the no `__proto__` environment even though the property is reserved.
Expand All @@ -149,18 +146,18 @@ function forwardStaticMembers (
const superDescriptor = Object.getOwnPropertyDescriptor(Super, key)

if (
!isPrimitive(descriptor.value)
&& superDescriptor
&& superDescriptor.value === descriptor.value
!isPrimitive(descriptor.value) &&
superDescriptor &&
superDescriptor.value === descriptor.value
) {
return
}
}

// Warn if the users manually declare reserved properties
if (
process.env.NODE_ENV !== 'production'
&& reservedPropertyNames.indexOf(key) >= 0
process.env.NODE_ENV !== 'production' &&
reservedPropertyNames.indexOf(key) >= 0
) {
warn(
`Static property name '${key}' declared on class '${Original.name}' ` +
Expand Down
2 changes: 1 addition & 1 deletion src/data.ts
Expand Up @@ -20,7 +20,7 @@ export function collectDataFromConstructor (vm: Vue, Component: VueClass<Vue>) {
if (key.charAt(0) !== '_') {
Object.defineProperty(this, key, {
get: () => vm[key],
set: value => vm[key] = value,
set: value => { vm[key] = value },
configurable: true
})
}
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Expand Up @@ -15,10 +15,8 @@ function Component (options: ComponentOptions<Vue> | VueClass<Vue>): any {
}
}

namespace Component {
export function registerHooks (keys: string[]): void {
$internalHooks.push(...keys)
}
Component.registerHooks = function registerHooks (keys: string[]): void {
$internalHooks.push(...keys)
}

export default Component
2 changes: 1 addition & 1 deletion src/reflect.ts
Expand Up @@ -20,7 +20,7 @@ export function copyReflectionMetadata (
})
}

function forwardMetadata(to: object, from: object, propertyKey?: string): void {
function forwardMetadata (to: object, from: object, propertyKey?: string): void {
const metaKeys = propertyKey
? Reflect.getOwnMetadataKeys(from, propertyKey)
: Reflect.getOwnMetadataKeys(from)
Expand Down
5 changes: 3 additions & 2 deletions src/util.ts
Expand Up @@ -3,7 +3,8 @@ import { VueClass, DecoratedClass } from './declarations'

export const noop = () => {}

export const hasProto = { __proto__: [] } instanceof Array
const fakeArray = { __proto__: [] }
export const hasProto = fakeArray instanceof Array

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

export function isPrimitive (value: any): boolean {
const type = typeof value
return value == null || (type !== "object" && type !== "function")
return value == null || (type !== 'object' && type !== 'function')
}

export function warn (message: string): void {
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc.js
@@ -0,0 +1,5 @@
module.exports = {
env: {
mocha: true
}
}
4 changes: 2 additions & 2 deletions test/test-babel.js
Expand Up @@ -40,8 +40,8 @@ describe('vue-class-component with Babel', () => {
const getterDecorator = (value) => () => {
return {
enumerable: true,
get() {
return value;
get () {
return value
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions test/test.ts
@@ -1,11 +1,10 @@
import 'reflect-metadata';
import 'reflect-metadata'
import Component, { createDecorator, mixins } from '../lib'
import { expect } from 'chai'
import * as td from 'testdouble'
import Vue, { ComputedOptions } from 'vue'

describe('vue-class-component', () => {

it('hooks', () => {
let created = false
let destroyed = false
Expand Down Expand Up @@ -72,21 +71,19 @@ describe('vue-class-component', () => {
const getterDecorator = (value: any) => (_: any, __: any): any => {
return {
enumerable: true,
get() {
return value;
get () {
return value
}
}
}

@Component
class MyComp extends Vue {

@valueDecorator('field1')
field1!: string

@getterDecorator('field2')
field2!: string

}

const c = new MyComp()
Expand Down Expand Up @@ -347,7 +344,7 @@ describe('vue-class-component', () => {
class MyComp extends Vue {
static myValue = 52

static myFunc() {
static myFunc () {
return 42
}
}
Expand Down

0 comments on commit de5cd9b

Please sign in to comment.