Skip to content

Commit

Permalink
refactor: add max-len rule (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Jun 15, 2018
1 parent 51dcc9e commit 2872a20
Show file tree
Hide file tree
Showing 128 changed files with 3,096 additions and 1,767 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Expand Up @@ -12,8 +12,9 @@
"plugin:vue-libs/recommended",
"plugin:flowtype/recommended"
],
rules: {
"rules": {
"no-debugger": 2,
"no-proto": 0
"no-proto": 0,
"max-len": 2
}
}
4 changes: 3 additions & 1 deletion docs/api/options.md
Expand Up @@ -82,7 +82,9 @@ const wrapper = shallowMount(Component, {
foo: '<p slot-scope="props">{{props.index}},{{props.text}}</p>'
}
})
expect(wrapper.find('#fooWrapper').html()).toBe('<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>')
expect(wrapper.find('#fooWrapper').html()).toBe(
`<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>`
)
```

## stubs
Expand Down
3 changes: 2 additions & 1 deletion docs/api/wrapper-array/filter.md
Expand Up @@ -18,5 +18,6 @@ import { shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = shallowMount(Foo)
const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered'))
const filteredDivArray = wrapper.findAll('div')
.filter(w => !w.hasClass('filtered'))
```
6 changes: 4 additions & 2 deletions docs/guides/common-tips.md
Expand Up @@ -23,7 +23,7 @@ Vue Test Utils allows you to mount a component without rendering its child compo
```js
import { shallowMount } from '@vue/test-utils'

const wrapper = shallowMount(Component) // returns a Wrapper containing a mounted Component instance
const wrapper = shallowMount(Component)
wrapper.vm // the mounted Vue instance
```

Expand Down Expand Up @@ -125,7 +125,9 @@ const $route = {

mount(Component, {
mocks: {
$route // adds the mocked `$route` object to the Vue instance before mounting component
// adds mocked `$route` object to the Vue instance
// before mounting component
$route
}
})
```
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/using-with-vuex.md
Expand Up @@ -69,15 +69,15 @@ describe('Actions.vue', () => {
})
})

it('calls store action "actionInput" when input value is "input" and an "input" event is fired', () => {
it('dispatches "actionInput" when input event value is "input"', () => {
const wrapper = shallowMount(Actions, { store, localVue })
const input = wrapper.find('input')
input.element.value = 'input'
input.trigger('input')
expect(actions.actionInput).toHaveBeenCalled()
})

it('does not call store action "actionInput" when input value is not "input" and an "input" event is fired', () => {
it('does not dispatch "actionInput" when event value is not "input"', () => {
const wrapper = shallowMount(Actions, { store, localVue })
const input = wrapper.find('input')
input.element.value = 'not input'
Expand Down
4 changes: 3 additions & 1 deletion docs/ja/api/options.md
Expand Up @@ -77,7 +77,9 @@ const wrapper = shallowMount(Component, {
foo: '<p slot-scope="props">{{props.index}},{{props.text}}</p>'
}
})
expect(wrapper.find('#fooWrapper').html()).toBe('<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>')
expect(wrapper.find('#fooWrapper').html()).toBe(
`<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>`
)
```

## stubs
Expand Down
3 changes: 2 additions & 1 deletion docs/ja/api/wrapper-array/filter.md
Expand Up @@ -18,5 +18,6 @@ import { shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = shallowMount(Foo)
const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered'))
const filteredDivArray = wrapper.findAll('div')
.filter(w => !w.hasClass('filtered'))
```
4 changes: 2 additions & 2 deletions docs/ja/guides/using-with-vuex.md
Expand Up @@ -68,15 +68,15 @@ describe('Actions.vue', () => {
})
})

it('calls store action actionInput when input value is input and an input event is fired', () => {
it('dispatches "actionInput" when input event value is "input"', () => {
const wrapper = shallowMount(Actions, { store, localVue })
const input = wrapper.find('input')
input.element.value = 'input'
input.trigger('input')
expect(actions.actionInput).toHaveBeenCalled()
})

it('does not call store action actionInput when input value is not input and an input event is fired', () => {
it('does not dispatch "actionInput" when event value is not "input"', () => {
const wrapper = shallowMount(Actions, { store, localVue })
const input = wrapper.find('input')
input.element.value = 'not input'
Expand Down
4 changes: 3 additions & 1 deletion docs/zh/api/options.md
Expand Up @@ -82,7 +82,9 @@ const wrapper = shallowMount(Component, {
foo: '<p slot-scope="props">{{props.index}},{{props.text}}</p>'
}
})
expect(wrapper.find('#fooWrapper').html()).toBe('<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>')
expect(wrapper.find('#fooWrapper').html()).toBe(
`<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>`
)
```

## stubs
Expand Down
3 changes: 2 additions & 1 deletion docs/zh/api/wrapper-array/filter.md
Expand Up @@ -18,5 +18,6 @@ import { shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = shallowMount(Foo)
const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered'))
const filteredDivArray = wrapper.findAll('div')
.filter(w => !w.hasClass('filtered'))
```
37 changes: 19 additions & 18 deletions flow/options.flow.js
@@ -1,20 +1,21 @@
declare type Options = { // eslint-disable-line no-undef
attachToDocument?: boolean,
propsData?: Object,
mocks?: Object,
methods?: Object,
slots?: Object,
scopedSlots?: Object,
localVue?: Component,
provide?: Object,
stubs?: Object,
context?: Object,
attrs?: Object,
listeners?: Object,
logModifiedComponents?: boolean,
sync?: boolean
}
declare type Options = {
// eslint-disable-line no-undef
attachToDocument?: boolean,
propsData?: Object,
mocks?: Object,
methods?: Object,
slots?: Object,
scopedSlots?: Object,
localVue?: Component,
provide?: Object,
stubs?: Object,
context?: Object,
attrs?: Object,
listeners?: Object,
logModifiedComponents?: boolean,
sync?: boolean
};

declare type SlotValue = Component | string | Array<Component | string>
declare type SlotValue = Component | string | Array<Component | string>;

declare type SlotsObject = {[name: string]: SlotValue}
declare type SlotsObject = { [name: string]: SlotValue };
4 changes: 2 additions & 2 deletions flow/vue.flow.js
Expand Up @@ -2,5 +2,5 @@

// Importing these types declares them, so they are available globally

declare type Component = Object | Function // eslint-disable-line no-undef
declare type VNode = Object // eslint-disable-line no-undef
declare type Component = Object | Function; // eslint-disable-line no-undef
declare type VNode = Object; // eslint-disable-line no-undef
80 changes: 42 additions & 38 deletions flow/wrapper.flow.js
Expand Up @@ -3,44 +3,48 @@
import type Wrapper from '~src/Wrapper'
import type WrapperArray from '~src/WrapperArray'

declare type Selector = any
declare type Selector = any;

declare interface BaseWrapper { // eslint-disable-line no-undef
at(index: number): Wrapper | void,
attributes(): { [name: string]: string } | void,
classes(): Array<string> | void,
contains(selector: Selector): boolean | void,
emitted(event?: string): { [name: string]: Array<Array<any>> } | Array<Array<any>> | void,
emittedByOrder(): Array<{ name: string; args: Array<any> }> | void,
exists(): boolean,
filter(predicate: Function): WrapperArray | void,
visible(): boolean | void,
hasAttribute(attribute: string, value: string): boolean | void,
hasClass(className: string): boolean | void,
hasProp(prop: string, value: string): boolean | void,
hasStyle(style: string, value: string): boolean | void,
find(selector: Selector): Wrapper | void,
findAll(selector: Selector): WrapperArray | void,
html(): string | void,
is(selector: Selector): boolean | void,
isEmpty(): boolean | void,
isVisible(): boolean | void,
isVueInstance(): boolean | void,
name(): string | void,
props(): { [name: string]: any } | void,
text(): string | void,
setData(data: Object): void,
setComputed(computed: Object): void,
setMethods(methods: Object): void,
setValue(value: any): void,
setChecked(checked: boolean): void,
setSelected(): void,
setProps(data: Object): void,
trigger(type: string, options: Object): void,
destroy(): void
declare interface BaseWrapper {
// eslint-disable-line no-undef
at(index: number): Wrapper | void;
attributes(): { [name: string]: string } | void;
classes(): Array<string> | void;
contains(selector: Selector): boolean | void;
emitted(
event?: string
): { [name: string]: Array<Array<any>> } | Array<Array<any>> | void;
emittedByOrder(): Array<{ name: string, args: Array<any> }> | void;
exists(): boolean;
filter(predicate: Function): WrapperArray | void;
visible(): boolean | void;
hasAttribute(attribute: string, value: string): boolean | void;
hasClass(className: string): boolean | void;
hasProp(prop: string, value: string): boolean | void;
hasStyle(style: string, value: string): boolean | void;
find(selector: Selector): Wrapper | void;
findAll(selector: Selector): WrapperArray | void;
html(): string | void;
is(selector: Selector): boolean | void;
isEmpty(): boolean | void;
isVisible(): boolean | void;
isVueInstance(): boolean | void;
name(): string | void;
props(): { [name: string]: any } | void;
text(): string | void;
setData(data: Object): void;
setComputed(computed: Object): void;
setMethods(methods: Object): void;
setValue(value: any): void;
setChecked(checked: boolean): void;
setSelected(): void;
setProps(data: Object): void;
trigger(type: string, options: Object): void;
destroy(): void;
}

declare type WrapperOptions = { // eslint-disable-line no-undef
attachedToDocument: boolean,
sync?: boolean
}
declare type WrapperOptions = {
// eslint-disable-line no-undef
attachedToDocument: boolean,
sync?: boolean
};
8 changes: 6 additions & 2 deletions packages/create-instance/add-mocks.js
Expand Up @@ -3,11 +3,15 @@ import $$Vue from 'vue'
import { warn } from 'shared/util'

export default function addMocks (mockedProperties: Object, Vue: Component) {
Object.keys(mockedProperties).forEach((key) => {
Object.keys(mockedProperties).forEach(key => {
try {
Vue.prototype[key] = mockedProperties[key]
} catch (e) {
warn(`could not overwrite property ${key}, this usually caused by a plugin that has added the property as a read-only value`)
warn(
`could not overwrite property ${key}, this is ` +
`usually caused by a plugin that has added ` +
`the property as a read-only value`
)
}
$$Vue.util.defineReactive(Vue, key, mockedProperties[key])
})
Expand Down
8 changes: 3 additions & 5 deletions packages/create-instance/add-slots.js
Expand Up @@ -11,14 +11,12 @@ function createVNodesForSlot (
slotValue: SlotValue,
name: string
): VNode | string {
if (typeof slotValue === 'string' &&
!startsWithTag(slotValue)) {
if (typeof slotValue === 'string' && !startsWithTag(slotValue)) {
return slotValue
}

const el = typeof slotValue === 'string'
? compileToFunctions(slotValue)
: slotValue
const el =
typeof slotValue === 'string' ? compileToFunctions(slotValue) : slotValue

const vnode = h(el)
vnode.data.slot = name
Expand Down
20 changes: 16 additions & 4 deletions packages/create-instance/create-functional-component.js
Expand Up @@ -16,13 +16,17 @@ function createFunctionalSlots (slots = {}, h) {
Object.keys(slots).forEach(slotType => {
if (Array.isArray(slots[slotType])) {
slots[slotType].forEach(slot => {
const component = typeof slot === 'string' ? compileToFunctions(slot) : slot
const component =
typeof slot === 'string' ? compileToFunctions(slot) : slot
const newSlot = h(component)
newSlot.data.slot = slotType
children.push(newSlot)
})
} else {
const component = typeof slots[slotType] === 'string' ? compileToFunctions(slots[slotType]) : slots[slotType]
const component =
typeof slots[slotType] === 'string'
? compileToFunctions(slots[slotType])
: slots[slotType]
const slot = h(component)
slot.data.slot = slotType
children.push(slot)
Expand All @@ -31,7 +35,10 @@ function createFunctionalSlots (slots = {}, h) {
return children
}

export default function createFunctionalComponent (component: Component, mountingOptions: Options) {
export default function createFunctionalComponent (
component: Component,
mountingOptions: Options
) {
if (mountingOptions.context && typeof mountingOptions.context !== 'object') {
throwError('mount.context must be an object')
}
Expand All @@ -44,7 +51,12 @@ export default function createFunctionalComponent (component: Component, mountin
return h(
component,
mountingOptions.context || component.FunctionalRenderContext,
(mountingOptions.context && mountingOptions.context.children && mountingOptions.context.children.map(x => typeof x === 'function' ? x(h) : x)) || createFunctionalSlots(mountingOptions.slots, h)
(mountingOptions.context &&
mountingOptions.context.children &&
mountingOptions.context.children.map(
x => (typeof x === 'function' ? x(h) : x)
)) ||
createFunctionalSlots(mountingOptions.slots, h)
)
},
name: component.name,
Expand Down

0 comments on commit 2872a20

Please sign in to comment.