From 28ffe2157794b09d19b03f7e1ffac21d6eb74032 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Wed, 18 Mar 2020 13:57:12 +0800
Subject: [PATCH 01/14] feat: init commit
---
docs/rules/README.md | 1 +
.../new-line-between-multi-line-property.md | 51 +++++++++++++
lib/configs/no-layout-rules.js | 1 +
lib/configs/recommended.js | 1 +
lib/index.js | 1 +
.../new-line-between-multi-line-property.js | 56 ++++++++++++++
.../new-line-between-multi-line-property.js | 74 +++++++++++++++++++
7 files changed, 185 insertions(+)
create mode 100644 docs/rules/new-line-between-multi-line-property.md
create mode 100644 lib/rules/new-line-between-multi-line-property.js
create mode 100644 tests/lib/rules/new-line-between-multi-line-property.js
diff --git a/docs/rules/README.md b/docs/rules/README.md
index ab1f5b220..89e4b8823 100644
--- a/docs/rules/README.md
+++ b/docs/rules/README.md
@@ -118,6 +118,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| Rule ID | Description | |
|:--------|:------------|:---|
| [vue/attributes-order](./attributes-order.md) | enforce order of attributes | :wrench: |
+| [vue/new-line-between-multi-line-property](./new-line-between-multi-line-property.md) | enforce new lines between multi-line properties in Vue components | :wrench: |
| [vue/no-v-html](./no-v-html.md) | disallow use of v-html to prevent XSS attack | |
| [vue/order-in-components](./order-in-components.md) | enforce order of properties in components | :wrench: |
| [vue/this-in-template](./this-in-template.md) | disallow usage of `this` in template | |
diff --git a/docs/rules/new-line-between-multi-line-property.md b/docs/rules/new-line-between-multi-line-property.md
new file mode 100644
index 000000000..7f44cf73f
--- /dev/null
+++ b/docs/rules/new-line-between-multi-line-property.md
@@ -0,0 +1,51 @@
+---
+pageClass: rule-details
+sidebarDepth: 0
+title: vue/new-line-between-multi-line-property
+description: enforce new lines between multi-line properties in Vue components
+---
+# vue/new-line-between-multi-line-property
+> enforce new lines between multi-line properties in Vue components
+
+- :gear: This rule is included in `"plugin:vue/recommended"`.
+- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
+
+Please describe the origin of the rule here.
+
+
+## Rule Details
+
+This rule aims to...
+
+Examples of **incorrect** code for this rule:
+
+```js
+
+// fill me in
+
+```
+
+Examples of **correct** code for this rule:
+
+```js
+
+// fill me in
+
+```
+
+### Options
+
+If there are any options, describe them here. Otherwise, delete this section.
+
+## When Not To Use It
+
+Give a short description of when it would be appropriate to turn off this rule.
+
+## Further Reading
+
+If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
+
+## :mag: Implementation
+
+- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/new-line-between-multi-line-property.js)
+- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/new-line-between-multi-line-property.js)
diff --git a/lib/configs/no-layout-rules.js b/lib/configs/no-layout-rules.js
index e45c080bc..f82581251 100644
--- a/lib/configs/no-layout-rules.js
+++ b/lib/configs/no-layout-rules.js
@@ -22,6 +22,7 @@ module.exports = {
'vue/max-len': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/mustache-interpolation-spacing': 'off',
+ 'vue/new-line-between-multi-line-property': 'off',
'vue/no-multi-spaces': 'off',
'vue/no-spaces-around-equal-signs-in-attribute': 'off',
'vue/object-curly-spacing': 'off',
diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js
index 51bcc2e8c..29d899c09 100644
--- a/lib/configs/recommended.js
+++ b/lib/configs/recommended.js
@@ -7,6 +7,7 @@ module.exports = {
extends: require.resolve('./strongly-recommended'),
rules: {
'vue/attributes-order': 'warn',
+ 'vue/new-line-between-multi-line-property': 'warn',
'vue/no-v-html': 'warn',
'vue/order-in-components': 'warn',
'vue/this-in-template': 'warn'
diff --git a/lib/index.js b/lib/index.js
index 02e65ba96..98f2fae90 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -36,6 +36,7 @@ module.exports = {
'multiline-html-element-content-newline': require('./rules/multiline-html-element-content-newline'),
'mustache-interpolation-spacing': require('./rules/mustache-interpolation-spacing'),
'name-property-casing': require('./rules/name-property-casing'),
+ 'new-line-between-multi-line-property': require('./rules/new-line-between-multi-line-property'),
'no-async-in-computed-properties': require('./rules/no-async-in-computed-properties'),
'no-boolean-default': require('./rules/no-boolean-default'),
'no-confusing-v-for-v-if': require('./rules/no-confusing-v-for-v-if'),
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
new file mode 100644
index 000000000..6ec7b7200
--- /dev/null
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -0,0 +1,56 @@
+/**
+ * @fileoverview Enforce new lines between multi-line properties in Vue components.
+ * @author IWANABETHATGUY
+ */
+'use strict'
+
+// ------------------------------------------------------------------------------
+// Rule Definition
+// ------------------------------------------------------------------------------
+
+module.exports = {
+ meta: {
+ type: 'layout',
+ docs: {
+ description: 'enforce new lines between multi-line properties in Vue components',
+ category: 'recommended',
+ url: 'https://eslint.vuejs.org/rules/new-line-between-multi-line-property.html'
+ },
+ fixable: 'code', // or "code" or "whitespace"
+ schema: [
+ // fill in your schema
+ ]
+ },
+
+ create: function (context) {
+ // variables should be defined here
+
+ // ----------------------------------------------------------------------
+ // Helpers
+ // ----------------------------------------------------------------------
+
+ // any helper functions should go here or else delete this section
+
+ // ----------------------------------------------------------------------
+ // Public
+ // ----------------------------------------------------------------------
+ return {
+ ObjectExpression (node) {
+ const properties = node.properties
+ for (let i = 1; i < properties.length; i++) {
+ const cur = properties[i]
+ const pre = properties[i - 1]
+ if (pre.loc.end.line - pre.loc.start.line >= 1 && cur.loc.start.line - pre.loc.end.line <= 1) {
+ context.report({
+ node,
+ message: 'Enforce new lines between multi-line properties in Vue components.',
+ fix (fixer) {
+ return fixer.insertTextBefore(cur, '\n' + ' '.repeat(cur.loc.start.column))
+ }
+ })
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/lib/rules/new-line-between-multi-line-property.js b/tests/lib/rules/new-line-between-multi-line-property.js
new file mode 100644
index 000000000..39a48bf68
--- /dev/null
+++ b/tests/lib/rules/new-line-between-multi-line-property.js
@@ -0,0 +1,74 @@
+/**
+ * @fileoverview Enforce new lines between multi-line properties in Vue components.
+ * @author IWANABETHATGUY
+ */
+'use strict'
+
+// ------------------------------------------------------------------------------
+// Requirements
+// ------------------------------------------------------------------------------
+
+const rule = require('../../../lib/rules/new-line-between-multi-line-property')
+const RuleTester = require('eslint').RuleTester
+const ruleTester = new RuleTester({
+ parser: require.resolve('vue-eslint-parser'),
+ parserOptions: { ecmaVersion: 2015, sourceType: 'module' }
+})
+
+// ------------------------------------------------------------------------------
+// Tests
+// ------------------------------------------------------------------------------
+
+ruleTester.run('new-line-between-multi-line-property', rule, {
+ valid: [
+ // give me some code that won't trigger a warning
+ ],
+
+ invalid: [
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ 'Enforce new lines between multi-line properties in Vue components.'
+ ]
+ }
+ ]
+})
From dcce787d49daa958c613c86ffb2e53c38893e2e3 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Wed, 18 Mar 2020 17:29:13 +0800
Subject: [PATCH 02/14] feat: add test, make rule configurable
---
docs/rules/README.md | 2 +-
.../new-line-between-multi-line-property.md | 2 +-
lib/configs/recommended.js | 1 -
lib/configs/strongly-recommended.js | 1 +
.../new-line-between-multi-line-property.js | 43 +--
.../new-line-between-multi-line-property.js | 270 +++++++++++++++++-
6 files changed, 297 insertions(+), 22 deletions(-)
diff --git a/docs/rules/README.md b/docs/rules/README.md
index 89e4b8823..2f010a60b 100644
--- a/docs/rules/README.md
+++ b/docs/rules/README.md
@@ -95,6 +95,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| [vue/multiline-html-element-content-newline](./multiline-html-element-content-newline.md) | require a line break before and after the contents of a multiline element | :wrench: |
| [vue/mustache-interpolation-spacing](./mustache-interpolation-spacing.md) | enforce unified spacing in mustache interpolations | :wrench: |
| [vue/name-property-casing](./name-property-casing.md) | enforce specific casing for the name property in Vue components | :wrench: |
+| [vue/new-line-between-multi-line-property](./new-line-between-multi-line-property.md) | enforce new lines between multi-line properties in Vue components | :wrench: |
| [vue/no-multi-spaces](./no-multi-spaces.md) | disallow multiple spaces | :wrench: |
| [vue/no-spaces-around-equal-signs-in-attribute](./no-spaces-around-equal-signs-in-attribute.md) | disallow spaces around equal signs in attribute | :wrench: |
| [vue/no-template-shadow](./no-template-shadow.md) | disallow variable declarations from shadowing variables declared in the outer scope | |
@@ -118,7 +119,6 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| Rule ID | Description | |
|:--------|:------------|:---|
| [vue/attributes-order](./attributes-order.md) | enforce order of attributes | :wrench: |
-| [vue/new-line-between-multi-line-property](./new-line-between-multi-line-property.md) | enforce new lines between multi-line properties in Vue components | :wrench: |
| [vue/no-v-html](./no-v-html.md) | disallow use of v-html to prevent XSS attack | |
| [vue/order-in-components](./order-in-components.md) | enforce order of properties in components | :wrench: |
| [vue/this-in-template](./this-in-template.md) | disallow usage of `this` in template | |
diff --git a/docs/rules/new-line-between-multi-line-property.md b/docs/rules/new-line-between-multi-line-property.md
index 7f44cf73f..948974b4b 100644
--- a/docs/rules/new-line-between-multi-line-property.md
+++ b/docs/rules/new-line-between-multi-line-property.md
@@ -7,7 +7,7 @@ description: enforce new lines between multi-line properties in Vue components
# vue/new-line-between-multi-line-property
> enforce new lines between multi-line properties in Vue components
-- :gear: This rule is included in `"plugin:vue/recommended"`.
+- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
Please describe the origin of the rule here.
diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js
index 29d899c09..51bcc2e8c 100644
--- a/lib/configs/recommended.js
+++ b/lib/configs/recommended.js
@@ -7,7 +7,6 @@ module.exports = {
extends: require.resolve('./strongly-recommended'),
rules: {
'vue/attributes-order': 'warn',
- 'vue/new-line-between-multi-line-property': 'warn',
'vue/no-v-html': 'warn',
'vue/order-in-components': 'warn',
'vue/this-in-template': 'warn'
diff --git a/lib/configs/strongly-recommended.js b/lib/configs/strongly-recommended.js
index 7c32816ce..b7160cf2e 100644
--- a/lib/configs/strongly-recommended.js
+++ b/lib/configs/strongly-recommended.js
@@ -17,6 +17,7 @@ module.exports = {
'vue/multiline-html-element-content-newline': 'warn',
'vue/mustache-interpolation-spacing': 'warn',
'vue/name-property-casing': 'warn',
+ 'vue/new-line-between-multi-line-property': 'warn',
'vue/no-multi-spaces': 'warn',
'vue/no-spaces-around-equal-signs-in-attribute': 'warn',
'vue/no-template-shadow': 'warn',
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index 6ec7b7200..2d036e162 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -3,7 +3,7 @@
* @author IWANABETHATGUY
*/
'use strict'
-
+const _ = require('lodash')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
@@ -13,39 +13,48 @@ module.exports = {
type: 'layout',
docs: {
description: 'enforce new lines between multi-line properties in Vue components',
- category: 'recommended',
+ category: 'strongly-recommended',
url: 'https://eslint.vuejs.org/rules/new-line-between-multi-line-property.html'
},
fixable: 'code', // or "code" or "whitespace"
schema: [
- // fill in your schema
+ {
+ type: 'object',
+ properties: {
+ // number of line you want to insert after multi-line property
+ insertLine: {
+ type: 'number',
+ minimum: 1
+ },
+ minLineOfMultilineProperty: {
+ type: 'number',
+ minimum: 2
+ }
+ }
+ }
]
},
create: function (context) {
- // variables should be defined here
-
- // ----------------------------------------------------------------------
- // Helpers
- // ----------------------------------------------------------------------
-
- // any helper functions should go here or else delete this section
-
- // ----------------------------------------------------------------------
- // Public
- // ----------------------------------------------------------------------
+ const insertLine = _.get(context, ['options', '0', 'insertLine'], 1)
+ const minLineOfMultilineProperty = _.get(context, ['options', '0', 'minLineOfMultilineProperty'], 2)
return {
ObjectExpression (node) {
const properties = node.properties
for (let i = 1; i < properties.length; i++) {
const cur = properties[i]
const pre = properties[i - 1]
- if (pre.loc.end.line - pre.loc.start.line >= 1 && cur.loc.start.line - pre.loc.end.line <= 1) {
+ const lineCountOfPreProperty = pre.loc.end.line - pre.loc.start.line + 1
+ const lineCountBetweenCurAndPreProperty = cur.loc.start.line - pre.loc.end.line - 1
+ if (lineCountOfPreProperty >= minLineOfMultilineProperty && lineCountBetweenCurAndPreProperty < insertLine) {
context.report({
- node,
+ node: pre,
+ loc: pre.loc,
message: 'Enforce new lines between multi-line properties in Vue components.',
fix (fixer) {
- return fixer.insertTextBefore(cur, '\n' + ' '.repeat(cur.loc.start.column))
+ const firstPosofLine = cur.range[0] - cur.loc.start.column
+ // this action equal to insert number of line before node
+ return fixer.replaceTextRange([firstPosofLine, firstPosofLine], '\n'.repeat(insertLine - lineCountBetweenCurAndPreProperty))
}
})
}
diff --git a/tests/lib/rules/new-line-between-multi-line-property.js b/tests/lib/rules/new-line-between-multi-line-property.js
index 39a48bf68..fb2599414 100644
--- a/tests/lib/rules/new-line-between-multi-line-property.js
+++ b/tests/lib/rules/new-line-between-multi-line-property.js
@@ -21,7 +21,61 @@ const ruleTester = new RuleTester({
ruleTester.run('new-line-between-multi-line-property', rule, {
valid: [
- // give me some code that won't trigger a warning
+ // test good example of proposal https://github.com/vuejs/eslint-plugin-vue/issues/391
+ {
+ filename: 'test.vue',
+ code: `
+
+ `
+ }
],
invalid: [
@@ -59,7 +113,164 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
type: Boolean,
default: false
},
-
+
+ label: String,
+ icon: String
+ }
+ }
+
+ `,
+ errors: [
+ 'Enforce new lines between multi-line properties in Vue components.'
+ ]
+ },
+ // test bad example of proposal https://github.com/vuejs/eslint-plugin-vue/issues/391
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ 'Enforce new lines between multi-line properties in Vue components.',
+ 'Enforce new lines between multi-line properties in Vue components.'
+ ]
+ },
+ // test set insertLine to 2
+ {
+ filename: 'test.vue',
+ options: [{ insertLine: 2 }],
+ code: `
+
+ `,
+ output: `
+
`,
errors: [
+ 'Enforce new lines between multi-line properties in Vue components.',
'Enforce new lines between multi-line properties in Vue components.'
]
+
+ },
+ // test set insertLine and minLineOfMultilineProperty to 5
+ {
+ filename: 'test.vue',
+ options: [{ insertLine: 2, minLineOfMultilineProperty: 5 }],
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ {
+ message: 'Enforce new lines between multi-line properties in Vue components.',
+ line: 9
+ }
+ ]
+
}
]
})
From df5a3f24521b37b7e74d45eddae3b857095d8bc5 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Wed, 18 Mar 2020 18:00:46 +0800
Subject: [PATCH 03/14] =?UTF-8?q?docs:=20update=20doc=F0=9F=93=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../new-line-between-multi-line-property.md | 72 ++++++++++++++-----
.../new-line-between-multi-line-property.js | 39 ++++++----
.../new-line-between-multi-line-property.js | 4 +-
3 files changed, 85 insertions(+), 30 deletions(-)
diff --git a/docs/rules/new-line-between-multi-line-property.md b/docs/rules/new-line-between-multi-line-property.md
index 948974b4b..ee9fbc237 100644
--- a/docs/rules/new-line-between-multi-line-property.md
+++ b/docs/rules/new-line-between-multi-line-property.md
@@ -10,36 +10,76 @@ description: enforce new lines between multi-line properties in Vue components
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
-Please describe the origin of the rule here.
-
-
## Rule Details
-This rule aims to...
+This rule aims at enforcing new lines between multi-line properties in Vue components to help readability
Examples of **incorrect** code for this rule:
-```js
-
-// fill me in
-
+
+
+```vue
+
```
-Examples of **correct** code for this rule:
+
-```js
-// fill me in
+Examples of **correct** code for this rule:
+
+
+```vue
+
```
-### Options
-
-If there are any options, describe them here. Otherwise, delete this section.
+
-## When Not To Use It
+## Options
-Give a short description of when it would be appropriate to turn off this rule.
+If there are any options, describe them here. Otherwise, delete this section.
## Further Reading
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index 2d036e162..4ba715810 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -12,21 +12,23 @@ module.exports = {
meta: {
type: 'layout',
docs: {
- description: 'enforce new lines between multi-line properties in Vue components',
+ description:
+ 'enforce new lines between multi-line properties in Vue components',
category: 'strongly-recommended',
- url: 'https://eslint.vuejs.org/rules/new-line-between-multi-line-property.html'
+ url:
+ 'https://eslint.vuejs.org/rules/new-line-between-multi-line-property.html'
},
- fixable: 'code', // or "code" or "whitespace"
+ fixable: 'code', // or "code" or "whitespace"
schema: [
{
type: 'object',
properties: {
// number of line you want to insert after multi-line property
- insertLine: {
+ 'insert-line': {
type: 'number',
minimum: 1
},
- minLineOfMultilineProperty: {
+ 'min-line-of-multiline-property': {
type: 'number',
minimum: 2
}
@@ -36,25 +38,38 @@ module.exports = {
},
create: function (context) {
- const insertLine = _.get(context, ['options', '0', 'insertLine'], 1)
- const minLineOfMultilineProperty = _.get(context, ['options', '0', 'minLineOfMultilineProperty'], 2)
+ const insertLine = _.get(context, ['options', '0', 'insert-line'], 1)
+ const minLineOfMultilineProperty = _.get(
+ context,
+ ['options', '0', 'min-line-of-multiline-property'],
+ 2
+ )
return {
ObjectExpression (node) {
const properties = node.properties
for (let i = 1; i < properties.length; i++) {
const cur = properties[i]
const pre = properties[i - 1]
- const lineCountOfPreProperty = pre.loc.end.line - pre.loc.start.line + 1
- const lineCountBetweenCurAndPreProperty = cur.loc.start.line - pre.loc.end.line - 1
- if (lineCountOfPreProperty >= minLineOfMultilineProperty && lineCountBetweenCurAndPreProperty < insertLine) {
+ const lineCountOfPreProperty =
+ pre.loc.end.line - pre.loc.start.line + 1
+ const lineCountBetweenCurAndPreProperty =
+ cur.loc.start.line - pre.loc.end.line - 1
+ if (
+ lineCountOfPreProperty >= minLineOfMultilineProperty &&
+ lineCountBetweenCurAndPreProperty < insertLine
+ ) {
context.report({
node: pre,
loc: pre.loc,
- message: 'Enforce new lines between multi-line properties in Vue components.',
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
fix (fixer) {
const firstPosofLine = cur.range[0] - cur.loc.start.column
// this action equal to insert number of line before node
- return fixer.replaceTextRange([firstPosofLine, firstPosofLine], '\n'.repeat(insertLine - lineCountBetweenCurAndPreProperty))
+ return fixer.replaceTextRange(
+ [firstPosofLine, firstPosofLine],
+ '\n'.repeat(insertLine - lineCountBetweenCurAndPreProperty)
+ )
}
})
}
diff --git a/tests/lib/rules/new-line-between-multi-line-property.js b/tests/lib/rules/new-line-between-multi-line-property.js
index fb2599414..9da5a9176 100644
--- a/tests/lib/rules/new-line-between-multi-line-property.js
+++ b/tests/lib/rules/new-line-between-multi-line-property.js
@@ -235,7 +235,7 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
// test set insertLine to 2
{
filename: 'test.vue',
- options: [{ insertLine: 2 }],
+ options: [{ 'insert-line': 2 }],
code: `
+ `,
+ output: `
+
+ `,
+ errors: [
+ 'Enforce new lines between multi-line properties in Vue components.',
+ 'Enforce new lines between multi-line properties in Vue components.'
+ ]
}
]
})
From 154b00a05532c034c9619f7caf909e2b1fedb242 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Sun, 26 Jul 2020 23:34:47 +0800
Subject: [PATCH 07/14] =?UTF-8?q?test:=20=F0=9F=92=8D=20fix=20report=20whe?=
=?UTF-8?q?n=20multi-line-property=20in=20callExpression?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/rules/README.md | 2 +-
.../new-line-between-multi-line-property.md | 1 -
lib/configs/strongly-recommended.js | 1 -
.../new-line-between-multi-line-property.js | 12 ++++-
.../new-line-between-multi-line-property.js | 52 ++++++++++++++++---
5 files changed, 56 insertions(+), 12 deletions(-)
diff --git a/docs/rules/README.md b/docs/rules/README.md
index 48a458d95..defbb3d14 100644
--- a/docs/rules/README.md
+++ b/docs/rules/README.md
@@ -230,7 +230,6 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| [vue/max-attributes-per-line](./max-attributes-per-line.md) | enforce the maximum number of attributes per line | :wrench: |
| [vue/multiline-html-element-content-newline](./multiline-html-element-content-newline.md) | require a line break before and after the contents of a multiline element | :wrench: |
| [vue/mustache-interpolation-spacing](./mustache-interpolation-spacing.md) | enforce unified spacing in mustache interpolations | :wrench: |
-| [vue/new-line-between-multi-line-property](./new-line-between-multi-line-property.md) | enforce new lines between multi-line properties in Vue components | :wrench: |
| [vue/no-multi-spaces](./no-multi-spaces.md) | disallow multiple spaces | :wrench: |
| [vue/no-spaces-around-equal-signs-in-attribute](./no-spaces-around-equal-signs-in-attribute.md) | disallow spaces around equal signs in attribute | :wrench: |
| [vue/no-template-shadow](./no-template-shadow.md) | disallow variable declarations from shadowing variables declared in the outer scope | |
@@ -284,6 +283,7 @@ For example:
| [vue/html-comment-content-spacing](./html-comment-content-spacing.md) | enforce unified spacing in HTML comments | :wrench: |
| [vue/html-comment-indent](./html-comment-indent.md) | enforce consistent indentation in HTML comments | :wrench: |
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | |
+| [vue/new-line-between-multi-line-property](./new-line-between-multi-line-property.md) | enforce new lines between multi-line properties in Vue components | :wrench: |
| [vue/no-bare-strings-in-template](./no-bare-strings-in-template.md) | disallow the use of bare strings in `` | |
| [vue/no-boolean-default](./no-boolean-default.md) | disallow boolean defaults | :wrench: |
| [vue/no-duplicate-attr-inheritance](./no-duplicate-attr-inheritance.md) | enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"` | |
diff --git a/docs/rules/new-line-between-multi-line-property.md b/docs/rules/new-line-between-multi-line-property.md
index ee9fbc237..6046a62a5 100644
--- a/docs/rules/new-line-between-multi-line-property.md
+++ b/docs/rules/new-line-between-multi-line-property.md
@@ -7,7 +7,6 @@ description: enforce new lines between multi-line properties in Vue components
# vue/new-line-between-multi-line-property
> enforce new lines between multi-line properties in Vue components
-- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
## Rule Details
diff --git a/lib/configs/strongly-recommended.js b/lib/configs/strongly-recommended.js
index a9daeb5b0..0d3d41246 100644
--- a/lib/configs/strongly-recommended.js
+++ b/lib/configs/strongly-recommended.js
@@ -17,7 +17,6 @@ module.exports = {
'vue/max-attributes-per-line': 'warn',
'vue/multiline-html-element-content-newline': 'warn',
'vue/mustache-interpolation-spacing': 'warn',
- 'vue/new-line-between-multi-line-property': 'warn',
'vue/no-multi-spaces': 'warn',
'vue/no-spaces-around-equal-signs-in-attribute': 'warn',
'vue/no-template-shadow': 'warn',
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index 8e99771c2..da4324f3a 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -14,7 +14,7 @@ module.exports = {
docs: {
description:
'enforce new lines between multi-line properties in Vue components',
- categories: ['strongly-recommended'],
+ categories: undefined,
url:
'https://eslint.vuejs.org/rules/new-line-between-multi-line-property.html'
},
@@ -44,8 +44,18 @@ module.exports = {
['options', '0', 'min-line-of-multiline-property'],
2
)
+ let inCallExpression = false
return {
+ CallExpression() {
+ inCallExpression = true
+ },
+ 'CallExpression:exit'() {
+ inCallExpression = false
+ },
ObjectExpression(node) {
+ if (inCallExpression) {
+ return
+ }
const properties = node.properties
for (let i = 1; i < properties.length; i++) {
const cur = properties[i]
diff --git a/tests/lib/rules/new-line-between-multi-line-property.js b/tests/lib/rules/new-line-between-multi-line-property.js
index 9f391bb12..e4337d1c3 100644
--- a/tests/lib/rules/new-line-between-multi-line-property.js
+++ b/tests/lib/rules/new-line-between-multi-line-property.js
@@ -121,7 +121,11 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
`,
errors: [
- 'Enforce new lines between multi-line properties in Vue components.'
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 10
+ }
]
},
// test bad example of proposal https://github.com/vuejs/eslint-plugin-vue/issues/391
@@ -228,8 +232,16 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
`,
errors: [
- 'Enforce new lines between multi-line properties in Vue components.',
- 'Enforce new lines between multi-line properties in Vue components.'
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 5
+ },
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 19
+ }
]
},
// test set insertLine to 2
@@ -278,8 +290,16 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
`,
errors: [
- 'Enforce new lines between multi-line properties in Vue components.',
- 'Enforce new lines between multi-line properties in Vue components.'
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 5
+ },
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 10
+ }
]
},
// test set insertLine and minLineOfMultilineProperty to 5
@@ -331,7 +351,7 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
{
message:
'Enforce new lines between multi-line properties in Vue components.',
- line: 10
+ line: 9
}
]
},
@@ -371,13 +391,16 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
type: String,
required: true
},
+
focused: {
type: Boolean,
default: false
},
+
label: String,
icon: String
},
+
staticMethodFn() {
fn({
a: {
@@ -390,8 +413,21 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
`,
errors: [
- 'Enforce new lines between multi-line properties in Vue components.',
- 'Enforce new lines between multi-line properties in Vue components.'
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 4
+ },
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 5
+ },
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 9
+ }
]
}
]
From f948a95ad45d99931716cbdc29ff6bb544458523 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Tue, 4 Aug 2020 14:11:08 +0800
Subject: [PATCH 08/14] =?UTF-8?q?test:=20=F0=9F=92=8D=20fix=20test=20in=20?=
=?UTF-8?q?change=20request?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../new-line-between-multi-line-property.js | 43 +++++----
.../new-line-between-multi-line-property.js | 92 +++++--------------
2 files changed, 47 insertions(+), 88 deletions(-)
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index da4324f3a..a59049c74 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -3,11 +3,10 @@
* @author IWANABETHATGUY
*/
'use strict'
-const _ = require('lodash')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
-
+// @ts-ignore
module.exports = {
meta: {
type: 'layout',
@@ -18,17 +17,13 @@ module.exports = {
url:
'https://eslint.vuejs.org/rules/new-line-between-multi-line-property.html'
},
- fixable: 'code', // or "code" or "whitespace"
+ fixable: 'whitespace', // or "code" or "whitespace"
schema: [
{
type: 'object',
properties: {
// number of line you want to insert after multi-line property
- 'insert-line': {
- type: 'number',
- minimum: 1
- },
- 'min-line-of-multiline-property': {
+ minLineOfMultilineProperty: {
type: 'number',
minimum: 2
}
@@ -38,22 +33,31 @@ module.exports = {
},
create(context) {
- const insertLine = _.get(context, ['options', '0', 'insert-line'], 1)
- const minLineOfMultilineProperty = _.get(
- context,
- ['options', '0', 'min-line-of-multiline-property'],
- 2
- )
- let inCallExpression = false
+ const insertLine = 1
+
+ let minLineOfMultilineProperty = 2
+ if (
+ context.options &&
+ context.options[0] &&
+ context.options[0].minLineOfMultilineProperty
+ ) {
+ minLineOfMultilineProperty = context.options[0].minLineOfMultilineProperty
+ }
+ // @ts-ignore
+ const callStack = []
return {
- CallExpression() {
- inCallExpression = true
+ // @ts-ignore
+ CallExpression(node) {
+ callStack.push(node)
},
'CallExpression:exit'() {
- inCallExpression = false
+ // @ts-ignore
+ callStack.pop()
},
+ // @ts-ignore
ObjectExpression(node) {
- if (inCallExpression) {
+ // @ts-ignore
+ if (callStack.length) {
return
}
const properties = node.properties
@@ -73,6 +77,7 @@ module.exports = {
loc: pre.loc,
message:
'Enforce new lines between multi-line properties in Vue components.',
+ // @ts-ignore
fix(fixer) {
const firstPosofLine = cur.range[0] - cur.loc.start.column
// this action equal to insert number of line before node
diff --git a/tests/lib/rules/new-line-between-multi-line-property.js b/tests/lib/rules/new-line-between-multi-line-property.js
index e4337d1c3..73853b218 100644
--- a/tests/lib/rules/new-line-between-multi-line-property.js
+++ b/tests/lib/rules/new-line-between-multi-line-property.js
@@ -244,73 +244,15 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
}
]
},
- // test set insertLine to 2
- {
- filename: 'test.vue',
- options: [{ 'insert-line': 2 }],
- code: `
-
- `,
- output: `
-
- `,
- errors: [
- {
- message:
- 'Enforce new lines between multi-line properties in Vue components.',
- line: 5
- },
- {
- message:
- 'Enforce new lines between multi-line properties in Vue components.',
- line: 10
- }
- ]
- },
// test set insertLine and minLineOfMultilineProperty to 5
{
filename: 'test.vue',
- options: [{ 'insert-line': 2, 'min-line-of-multiline-property': 5 }],
+ options: [{ minLineOfMultilineProperty: 5 }],
code: `
`
+ },
+ // should valid if there are more than one line between
+ // multiline property
+ {
+ filename: 'test.vue',
+ code: `
+
+ `
}
],
@@ -295,6 +323,122 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
}
]
},
+ // test js comments
+ {
+ filename: 'test.vue',
+ options: [{ minLineOfMultilineProperty: 5 }],
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 9
+ }
+ ]
+ },
+ // test js doc
+ {
+ filename: 'test.vue',
+ options: [],
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 12
+ }
+ ]
+ },
{
filename: 'test.vue',
code: `
From 269a40eb26a6b0950ba65dc9e2149b5a1bb2a741 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Thu, 6 Aug 2020 14:30:22 +0800
Subject: [PATCH 10/14] =?UTF-8?q?test:=20=F0=9F=92=8D=20Vue.component()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../new-line-between-multi-line-property.js | 153 ++++++++++--------
.../new-line-between-multi-line-property.js | 92 +++++++++++
2 files changed, 174 insertions(+), 71 deletions(-)
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index af8e7908b..dd3099c18 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -3,6 +3,8 @@
* @author IWANABETHATGUY
*/
'use strict'
+
+const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
@@ -32,6 +34,7 @@ module.exports = {
]
},
+ /** @param {RuleContext} context */
create(context) {
const insertLine = 1
@@ -43,86 +46,94 @@ module.exports = {
) {
minLineOfMultilineProperty = context.options[0].minLineOfMultilineProperty
}
- // @ts-ignore
+
+ /** @type {any[]} */
const callStack = []
/** @type {any[]} */
let comments = []
- return {
- Program(node) {
- comments = node.comments
- },
- // @ts-ignore
- CallExpression(node) {
- callStack.push(node)
- },
- 'CallExpression:exit'() {
- // @ts-ignore
- callStack.pop()
- },
- // @ts-ignore
- ObjectExpression(node) {
- // @ts-ignore
- if (callStack.length) {
- return
+ return Object.assign(
+ {
+ /**
+ * @param {Program} node
+ */
+ Program(node) {
+ comments = node.comments
}
- const properties = node.properties
- for (let i = 1; i < properties.length; i++) {
- const cur = properties[i]
- const pre = properties[i - 1]
+ },
+ utils.defineVueVisitor(context, {
+ CallExpression(node) {
+ callStack.push(node)
+ },
+ 'CallExpression:exit'() {
+ callStack.pop()
+ },
- /** @type {any[]} */
- const leadingComments = []
- // getFirstLeadingComments is enough , after that break the loop.
- for (
- let commentsIndex = 0;
- commentsIndex < comments.length;
- commentsIndex++
- ) {
- const comment = comments[commentsIndex]
- if (
- comment.range[0] > pre.range[1] &&
- comment.range[1] < cur.range[0]
+ /**
+ * @param {ObjectExpression} node
+ */
+ ObjectExpression(node) {
+ if (callStack.length) {
+ return
+ }
+ const properties = node.properties
+ for (let i = 1; i < properties.length; i++) {
+ const cur = properties[i]
+ const pre = properties[i - 1]
+
+ /** @type {any[]} */
+ const leadingComments = []
+ // getFirstLeadingComments is enough , after that break the loop.
+ for (
+ let commentsIndex = 0;
+ commentsIndex < comments.length;
+ commentsIndex++
) {
- leadingComments.push(comments[commentsIndex])
- break
+ const comment = comments[commentsIndex]
+ if (
+ comment.range[0] > pre.range[1] &&
+ comment.range[1] < cur.range[0]
+ ) {
+ leadingComments.push(comments[commentsIndex])
+ break
+ }
}
- }
- const lineCountOfPreProperty =
- pre.loc.end.line - pre.loc.start.line + 1
- let curStartLine = cur.loc.start.line
- if (leadingComments.length) {
- curStartLine = leadingComments[0].loc.start.line
- }
- const lineCountBetweenCurAndPreProperty =
- curStartLine - pre.loc.end.line - 1
- if (
- lineCountOfPreProperty >= minLineOfMultilineProperty &&
- lineCountBetweenCurAndPreProperty < insertLine
- ) {
- context.report({
- node: pre,
- loc: pre.loc,
- message:
- 'Enforce new lines between multi-line properties in Vue components.',
- // @ts-ignore
- fix(fixer) {
- let firstPositionOfLine = cur.range[0] - cur.loc.start.column
- if (leadingComments.length) {
- const firstComment = leadingComments[0]
- firstPositionOfLine =
- firstComment.range[0] - firstComment.loc.start.column
+ const lineCountOfPreProperty =
+ pre.loc.end.line - pre.loc.start.line + 1
+ let curStartLine = cur.loc.start.line
+ if (leadingComments.length) {
+ curStartLine = leadingComments[0].loc.start.line
+ }
+ const lineCountBetweenCurAndPreProperty =
+ curStartLine - pre.loc.end.line - 1
+ if (
+ lineCountOfPreProperty >= minLineOfMultilineProperty &&
+ lineCountBetweenCurAndPreProperty < insertLine
+ ) {
+ context.report({
+ node: pre,
+ loc: pre.loc,
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ // @ts-ignore
+ fix(fixer) {
+ let firstPositionOfLine = cur.range[0] - cur.loc.start.column
+ if (leadingComments.length) {
+ const firstComment = leadingComments[0]
+ firstPositionOfLine =
+ firstComment.range[0] - firstComment.loc.start.column
+ }
+ // this action equal to insert number of line before node
+ return fixer.insertTextAfterRange(
+ [firstPositionOfLine, firstPositionOfLine],
+ '\n'
+ // to avoid conflict with no-multiple-empty-lines, only insert one newline
+ )
}
- // this action equal to insert number of line before node
- return fixer.replaceTextRange(
- [firstPositionOfLine, firstPositionOfLine],
- '\n'
- // to avoid conflict with no-multiple-empty-lines, only insert one newline
- )
- }
- })
+ })
+ }
}
}
- }
- }
+ })
+ )
}
}
diff --git a/tests/lib/rules/new-line-between-multi-line-property.js b/tests/lib/rules/new-line-between-multi-line-property.js
index 7bc6d0e91..740654f1a 100644
--- a/tests/lib/rules/new-line-between-multi-line-property.js
+++ b/tests/lib/rules/new-line-between-multi-line-property.js
@@ -527,6 +527,98 @@ ruleTester.run('new-line-between-multi-line-property', rule, {
line: 9
}
]
+ },
+ // test Vue.component()
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 4
+ },
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 5
+ },
+ {
+ message:
+ 'Enforce new lines between multi-line properties in Vue components.',
+ line: 10
+ }
+ ]
}
]
})
From 26e9d00a0f6dcf1b2f345272686b6d7ee20fad6e Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Thu, 6 Aug 2020 14:42:29 +0800
Subject: [PATCH 11/14] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20docs?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../new-line-between-multi-line-property.md | 21 +++++++++++--------
.../new-line-between-multi-line-property.js | 1 +
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/docs/rules/new-line-between-multi-line-property.md b/docs/rules/new-line-between-multi-line-property.md
index 6046a62a5..afa1856d8 100644
--- a/docs/rules/new-line-between-multi-line-property.md
+++ b/docs/rules/new-line-between-multi-line-property.md
@@ -9,7 +9,7 @@ description: enforce new lines between multi-line properties in Vue components
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
-## Rule Details
+## :book: Rule Details
This rule aims at enforcing new lines between multi-line properties in Vue components to help readability
@@ -76,14 +76,17 @@ export default {
-## Options
-
-If there are any options, describe them here. Otherwise, delete this section.
-
-## Further Reading
-
-If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
-
+## :wrench: Option
+```json
+{
+ "vue/new-line-between-multiline-property": ["error", {
+ "minLineOfMultilineProperty": 2
+ }]
+}
+```
+- `minLineOfMultilineProperty` ... `type: number`, Define the minimum number of rows for a multi-line property .`type:` number, `default:` 2 , `min:`: 2
+## :books: Further Reading
+Nothing here
## :mag: Implementation
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/new-line-between-multi-line-property.js)
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index dd3099c18..3f2873fd5 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -36,6 +36,7 @@ module.exports = {
/** @param {RuleContext} context */
create(context) {
+ // always insert one line
const insertLine = 1
let minLineOfMultilineProperty = 2
From 12a9aaafc04e386e61d65c3734d8ebcda409bed2 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Sat, 8 Aug 2020 16:03:31 +0800
Subject: [PATCH 12/14] =?UTF-8?q?fix:=20=F0=9F=90=9B=20using=20sourceCode?=
=?UTF-8?q?=20api?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/rules/new-line-between-multi-line-property.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index 3f2873fd5..74bf68f24 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -51,7 +51,7 @@ module.exports = {
/** @type {any[]} */
const callStack = []
/** @type {any[]} */
- let comments = []
+ let comments = context.getSourceCode().getAllComments();
return Object.assign(
{
/**
From aa7d47ad27ca5cfdf2dc3429714828ed8f0b2351 Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Sat, 8 Aug 2020 16:21:02 +0800
Subject: [PATCH 13/14] =?UTF-8?q?fix:=20=F0=9F=90=9B=20using=20getTokenBew?=
=?UTF-8?q?teen=20instead=20of=20getAlltoken?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../new-line-between-multi-line-property.js | 29 ++-----------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index 74bf68f24..3a14511e0 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -50,17 +50,8 @@ module.exports = {
/** @type {any[]} */
const callStack = []
- /** @type {any[]} */
- let comments = context.getSourceCode().getAllComments();
+ let sourceCode = context.getSourceCode();
return Object.assign(
- {
- /**
- * @param {Program} node
- */
- Program(node) {
- comments = node.comments
- }
- },
utils.defineVueVisitor(context, {
CallExpression(node) {
callStack.push(node)
@@ -81,23 +72,7 @@ module.exports = {
const cur = properties[i]
const pre = properties[i - 1]
- /** @type {any[]} */
- const leadingComments = []
- // getFirstLeadingComments is enough , after that break the loop.
- for (
- let commentsIndex = 0;
- commentsIndex < comments.length;
- commentsIndex++
- ) {
- const comment = comments[commentsIndex]
- if (
- comment.range[0] > pre.range[1] &&
- comment.range[1] < cur.range[0]
- ) {
- leadingComments.push(comments[commentsIndex])
- break
- }
- }
+ const leadingComments = sourceCode.getTokensBetween(pre, cur, {includeComments: true}).filter(token => ['Line', 'Block'].includes(token.type));
const lineCountOfPreProperty =
pre.loc.end.line - pre.loc.start.line + 1
let curStartLine = cur.loc.start.line
From b556320b990e19d41ee2d7fa81a078dd8976190a Mon Sep 17 00:00:00 2001
From: IWANABETHATGUY <974153916@qq.com>
Date: Sat, 8 Aug 2020 16:25:35 +0800
Subject: [PATCH 14/14] =?UTF-8?q?fix:=20=F0=9F=90=9B=20lint=20error?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/rules/new-line-between-multi-line-property.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/rules/new-line-between-multi-line-property.js b/lib/rules/new-line-between-multi-line-property.js
index 3a14511e0..cdea8ea02 100644
--- a/lib/rules/new-line-between-multi-line-property.js
+++ b/lib/rules/new-line-between-multi-line-property.js
@@ -50,7 +50,7 @@ module.exports = {
/** @type {any[]} */
const callStack = []
- let sourceCode = context.getSourceCode();
+ const sourceCode = context.getSourceCode()
return Object.assign(
utils.defineVueVisitor(context, {
CallExpression(node) {
@@ -72,7 +72,9 @@ module.exports = {
const cur = properties[i]
const pre = properties[i - 1]
- const leadingComments = sourceCode.getTokensBetween(pre, cur, {includeComments: true}).filter(token => ['Line', 'Block'].includes(token.type));
+ const leadingComments = sourceCode
+ .getTokensBetween(pre, cur, { includeComments: true })
+ .filter((token) => ['Line', 'Block'].includes(token.type))
const lineCountOfPreProperty =
pre.loc.end.line - pre.loc.start.line + 1
let curStartLine = cur.loc.start.line