Skip to content

Commit cc43821

Browse files
mysticateamichalsnik
authored andcommitted
[Fix] Crash with babel-eslint (#273)
* Fix: crash with babel-eslint * Chore: fix lint errors * Fix: upgrade eslint-plugin-vue-libs to 2.0.0 * fix for tests
1 parent 1ac12f5 commit cc43821

18 files changed

+117
-86
lines changed

circle.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ test:
1212
- nvm use 4 && npm test
1313
- nvm use 6 && npm test
1414
- nvm use 8 && npm test
15-
- nvm use 8 && npm i [email protected] --no-save && npm run -s test:base
15+
# Test for the minimum version we are supporting.
16+
- nvm use 8 && npm i [email protected] --no-save && $(npm bin)/mocha tests/lib/rules/*.js --reporter dot

eslint-internal-rules/consistent-docs-description.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function getPropertyFromObject (property, node) {
4343
*/
4444
function checkMetaDocsDescription (context, exportsNode) {
4545
if (exportsNode.type !== 'ObjectExpression') {
46-
// if the exported node is not the correct format, "internal-no-invalid-meta" will already report this.
46+
// if the exported node is not the correct format, "internal-no-invalid-meta" will already report this.
4747
return
4848
}
4949

@@ -52,7 +52,7 @@ function checkMetaDocsDescription (context, exportsNode) {
5252
const metaDocsDescription = metaDocs && getPropertyFromObject('description', metaDocs.value)
5353

5454
if (!metaDocsDescription) {
55-
// if there is no `meta.docs.description` property, "internal-no-invalid-meta" will already report this.
55+
// if there is no `meta.docs.description` property, "internal-no-invalid-meta" will already report this.
5656
return
5757
}
5858

lib/rules/name-property-casing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = {
5151
description: 'enforce specific casing for the name property in Vue components',
5252
category: 'strongly-recommended'
5353
},
54-
fixable: 'code', // or "code" or "whitespace"
54+
fixable: 'code', // or "code" or "whitespace"
5555
schema: [
5656
{
5757
enum: allowedCaseOptions

lib/rules/no-confusing-v-for-v-if.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const utils = require('../utils')
2323
function isUsingIterationVar (vIf) {
2424
const element = vIf.parent.parent
2525
return vIf.value.references.some(reference =>
26-
element.variables.some(variable =>
27-
variable.id.name === reference.id.name &&
28-
variable.kind === 'v-for'
29-
)
26+
element.variables.some(variable =>
27+
variable.id.name === reference.id.name &&
28+
variable.kind === 'v-for'
3029
)
30+
)
3131
}
3232

3333
/**

lib/rules/no-dupe-keys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
description: 'disallow duplication of field names',
5050
category: 'essential'
5151
},
52-
fixable: null, // or "code" or "whitespace"
52+
fixable: null, // or "code" or "whitespace"
5353
schema: [
5454
{
5555
type: 'object',

lib/rules/no-multi-spaces.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
description: 'disallow multiple spaces',
1515
category: 'strongly-recommended'
1616
},
17-
fixable: 'whitespace', // or "code" or "whitespace"
17+
fixable: 'whitespace', // or "code" or "whitespace"
1818
schema: []
1919
},
2020

lib/rules/require-default-prop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
description: 'require default value for props',
1717
category: 'strongly-recommended'
1818
},
19-
fixable: null, // or "code" or "whitespace"
19+
fixable: null, // or "code" or "whitespace"
2020
schema: []
2121
},
2222

lib/rules/require-prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = {
8383
description: 'require type definitions in props',
8484
category: 'strongly-recommended'
8585
},
86-
fixable: null, // or "code" or "whitespace"
86+
fixable: null, // or "code" or "whitespace"
8787
schema: [
8888
// fill in your schema
8989
]

lib/rules/require-render-return.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = {
4646
description: 'enforce render function to always return value',
4747
category: 'essential'
4848
},
49-
fixable: null, // or "code" or "whitespace"
49+
fixable: null, // or "code" or "whitespace"
5050
schema: []
5151
},
5252

lib/rules/return-in-computed-property.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = {
5050
description: 'enforce that a return statement is present in computed property',
5151
category: 'essential'
5252
},
53-
fixable: null, // or "code" or "whitespace"
53+
fixable: null, // or "code" or "whitespace"
5454
schema: [
5555
{
5656
type: 'object',

lib/rules/v-bind-style.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ function create (context) {
3434
node,
3535
loc: node.loc,
3636
message: shorthand
37-
? "Unexpected 'v-bind' before ':'."
38-
: "Expected 'v-bind' before ':'.",
37+
? "Unexpected 'v-bind' before ':'."
38+
: "Expected 'v-bind' before ':'.",
3939
fix: (fixer) => shorthand
40-
? fixer.removeRange([node.range[0], node.range[0] + 6])
41-
: fixer.insertTextBefore(node, 'v-bind')
40+
? fixer.removeRange([node.range[0], node.range[0] + 6])
41+
: fixer.insertTextBefore(node, 'v-bind')
4242
})
4343
}
4444
})

lib/rules/v-on-style.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ function create (context) {
3535
node,
3636
loc: node.loc,
3737
message: shorthand
38-
? "Expected '@' instead of 'v-on:'."
39-
: "Expected 'v-on:' instead of '@'.",
38+
? "Expected '@' instead of 'v-on:'."
39+
: "Expected 'v-on:' instead of '@'.",
4040
fix: (fixer) => shorthand
41-
? fixer.replaceTextRange([pos, pos + 5], '@')
42-
: fixer.replaceTextRange([pos, pos + 1], 'v-on:')
41+
? fixer.replaceTextRange([pos, pos + 5], '@')
42+
: fixer.replaceTextRange([pos, pos + 1], 'v-on:')
4343
})
4444
}
4545
})

lib/rules/valid-v-for.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ function isUsingIterationVar (vFor, vBindKey) {
2828
const references = vBindKey.value.references
2929
const variables = vFor.parent.parent.variables
3030
return references.some(reference =>
31-
variables.some(variable =>
32-
variable.id.name === reference.id.name &&
31+
variables.some(variable =>
32+
variable.id.name === reference.id.name &&
3333
variable.kind === 'v-for'
34-
)
3534
)
35+
)
3636
}
3737

3838
/**
@@ -48,11 +48,11 @@ function checkChildKey (context, vFor, child) {
4848
const childForRefs = childFor.value.references
4949
const variables = vFor.parent.parent.variables
5050
const usedInFor = childForRefs.some(cref =>
51-
variables.some(variable =>
52-
cref.id.name === variable.id.name &&
53-
variable.kind === 'v-for'
54-
)
51+
variables.some(variable =>
52+
cref.id.name === variable.id.name &&
53+
variable.kind === 'v-for'
5554
)
55+
)
5656
// if parent iterator is used, skip other checks
5757
// iterator usage will be checked later by child v-for
5858
if (usedInFor) {

lib/rules/valid-v-model.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ const VALID_MODIFIERS = new Set(['lazy', 'number', 'trim'])
2525
function isValidElement (node) {
2626
const name = node.name
2727
return (
28-
name === 'input' ||
29-
name === 'select' ||
30-
name === 'textarea' ||
31-
(
32-
name !== 'keep-alive' &&
33-
name !== 'slot' &&
34-
name !== 'transition' &&
35-
name !== 'transition-group' &&
36-
utils.isCustomComponent(node)
37-
)
28+
name === 'input' ||
29+
name === 'select' ||
30+
name === 'textarea' ||
31+
(
32+
name !== 'keep-alive' &&
33+
name !== 'slot' &&
34+
name !== 'transition' &&
35+
name !== 'transition-group' &&
36+
utils.isCustomComponent(node)
37+
)
3838
)
3939
}
4040

@@ -45,9 +45,9 @@ function isValidElement (node) {
4545
*/
4646
function isLhs (node) {
4747
return node != null && (
48-
node.type === 'Identifier' ||
49-
node.type === 'MemberExpression'
50-
)
48+
node.type === 'Identifier' ||
49+
node.type === 'MemberExpression'
50+
)
5151
}
5252

5353
/**

lib/utils/index.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
loc: { line: 1, column: 0 },
3636
message: 'Use the latest vue-eslint-parser. See also https://github.com/vuejs/eslint-plugin-vue#what-is-the-use-the-latest-vue-eslint-parser-error'
3737
})
38-
return
38+
return {}
3939
}
4040
return context.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor)
4141
},
@@ -85,13 +85,13 @@ module.exports = {
8585
hasAttribute (node, name, value) {
8686
assert(node && node.type === 'VElement')
8787
return node.startTag.attributes.some(a =>
88-
!a.directive &&
89-
a.key.name === name &&
90-
(
91-
value === undefined ||
92-
(a.value != null && a.value.value === value)
93-
)
94-
)
88+
!a.directive &&
89+
a.key.name === name &&
90+
(
91+
value === undefined ||
92+
(a.value != null && a.value.value === value)
93+
)
94+
)
9595
},
9696

9797
/**
@@ -104,10 +104,10 @@ module.exports = {
104104
hasDirective (node, name, argument) {
105105
assert(node && node.type === 'VElement')
106106
return node.startTag.attributes.some(a =>
107-
a.directive &&
108-
a.key.name === name &&
109-
(argument === undefined || a.key.argument === argument)
110-
)
107+
a.directive &&
108+
a.key.name === name &&
109+
(argument === undefined || a.key.argument === argument)
110+
)
111111
},
112112

113113
/**
@@ -118,8 +118,8 @@ module.exports = {
118118
hasAttributeValue (node) {
119119
assert(node && node.type === 'VAttribute')
120120
return (
121-
node.value != null &&
122-
(node.value.expression != null || node.value.syntaxError != null)
121+
node.value != null &&
122+
(node.value.expression != null || node.value.syntaxError != null)
123123
)
124124
},
125125

@@ -133,13 +133,13 @@ module.exports = {
133133
getAttribute (node, name, value) {
134134
assert(node && node.type === 'VElement')
135135
return node.startTag.attributes.find(a =>
136-
!a.directive &&
137-
a.key.name === name &&
138-
(
139-
value === undefined ||
140-
(a.value != null && a.value.value === value)
141-
)
142-
)
136+
!a.directive &&
137+
a.key.name === name &&
138+
(
139+
value === undefined ||
140+
(a.value != null && a.value.value === value)
141+
)
142+
)
143143
},
144144

145145
/**
@@ -152,10 +152,10 @@ module.exports = {
152152
getDirective (node, name, argument) {
153153
assert(node && node.type === 'VElement')
154154
return node.startTag.attributes.find(a =>
155-
a.directive &&
156-
a.key.name === name &&
157-
(argument === undefined || a.key.argument === argument)
158-
)
155+
a.directive &&
156+
a.key.name === name &&
157+
(argument === undefined || a.key.argument === argument)
158+
)
159159
},
160160

161161
/**
@@ -168,11 +168,11 @@ module.exports = {
168168

169169
const prev = this.prevSibling(node)
170170
return (
171-
prev != null &&
172-
prev.startTag.attributes.some(a =>
173-
a.directive &&
174-
(a.key.name === 'if' || a.key.name === 'else-if')
175-
)
171+
prev != null &&
172+
prev.startTag.attributes.some(a =>
173+
a.directive &&
174+
(a.key.name === 'if' || a.key.name === 'else-if')
175+
)
176176
)
177177
},
178178

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@
5050
"@types/node": "^4.2.16",
5151
"babel-eslint": "^7.2.3",
5252
"chai": "^4.1.0",
53-
"eslint": "^3.19.0",
53+
"eslint": "^4.12.1",
5454
"eslint-plugin-eslint-plugin": "^0.8.0",
55-
"eslint-plugin-vue-libs": "^1.2.0",
55+
"eslint-plugin-html": "^4.0.1",
56+
"eslint-plugin-vue-libs": "^2.0.0",
5657
"mocha": "^3.2.0",
5758
"nyc": "^11.1.0"
5859
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @author Toru Nagashima <https://github.com/mysticatea>
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
const Linter = require('eslint').Linter
8+
const rules = require('../..').rules
9+
10+
describe("Don't crash even if without vue-eslint-parser.", () => {
11+
const code = '<template><div>TEST</div></template>'
12+
13+
for (const key of Object.keys(rules)) {
14+
const ruleId = `vue/${key}`
15+
16+
it(ruleId, () => {
17+
const linter = new Linter()
18+
const config = {
19+
parser: 'babel-eslint',
20+
parserOptions: { ecmaVersion: 2015 },
21+
rules: {
22+
[ruleId]: 'error'
23+
}
24+
}
25+
linter.defineRule(ruleId, rules[key])
26+
linter.verifyAndFix(code, config, 'test.vue')
27+
})
28+
}
29+
})

tools/update-rules.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const deprecatedRules = rules
7979
let rulesTableContent = categories.map(category => `
8080
### ${categoryTitles[category]}
8181
${
82-
category === 'uncategorized' ? '' : `
82+
category === 'uncategorized' ? '' : `
8383
Enforce all the rules in this category, as well as all higher priority rules, with:
8484
8585
\`\`\` json
@@ -123,17 +123,17 @@ if (deprecatedRules.length) {
123123
| Rule ID | Replaced by |
124124
|:--------|:------------|
125125
${
126-
rules
127-
.filter(entry => entry[1].meta.deprecated)
128-
.map(entry => {
129-
const name = entry[0]
130-
const meta = entry[1].meta
131-
const link = `[${name}](./docs/rules/${name}.md)`
132-
const replacedBy = (meta.docs.replacedBy || []).map(id => `[${id}](./docs/rules/${id}.md)`).join(', ') || '(no replacement)'
133-
return `| ${link} | ${replacedBy} |`
134-
})
135-
.join('\n')
136-
}
126+
rules
127+
.filter(entry => entry[1].meta.deprecated)
128+
.map(entry => {
129+
const name = entry[0]
130+
const meta = entry[1].meta
131+
const link = `[${name}](./docs/rules/${name}.md)`
132+
const replacedBy = (meta.docs.replacedBy || []).map(id => `[${id}](./docs/rules/${id}.md)`).join(', ') || '(no replacement)'
133+
return `| ${link} | ${replacedBy} |`
134+
})
135+
.join('\n')
136+
}
137137
`
138138
}
139139

0 commit comments

Comments
 (0)