Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/eslint-plugin-vue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.0.1
Choose a base ref
...
head repository: vuejs/eslint-plugin-vue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.2
Choose a head ref
  • 7 commits
  • 8 files changed
  • 2 contributors

Commits on Nov 19, 2019

  1. Typescript doc for vue/html-indent (#989)

    akoidan authored and ota-meshi committed Nov 19, 2019
    Copy the full SHA
    e8f130c View commit details

Commits on Dec 26, 2019

  1. Fixed false positives inside the ternary operator in `no-async-in-com…

    …puted-properties` (#962)
    
    * Fixed false positives inside the ternary operator in `no-async-in-computed-properties`
    
    * Add testcase
    ota-meshi authored Dec 26, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b412783 View commit details
  2. Fixed an issue that caused an error when extra commas were included i…

    …n `require-prop-type-constructor` (#963)
    ota-meshi authored Dec 26, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2418da7 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    acb48eb View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4476263 View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    959298f View commit details
  6. version 6.0.2

    ota-meshi committed Dec 26, 2019
    Copy the full SHA
    2e75458 View commit details
1 change: 1 addition & 0 deletions docs/rules/script-indent.md
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ This rule only checks `.vue` files and does not interfere with other `.js` files

- [indent](https://eslint.org/docs/rules/indent)
- [vue/html-indent](./html-indent.md)
- [@typescript-eslint/indent](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md). The `vue/script-indent` rule does not understand TypeScript AST. Please use `@typescript-eslint/indent` rule instead of this one inside of `<script lang="ts"`

## :mag: Implementation

52 changes: 19 additions & 33 deletions lib/rules/no-async-in-computed-properties.js
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ module.exports = {

create (context) {
const forbiddenNodes = []
const allowedScopes = []
let scopeStack = { upper: null, body: null }

const expressionTypes = {
promise: 'asynchronous action',
@@ -87,65 +87,54 @@ module.exports = {
if (node.async) {
forbiddenNodes.push({
node: node,
type: 'async'
type: 'async',
targetBody: node.body
})
} else if (node.parent.type === 'ReturnStatement') {
allowedScopes.push(node)
}

scopeStack = { upper: scopeStack, body: node.body }
}

function onFunctionExit () {
scopeStack = scopeStack.upper
}
return Object.assign({},
{
FunctionDeclaration: onFunctionEnter,

FunctionExpression: onFunctionEnter,

ArrowFunctionExpression: onFunctionEnter,
':function': onFunctionEnter,
':function:exit': onFunctionExit,

NewExpression (node) {
if (node.callee.name === 'Promise') {
forbiddenNodes.push({
node: node,
type: 'new'
type: 'new',
targetBody: scopeStack.body
})
} else if (node.parent.type === 'ReturnStatement') {
allowedScopes.push(node)
}
},

CallExpression (node) {
if (isPromise(node)) {
forbiddenNodes.push({
node: node,
type: 'promise'
type: 'promise',
targetBody: scopeStack.body
})
} else if (isTimedFunction(node)) {
forbiddenNodes.push({
node: node,
type: 'timed'
type: 'timed',
targetBody: scopeStack.body
})
} else if (node.parent.type === 'ReturnStatement') {
allowedScopes.push(node)
}
},

AwaitExpression (node) {
forbiddenNodes.push({
node: node,
type: 'await'
type: 'await',
targetBody: scopeStack.body
})
},

'ReturnStatement' (node) {
if (
node.argument &&
(
node.argument.type === 'ObjectExpression' ||
node.argument.type === 'ArrayExpression'
)
) {
allowedScopes.push(node.argument)
}
}
},
utils.executeOnVue(context, (obj) => {
@@ -157,10 +146,7 @@ module.exports = {
cp.value &&
el.node.loc.start.line >= cp.value.loc.start.line &&
el.node.loc.end.line <= cp.value.loc.end.line &&
!allowedScopes.some(scope =>
scope.range[0] < el.node.range[0] &&
scope.range[1] > el.node.range[1]
)
el.targetBody === cp.value
) {
context.report({
node: el.node,
2 changes: 1 addition & 1 deletion lib/rules/no-multi-spaces.js
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ module.exports = {
if (context.parserServices.getTemplateBodyTokenStore == null) {
context.report({
loc: { line: 1, column: 0 },
message: 'Use the latest vue-eslint-parser. See also https://vuejs.github.io/eslint-plugin-vue/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
message: 'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
})
return
}
15 changes: 12 additions & 3 deletions lib/rules/require-prop-type-constructor.js
Original file line number Diff line number Diff line change
@@ -35,14 +35,23 @@ module.exports = {

create (context) {
const fix = node => fixer => {
let newText
if (node.type === 'Literal') {
return fixer.replaceText(node, node.value)
if (typeof node.value !== 'string') {
return undefined
}
newText = node.value
} else if (
node.type === 'TemplateLiteral' &&
node.expressions.length === 0 &&
node.quasis.length === 1
) {
return fixer.replaceText(node, node.quasis[0].value.cooked)
newText = node.quasis[0].value.cooked
} else {
return undefined
}
if (newText) {
return fixer.replaceText(node, newText)
}
}

@@ -58,7 +67,7 @@ module.exports = {
})
} else if (node.type === 'ArrayExpression') {
node.elements
.filter(prop => isForbiddenType(prop))
.filter(prop => prop && isForbiddenType(prop))
.forEach(prop => context.report({
node: prop,
message,
5 changes: 3 additions & 2 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ module.exports = {
if (context.parserServices.defineTemplateBodyVisitor == null) {
context.report({
loc: { line: 1, column: 0 },
message: 'Use the latest vue-eslint-parser. See also https://vuejs.github.io/eslint-plugin-vue/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error'
message: 'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error'
})
return {}
}
@@ -115,7 +115,7 @@ module.exports = {
meta: Object.assign({}, coreRule.meta, {
docs: Object.assign({}, coreRule.meta.docs, {
category,
url: `https://vuejs.github.io/eslint-plugin-vue/rules/${path.basename(coreRule.meta.docs.url || '')}.html`
url: `https://eslint.vuejs.org/rules/${path.basename(coreRule.meta.docs.url || '')}.html`
})
})
}
@@ -453,6 +453,7 @@ module.exports = {
})
} else {
props = propsNode.value.elements
.filter(prop => prop)
.map(prop => {
const key = prop.type === 'Literal' && typeof prop.value === 'string' ? prop : null
return { key, value: null, node: prop, propName: key != null ? prop.value : null }
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-vue",
"version": "6.0.1",
"version": "6.0.2",
"description": "Official ESLint plugin for Vue.js",
"main": "lib/index.js",
"scripts": {
@@ -56,8 +56,9 @@
"chai": "^4.1.0",
"eslint": "^6.0.0",
"eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-vue-libs": "^4.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-vue": "file:.",
"eslint-plugin-vue-libs": "^4.0.0",
"eslint4b": "^6.6.0",
"lodash": "^4.17.4",
"mocha": "^5.2.0",
43 changes: 43 additions & 0 deletions tests/lib/rules/no-async-in-computed-properties.js
Original file line number Diff line number Diff line change
@@ -181,6 +181,49 @@ ruleTester.run('no-async-in-computed-properties', rule, {
}
`,
parserOptions
},
{
filename: 'test.vue',
code: `
export default {
computed: {
foo() {
return this.bar
? {
baz:() => Promise.resolve(1)
}
: {}
}
}
}
`,
parserOptions
},
{
filename: 'test.vue',
code: `
export default {
computed: {
foo() {
return this.bar ? () => Promise.resolve(1) : null
}
}
}
`,
parserOptions
},
{
filename: 'test.vue',
code: `
export default {
computed: {
foo() {
return this.bar ? async () => 1 : null
}
}
}
`,
parserOptions
}
],

Loading