Skip to content

[Fix] Crash with babel-eslint #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ test:
- nvm use 4 && npm test
- nvm use 6 && npm test
- nvm use 8 && npm test
- nvm use 8 && npm i [email protected] --no-save && npm run -s test:base
# Test for the minimum version we are supporting.
- nvm use 8 && npm i [email protected] --no-save && $(npm bin)/mocha tests/lib/rules/*.js --reporter dot
4 changes: 2 additions & 2 deletions eslint-internal-rules/consistent-docs-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getPropertyFromObject (property, node) {
*/
function checkMetaDocsDescription (context, exportsNode) {
if (exportsNode.type !== 'ObjectExpression') {
// if the exported node is not the correct format, "internal-no-invalid-meta" will already report this.
// if the exported node is not the correct format, "internal-no-invalid-meta" will already report this.
return
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/name-property-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
description: 'enforce specific casing for the name property in Vue components',
category: 'strongly-recommended'
},
fixable: 'code', // or "code" or "whitespace"
fixable: 'code', // or "code" or "whitespace"
schema: [
{
enum: allowedCaseOptions
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-confusing-v-for-v-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const utils = require('../utils')
function isUsingIterationVar (vIf) {
const element = vIf.parent.parent
return vIf.value.references.some(reference =>
element.variables.some(variable =>
variable.id.name === reference.id.name &&
variable.kind === 'v-for'
)
element.variables.some(variable =>
variable.id.name === reference.id.name &&
variable.kind === 'v-for'
)
)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
description: 'disallow duplication of field names',
category: 'essential'
},
fixable: null, // or "code" or "whitespace"
fixable: null, // or "code" or "whitespace"
schema: [
{
type: 'object',
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-multi-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
description: 'disallow multiple spaces',
category: 'strongly-recommended'
},
fixable: 'whitespace', // or "code" or "whitespace"
fixable: 'whitespace', // or "code" or "whitespace"
schema: []
},

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
description: 'require default value for props',
category: 'strongly-recommended'
},
fixable: null, // or "code" or "whitespace"
fixable: null, // or "code" or "whitespace"
schema: []
},

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = {
description: 'require type definitions in props',
category: 'strongly-recommended'
},
fixable: null, // or "code" or "whitespace"
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-render-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
description: 'enforce render function to always return value',
category: 'essential'
},
fixable: null, // or "code" or "whitespace"
fixable: null, // or "code" or "whitespace"
schema: []
},

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/return-in-computed-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
description: 'enforce that a return statement is present in computed property',
category: 'essential'
},
fixable: null, // or "code" or "whitespace"
fixable: null, // or "code" or "whitespace"
schema: [
{
type: 'object',
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/v-bind-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ function create (context) {
node,
loc: node.loc,
message: shorthand
? "Unexpected 'v-bind' before ':'."
: "Expected 'v-bind' before ':'.",
? "Unexpected 'v-bind' before ':'."
: "Expected 'v-bind' before ':'.",
fix: (fixer) => shorthand
? fixer.removeRange([node.range[0], node.range[0] + 6])
: fixer.insertTextBefore(node, 'v-bind')
? fixer.removeRange([node.range[0], node.range[0] + 6])
: fixer.insertTextBefore(node, 'v-bind')
})
}
})
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/v-on-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ function create (context) {
node,
loc: node.loc,
message: shorthand
? "Expected '@' instead of 'v-on:'."
: "Expected 'v-on:' instead of '@'.",
? "Expected '@' instead of 'v-on:'."
: "Expected 'v-on:' instead of '@'.",
fix: (fixer) => shorthand
? fixer.replaceTextRange([pos, pos + 5], '@')
: fixer.replaceTextRange([pos, pos + 1], 'v-on:')
? fixer.replaceTextRange([pos, pos + 5], '@')
: fixer.replaceTextRange([pos, pos + 1], 'v-on:')
})
}
})
Expand Down
14 changes: 7 additions & 7 deletions lib/rules/valid-v-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ function isUsingIterationVar (vFor, vBindKey) {
const references = vBindKey.value.references
const variables = vFor.parent.parent.variables
return references.some(reference =>
variables.some(variable =>
variable.id.name === reference.id.name &&
variables.some(variable =>
variable.id.name === reference.id.name &&
variable.kind === 'v-for'
)
)
)
}

/**
Expand All @@ -48,11 +48,11 @@ function checkChildKey (context, vFor, child) {
const childForRefs = childFor.value.references
const variables = vFor.parent.parent.variables
const usedInFor = childForRefs.some(cref =>
variables.some(variable =>
cref.id.name === variable.id.name &&
variable.kind === 'v-for'
)
variables.some(variable =>
cref.id.name === variable.id.name &&
variable.kind === 'v-for'
)
)
// if parent iterator is used, skip other checks
// iterator usage will be checked later by child v-for
if (usedInFor) {
Expand Down
26 changes: 13 additions & 13 deletions lib/rules/valid-v-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ const VALID_MODIFIERS = new Set(['lazy', 'number', 'trim'])
function isValidElement (node) {
const name = node.name
return (
name === 'input' ||
name === 'select' ||
name === 'textarea' ||
(
name !== 'keep-alive' &&
name !== 'slot' &&
name !== 'transition' &&
name !== 'transition-group' &&
utils.isCustomComponent(node)
)
name === 'input' ||
name === 'select' ||
name === 'textarea' ||
(
name !== 'keep-alive' &&
name !== 'slot' &&
name !== 'transition' &&
name !== 'transition-group' &&
utils.isCustomComponent(node)
)
)
}

Expand All @@ -45,9 +45,9 @@ function isValidElement (node) {
*/
function isLhs (node) {
return node != null && (
node.type === 'Identifier' ||
node.type === 'MemberExpression'
)
node.type === 'Identifier' ||
node.type === 'MemberExpression'
)
}

/**
Expand Down
60 changes: 30 additions & 30 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
loc: { line: 1, column: 0 },
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'
})
return
return {}
}
return context.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor)
},
Expand Down Expand Up @@ -85,13 +85,13 @@ module.exports = {
hasAttribute (node, name, value) {
assert(node && node.type === 'VElement')
return node.startTag.attributes.some(a =>
!a.directive &&
a.key.name === name &&
(
value === undefined ||
(a.value != null && a.value.value === value)
)
)
!a.directive &&
a.key.name === name &&
(
value === undefined ||
(a.value != null && a.value.value === value)
)
)
},

/**
Expand All @@ -104,10 +104,10 @@ module.exports = {
hasDirective (node, name, argument) {
assert(node && node.type === 'VElement')
return node.startTag.attributes.some(a =>
a.directive &&
a.key.name === name &&
(argument === undefined || a.key.argument === argument)
)
a.directive &&
a.key.name === name &&
(argument === undefined || a.key.argument === argument)
)
},

/**
Expand All @@ -118,8 +118,8 @@ module.exports = {
hasAttributeValue (node) {
assert(node && node.type === 'VAttribute')
return (
node.value != null &&
(node.value.expression != null || node.value.syntaxError != null)
node.value != null &&
(node.value.expression != null || node.value.syntaxError != null)
)
},

Expand All @@ -133,13 +133,13 @@ module.exports = {
getAttribute (node, name, value) {
assert(node && node.type === 'VElement')
return node.startTag.attributes.find(a =>
!a.directive &&
a.key.name === name &&
(
value === undefined ||
(a.value != null && a.value.value === value)
)
)
!a.directive &&
a.key.name === name &&
(
value === undefined ||
(a.value != null && a.value.value === value)
)
)
},

/**
Expand All @@ -152,10 +152,10 @@ module.exports = {
getDirective (node, name, argument) {
assert(node && node.type === 'VElement')
return node.startTag.attributes.find(a =>
a.directive &&
a.key.name === name &&
(argument === undefined || a.key.argument === argument)
)
a.directive &&
a.key.name === name &&
(argument === undefined || a.key.argument === argument)
)
},

/**
Expand All @@ -168,11 +168,11 @@ module.exports = {

const prev = this.prevSibling(node)
return (
prev != null &&
prev.startTag.attributes.some(a =>
a.directive &&
(a.key.name === 'if' || a.key.name === 'else-if')
)
prev != null &&
prev.startTag.attributes.some(a =>
a.directive &&
(a.key.name === 'if' || a.key.name === 'else-if')
)
)
},

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
"@types/node": "^4.2.16",
"babel-eslint": "^7.2.3",
"chai": "^4.1.0",
"eslint": "^3.19.0",
"eslint": "^4.12.1",
"eslint-plugin-eslint-plugin": "^0.8.0",
"eslint-plugin-vue-libs": "^1.2.0",
"eslint-plugin-html": "^4.0.1",
"eslint-plugin-vue-libs": "^2.0.0",
"mocha": "^3.2.0",
"nyc": "^11.1.0"
}
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/rules-without-vue-eslint-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
'use strict'

const Linter = require('eslint').Linter
const rules = require('../..').rules

describe("Don't crash even if without vue-eslint-parser.", () => {
const code = '<template><div>TEST</div></template>'

for (const key of Object.keys(rules)) {
const ruleId = `vue/${key}`

it(ruleId, () => {
const linter = new Linter()
const config = {
parser: 'babel-eslint',
parserOptions: { ecmaVersion: 2015 },
rules: {
[ruleId]: 'error'
}
}
linter.defineRule(ruleId, rules[key])
linter.verifyAndFix(code, config, 'test.vue')
})
}
})
24 changes: 12 additions & 12 deletions tools/update-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const deprecatedRules = rules
let rulesTableContent = categories.map(category => `
### ${categoryTitles[category]}
${
category === 'uncategorized' ? '' : `
category === 'uncategorized' ? '' : `
Enforce all the rules in this category, as well as all higher priority rules, with:

\`\`\` json
Expand Down Expand Up @@ -123,17 +123,17 @@ if (deprecatedRules.length) {
| Rule ID | Replaced by |
|:--------|:------------|
${
rules
.filter(entry => entry[1].meta.deprecated)
.map(entry => {
const name = entry[0]
const meta = entry[1].meta
const link = `[${name}](./docs/rules/${name}.md)`
const replacedBy = (meta.docs.replacedBy || []).map(id => `[${id}](./docs/rules/${id}.md)`).join(', ') || '(no replacement)'
return `| ${link} | ${replacedBy} |`
})
.join('\n')
}
rules
.filter(entry => entry[1].meta.deprecated)
.map(entry => {
const name = entry[0]
const meta = entry[1].meta
const link = `[${name}](./docs/rules/${name}.md)`
const replacedBy = (meta.docs.replacedBy || []).map(id => `[${id}](./docs/rules/${id}.md)`).join(', ') || '(no replacement)'
return `| ${link} | ${replacedBy} |`
})
.join('\n')
}
`
}

Expand Down