Skip to content

Commit

Permalink
build: upgrade eslint and use only non-stylistic rules
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 24, 2018
1 parent 980801c commit 76fd45c
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 281 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
root: true,
parserOptions: {
parser: require.resolve('babel-eslint'),
ecmaVersion: 2018,
sourceType: 'module'
},
env: {
es6: true,
node: true,
browser: true
},
plugins: [
"flowtype"
],
extends: [
"eslint:recommended",
"plugin:flowtype/recommended"
],
globals: {
"__WEEX__": true,
"WXEnvironment": true
},
rules: {
'no-console': process.env.NODE_ENV !== 'production' ? 0 : 2,
'no-useless-escape': 0,
'no-empty': 0
}
}
14 changes: 0 additions & 14 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion dist/vue.min.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test:ssr": "npm run build:ssr && jasmine JASMINE_CONFIG_PATH=test/ssr/jasmine.js",
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2",
"test:types": "tsc -p ./types/test/tsconfig.json",
"lint": "eslint --fix src scripts test",
"lint": "eslint src scripts test",
"flow": "flow check",
"sauce": "karma start test/unit/karma.sauce.config.js",
"bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js",
Expand Down Expand Up @@ -94,11 +94,9 @@
"de-indent": "^1.0.2",
"es6-promise": "^4.1.0",
"escodegen": "^1.8.1",
"eslint": "^4.13.1",
"eslint-loader": "^1.7.1",
"eslint": "^5.7.0",
"eslint-plugin-flowtype": "^2.34.0",
"eslint-plugin-jasmine": "^2.8.4",
"eslint-plugin-vue-libs": "^2.0.1",
"file-loader": "^1.1.5",
"flow-bin": "^0.61.0",
"hash-sum": "^1.0.2",
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/codegen/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const modifierCode: { [key: string]: string } = {

export function genHandlers (
events: ASTElementHandlers,
isNative: boolean,
warn: Function
isNative: boolean
): string {
let res = isNative ? 'nativeOn:{' : 'on:{'
for (const name in events) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ export function genData (el: ASTElement, state: CodegenState): string {
}
// event handlers
if (el.events) {
data += `${genHandlers(el.events, false, state.warn)},`
data += `${genHandlers(el.events, false)},`
}
if (el.nativeEvents) {
data += `${genHandlers(el.nativeEvents, true, state.warn)},`
data += `${genHandlers(el.nativeEvents, true)},`
}
// slot target
// only for non-scoped slots
Expand Down
2 changes: 1 addition & 1 deletion src/core/instance/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export function stateMixin (Vue: Class<Component>) {
const propsDef = {}
propsDef.get = function () { return this._props }
if (process.env.NODE_ENV !== 'production') {
dataDef.set = function (newData: Object) {
dataDef.set = function () {
warn(
'Avoid replacing instance root $data. ' +
'Use nested data properties instead.',
Expand Down
11 changes: 6 additions & 5 deletions src/core/observer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ export class Observer {
this.vmCount = 0
def(value, '__ob__', this)
if (Array.isArray(value)) {
const augment = hasProto
? protoAugment
: copyAugment
augment(value, arrayMethods, arrayKeys)
if (hasProto) {
protoAugment(value, arrayMethods)
} else {
copyAugment(value, arrayMethods, arrayKeys)
}
this.observeArray(value)
} else {
this.walk(value)
Expand Down Expand Up @@ -83,7 +84,7 @@ export class Observer {
* Augment an target Object or Array by intercepting
* the prototype chain using __proto__
*/
function protoAugment (target, src: Object, keys: any) {
function protoAugment (target, src: Object) {
/* eslint-disable no-proto */
target.__proto__ = src
/* eslint-enable no-proto */
Expand Down
3 changes: 1 addition & 2 deletions src/platforms/weex/compiler/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { genComponentModel, genAssignmentCode } from 'compiler/directives/model'

export default function model (
el: ASTElement,
dir: ASTDirective,
_warn: Function
dir: ASTDirective
): ?boolean {
if (el.tag === 'input' || el.tag === 'textarea') {
genDefaultModel(el, dir.value, dir.modifiers)
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/compiler/modules/append.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { makeMap } from 'shared/util'
// must be sent to the native together.
const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true)

function preTransformNode (el: ASTElement, options: CompilerOptions) {
function preTransformNode (el: ASTElement) {
if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) {
el.attrsMap.append = 'tree'
el.attrsList.push({ name: 'append', value: 'tree' })
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/compiler/modules/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function normalizeKeyName (str: string): string {
return normalize(str)
}

function transformNode (el: ASTElement, options: CompilerOptions) {
function transformNode (el: ASTElement) {
if (Array.isArray(el.attrsList)) {
el.attrsList.forEach(attr => {
if (attr.name && attr.name.match(/\-/)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import { addAttr } from 'compiler/helpers'

// mark component root nodes as
export function postTransformComponentRoot (
el: ASTElement,
options: WeexCompilerOptions
) {
export function postTransformComponentRoot (el: ASTElement) {
if (!el.parent) {
// component root
addAttr(el, '@isComponentRoot', 'true')
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/weex/compiler/modules/recycle-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function preTransformNode (el: ASTElement, options: WeexCompilerOptions) {
currentRecycleList = el
}
if (shouldCompile(el, options)) {
preTransformVBind(el, options)
preTransformVBind(el)
preTransformVIf(el, options) // also v-else-if and v-else
preTransformVFor(el, options)
preTransformVOnce(el, options)
preTransformVOnce(el)
}
}

Expand All @@ -41,12 +41,12 @@ function postTransformNode (el: ASTElement, options: WeexCompilerOptions) {
// mark child component in parent template
postTransformComponent(el, options)
// mark root in child component template
postTransformComponentRoot(el, options)
postTransformComponentRoot(el)
// <text>: transform children text into value attr
if (el.tag === 'text') {
postTransformText(el, options)
postTransformText(el)
}
postTransformVOn(el, options)
postTransformVOn(el)
}
if (el === currentRecycleList) {
currentRecycleList = null
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/compiler/modules/recycle-list/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function genText (node: ASTNode) {
return JSON.stringify(value)
}

export function postTransformText (el: ASTElement, options: WeexCompilerOptions) {
export function postTransformText (el: ASTElement) {
// weex <text> can only contain text, so the parser
// always generates a single child.
if (el.children.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/compiler/modules/recycle-list/v-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function parseAttrName (name: string): string {
return camelize(name.replace(bindRE, ''))
}

export function preTransformVBind (el: ASTElement, options: WeexCompilerOptions) {
export function preTransformVBind (el: ASTElement) {
for (const attr in el.attrsMap) {
if (bindRE.test(attr)) {
const name: string = parseAttrName(attr)
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/compiler/modules/recycle-list/v-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function parseHandlerParams (handler: ASTElementHandler) {
}
}

export function postTransformVOn (el: ASTElement, options: WeexCompilerOptions) {
export function postTransformVOn (el: ASTElement) {
const events: ASTElementHandlers | void = el.events
if (!events) {
return
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/weex/compiler/modules/recycle-list/v-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function containVOnce (el: ASTElement): boolean {
return false
}

export function preTransformVOnce (el: ASTElement, options: WeexCompilerOptions) {
export function preTransformVOnce (el: ASTElement) {
if (containVOnce(el)) {
getAndRemoveAttr(el, 'v-once', true)
addRawAttr(el, '[[once]]', true)
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/weex/runtime/modules/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function enter (_, vnode) {
const stylesheet = vnode.context.$options.style || {}
const startState = stylesheet[startClass]
const transitionProperties = (stylesheet['@TRANSITION'] && stylesheet['@TRANSITION'][activeClass]) || {}
const endState = getEnterTargetState(el, stylesheet, startClass, toClass, activeClass, vnode.context)
const endState = getEnterTargetState(el, stylesheet, startClass, toClass, activeClass)
const needAnimation = Object.keys(endState).length > 0

const cb = el._enterCb = once(() => {
Expand Down Expand Up @@ -229,7 +229,7 @@ function leave (vnode, rm) {
}

// determine the target animation style for an entering transition.
function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass, vm) {
function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass) {
const targetState = {}
const startState = stylesheet[startClass]
const endState = stylesheet[endClass]
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/weex/util/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export const isUnaryTag = makeMap(
true
)

export function mustUseProp (tag: string, type: ?string, name: string): boolean {
export function mustUseProp (): boolean {
return false
}

export function getTagNamespace (tag?: string): string | void { }
export function getTagNamespace (): void { }

export function isUnknownElement (tag?: string): boolean {
export function isUnknownElement (): boolean {
return false
}

Expand Down
1 change: 1 addition & 0 deletions src/server/render-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class RenderContext {
if (isUndef(lastState)) {
return this.done()
}
/* eslint-disable no-case-declarations */
switch (lastState.type) {
case 'Element':
case 'Fragment':
Expand Down
2 changes: 1 addition & 1 deletion src/sfc/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function parseComponent (
}
}

function end (tag: string, start: number, end: number) {
function end (tag: string, start: number) {
if (depth === 1 && currentBlock) {
currentBlock.end = start
let text = deindent(content.slice(currentBlock.start, currentBlock.end))
Expand Down
4 changes: 4 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ export function toObject (arr: Array<any>): Object {
return res
}

/* eslint-disable no-unused-vars */

/**
* Perform no operation.
* Stubbing args to make Flow happy without leaving useless transpiled code
Expand All @@ -252,6 +254,8 @@ export function noop (a?: any, b?: any, c?: any) {}
*/
export const no = (a?: any, b?: any, c?: any) => false

/* eslint-enable no-unused-vars */

/**
* Return the same value.
*/
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/ssr/ssr-basic-renderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('SSR: basicRenderer', () => {
created () {
ssrContext = this.$ssrContext
}
}), (err, result) => {
}), (err) => {
expect(err).toBeNull()
expect(ssrContext).toBeUndefined()
done()
Expand Down
2 changes: 1 addition & 1 deletion test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ describe('SSR: renderToString', () => {
it('should catch template compilation error', done => {
renderToString(new Vue({
template: `<div></div><div></div>`
}), (err, res) => {
}), (err) => {
expect(err.toString()).toContain('Component template should contain exactly one root element')
done()
})
Expand Down
3 changes: 2 additions & 1 deletion test/unit/.eslintrc → test/unit/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"plugins": ["jasmine"],
"rules": {
"jasmine/no-focused-tests": 2
"jasmine/no-focused-tests": 2,
"no-unused-vars": 0
}
}
2 changes: 1 addition & 1 deletion test/unit/features/error-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const components = createErrorTestComponents()
describe('Error handling', () => {
// hooks that prevents the component from rendering, but should not
// break parent component
;[
[
['data', 'data()'],
['render', 'render'],
['beforeCreate', 'beforeCreate hook'],
Expand Down
2 changes: 1 addition & 1 deletion test/unit/modules/compiler/compiler-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('compile options', () => {
computed: {
valid () {
let ret = true
for (let i = 0; i > this.validators.length; i++) {
for (let i = 0; i < this.validators.length; i++) {
const { name } = this.validators[i]
if (!this.result[name]) {
ret = false
Expand Down
Loading

0 comments on commit 76fd45c

Please sign in to comment.