eslint-plugin-mpx 0.0.20 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/lib/configs/base.js +2 -1
- package/lib/rules/html-end-tags.js +1 -1
- package/lib/rules/jsx-uses-vars.js +1 -1
- package/lib/rules/no-arrow-functions-in-watch.js +1 -1
- package/lib/rules/no-async-in-computed-properties.js +1 -1
- package/lib/rules/no-dupe-keys.js +2 -2
- package/lib/rules/no-dupe-wx-elif.js +7 -2
- package/lib/rules/no-duplicate-attributes.js +6 -16
- package/lib/rules/no-reserved-keys.js +2 -2
- package/lib/rules/no-side-effects-in-computed-properties.js +1 -1
- package/lib/rules/no-template-shadow.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/return-in-computed-property.js +1 -1
- package/lib/rules/valid-v-text.js +1 -1
- package/lib/rules/valid-wx-elif.js +1 -1
- package/lib/rules/valid-wx-else.js +1 -1
- package/lib/rules/valid-wx-for.js +1 -1
- package/lib/rules/valid-wx-if.js +2 -2
- package/lib/rules/valid-wx-model.js +1 -1
- package/lib/utils/index.js +5 -6
- package/lib/utils/vue-reserved.json +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,6 +16,9 @@ Next, install `eslint-plugin-mpx`:
|
|
|
16
16
|
$ npm install eslint-plugin-mpx --save-dev
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## Docs
|
|
20
|
+
|
|
21
|
+
https://mpx-ecology.github.io/eslint-plugin-mpx/
|
|
19
22
|
|
|
20
23
|
## Usage
|
|
21
24
|
|
|
@@ -23,8 +26,8 @@ Add `mpx` to the plugins section of your `.eslintrc` configuration file. You can
|
|
|
23
26
|
|
|
24
27
|
```json
|
|
25
28
|
{
|
|
26
|
-
"
|
|
27
|
-
|
|
29
|
+
"extends": [
|
|
30
|
+
"plugin:mpx/mpx-essential"
|
|
28
31
|
]
|
|
29
32
|
}
|
|
30
33
|
```
|
package/lib/configs/base.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'suggestion',
|
|
21
21
|
docs: {
|
|
22
22
|
description: 'enforce end tag style',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['mpx-essential'],
|
|
24
24
|
url: 'https://eslint.vuejs.org/rules/html-end-tags.html'
|
|
25
25
|
},
|
|
26
26
|
fixable: 'code',
|
|
@@ -39,7 +39,7 @@ module.exports = {
|
|
|
39
39
|
type: 'problem',
|
|
40
40
|
docs: {
|
|
41
41
|
description: 'prevent variables used in JSX to be marked as unused', // eslint-disable-line consistent-docs-description
|
|
42
|
-
categories: ['base'],
|
|
42
|
+
// categories: ['base'],
|
|
43
43
|
url: 'https://eslint.vuejs.org/rules/jsx-uses-vars.html'
|
|
44
44
|
},
|
|
45
45
|
schema: []
|
|
@@ -10,7 +10,7 @@ module.exports = {
|
|
|
10
10
|
type: 'problem',
|
|
11
11
|
docs: {
|
|
12
12
|
description: 'disallow using arrow functions to define watcher',
|
|
13
|
-
categories: ['
|
|
13
|
+
categories: ['mpx-essential'],
|
|
14
14
|
url: 'https://eslint.vuejs.org/rules/no-arrow-functions-in-watch.html'
|
|
15
15
|
},
|
|
16
16
|
fixable: null,
|
|
@@ -69,7 +69,7 @@ module.exports = {
|
|
|
69
69
|
type: 'problem',
|
|
70
70
|
docs: {
|
|
71
71
|
description: 'disallow asynchronous actions in computed properties',
|
|
72
|
-
categories: ['
|
|
72
|
+
categories: ['mpx-essential'],
|
|
73
73
|
url: 'https://eslint.vuejs.org/rules/no-async-in-computed-properties.html'
|
|
74
74
|
},
|
|
75
75
|
fixable: null,
|
|
@@ -14,14 +14,14 @@ const utils = require('../utils')
|
|
|
14
14
|
// Rule Definition
|
|
15
15
|
// ------------------------------------------------------------------------------
|
|
16
16
|
/** @type {GroupName[]} */
|
|
17
|
-
const GROUP_NAMES = ['
|
|
17
|
+
const GROUP_NAMES = ['properties', 'computed', 'data', 'methods']
|
|
18
18
|
|
|
19
19
|
module.exports = {
|
|
20
20
|
meta: {
|
|
21
21
|
type: 'problem',
|
|
22
22
|
docs: {
|
|
23
23
|
description: 'disallow duplication of field names',
|
|
24
|
-
categories: ['
|
|
24
|
+
categories: ['mpx-essential'],
|
|
25
25
|
url: 'https://eslint.vuejs.org/rules/no-dupe-keys.html'
|
|
26
26
|
},
|
|
27
27
|
fixable: null, // or "code" or "whitespace"
|
|
@@ -139,10 +139,15 @@ module.exports = {
|
|
|
139
139
|
operandsB.operands.some((operandB) => equal(operandA, operandB))
|
|
140
140
|
)
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
const sourceCode = context.getSourceCode()
|
|
143
143
|
return utils.defineTemplateBodyVisitor(context, {
|
|
144
144
|
"VAttribute[directive=true][key.name.name='elif']"(node) {
|
|
145
|
-
|
|
145
|
+
const text = sourceCode.getText(node).slice(-3)
|
|
146
|
+
if (
|
|
147
|
+
!node.value ||
|
|
148
|
+
!node.value.expression ||
|
|
149
|
+
!['}}"', "}}'"].includes(text)
|
|
150
|
+
) {
|
|
146
151
|
return
|
|
147
152
|
}
|
|
148
153
|
const test = node.value.expression
|
|
@@ -24,11 +24,12 @@ function getName(attribute) {
|
|
|
24
24
|
if (!attribute.directive) {
|
|
25
25
|
return attribute.key.name
|
|
26
26
|
}
|
|
27
|
-
if (attribute.key.name.name
|
|
27
|
+
if (attribute.key.name.name.startsWith('bind')) {
|
|
28
28
|
return (
|
|
29
29
|
(attribute.key.argument &&
|
|
30
30
|
attribute.key.argument.type === 'VIdentifier' &&
|
|
31
|
-
attribute.key.argument.name) ||
|
|
31
|
+
attribute.key.name.name + attribute.key.argument.name) ||
|
|
32
|
+
attribute.key.name.name ||
|
|
32
33
|
null
|
|
33
34
|
)
|
|
34
35
|
}
|
|
@@ -44,7 +45,7 @@ module.exports = {
|
|
|
44
45
|
type: 'problem',
|
|
45
46
|
docs: {
|
|
46
47
|
description: 'disallow duplication of attributes',
|
|
47
|
-
categories: ['
|
|
48
|
+
categories: ['mpx-essential'],
|
|
48
49
|
url: 'https://eslint.vuejs.org/rules/no-duplicate-attributes.html'
|
|
49
50
|
},
|
|
50
51
|
fixable: null,
|
|
@@ -65,10 +66,6 @@ module.exports = {
|
|
|
65
66
|
},
|
|
66
67
|
/** @param {RuleContext} context */
|
|
67
68
|
create(context) {
|
|
68
|
-
const options = context.options[0] || {}
|
|
69
|
-
const allowCoexistStyle = options.allowCoexistStyle !== false
|
|
70
|
-
const allowCoexistClass = options.allowCoexistClass !== false
|
|
71
|
-
|
|
72
69
|
/** @type {Set<string>} */
|
|
73
70
|
const directiveNames = new Set()
|
|
74
71
|
/** @type {Set<string>} */
|
|
@@ -76,15 +73,8 @@ module.exports = {
|
|
|
76
73
|
|
|
77
74
|
/**
|
|
78
75
|
* @param {string} name
|
|
79
|
-
* @param {boolean} isDirective
|
|
80
76
|
*/
|
|
81
|
-
function isDuplicate(name
|
|
82
|
-
if (
|
|
83
|
-
(allowCoexistStyle && name === 'style') ||
|
|
84
|
-
(allowCoexistClass && name === 'class')
|
|
85
|
-
) {
|
|
86
|
-
return isDirective ? directiveNames.has(name) : attributeNames.has(name)
|
|
87
|
-
}
|
|
77
|
+
function isDuplicate(name) {
|
|
88
78
|
return directiveNames.has(name) || attributeNames.has(name)
|
|
89
79
|
}
|
|
90
80
|
|
|
@@ -99,7 +89,7 @@ module.exports = {
|
|
|
99
89
|
return
|
|
100
90
|
}
|
|
101
91
|
|
|
102
|
-
if (isDuplicate(name
|
|
92
|
+
if (isDuplicate(name)) {
|
|
103
93
|
context.report({
|
|
104
94
|
node,
|
|
105
95
|
loc: node.loc,
|
|
@@ -16,14 +16,14 @@ const utils = require('../utils')
|
|
|
16
16
|
|
|
17
17
|
const RESERVED_KEYS = require('../utils/vue-reserved.json')
|
|
18
18
|
/** @type {GroupName[]} */
|
|
19
|
-
const GROUP_NAMES = ['properties', 'computed', 'data', 'methods'
|
|
19
|
+
const GROUP_NAMES = ['properties', 'computed', 'data', 'methods']
|
|
20
20
|
|
|
21
21
|
module.exports = {
|
|
22
22
|
meta: {
|
|
23
23
|
type: 'suggestion',
|
|
24
24
|
docs: {
|
|
25
25
|
description: 'disallow overwriting reserved keys',
|
|
26
|
-
categories: ['
|
|
26
|
+
categories: ['mpx-essential'],
|
|
27
27
|
url: 'https://eslint.vuejs.org/rules/no-reserved-keys.html'
|
|
28
28
|
},
|
|
29
29
|
fixable: null,
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'problem',
|
|
21
21
|
docs: {
|
|
22
22
|
description: 'disallow side effects in computed properties',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['mpx-essential'],
|
|
24
24
|
url:
|
|
25
25
|
'https://eslint.vuejs.org/rules/no-side-effects-in-computed-properties.html'
|
|
26
26
|
},
|
|
@@ -19,7 +19,7 @@ const utils = require('../utils')
|
|
|
19
19
|
// ------------------------------------------------------------------------------
|
|
20
20
|
|
|
21
21
|
/** @type {GroupName[]} */
|
|
22
|
-
const GROUP_NAMES = ['
|
|
22
|
+
const GROUP_NAMES = ['properties', 'computed', 'data', 'methods']
|
|
23
23
|
|
|
24
24
|
module.exports = {
|
|
25
25
|
meta: {
|
|
@@ -63,7 +63,7 @@ module.exports = {
|
|
|
63
63
|
docs: {
|
|
64
64
|
description:
|
|
65
65
|
'disallow unused variable definitions of v-for directives or scope attributes',
|
|
66
|
-
categories: ['
|
|
66
|
+
categories: ['essential'],
|
|
67
67
|
url: 'https://eslint.vuejs.org/rules/no-unused-vars.html'
|
|
68
68
|
},
|
|
69
69
|
fixable: null,
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
docs: {
|
|
21
21
|
description:
|
|
22
22
|
'enforce that a return statement is present in computed property',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['mpx-essential'],
|
|
24
24
|
url: 'https://eslint.vuejs.org/rules/return-in-computed-property.html'
|
|
25
25
|
},
|
|
26
26
|
fixable: null, // or "code" or "whitespace"
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'problem',
|
|
21
21
|
docs: {
|
|
22
22
|
description: 'enforce valid `v-text` directives',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['essential'],
|
|
24
24
|
url: 'https://eslint.vuejs.org/rules/valid-v-text.html'
|
|
25
25
|
},
|
|
26
26
|
fixable: null,
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'problem',
|
|
21
21
|
docs: {
|
|
22
22
|
description: 'enforce valid `wx:elif` directives',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['mpx-essential'],
|
|
24
24
|
url: 'https://eslint.vuejs.org/rules/valid-wx:elif.html'
|
|
25
25
|
},
|
|
26
26
|
fixable: null,
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'problem',
|
|
21
21
|
docs: {
|
|
22
22
|
description: 'enforce valid `wx:else` directives',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['mpx-essential'],
|
|
24
24
|
url: 'https://eslint.vuejs.org/rules/valid-wx:else.html'
|
|
25
25
|
},
|
|
26
26
|
fixable: null,
|
|
@@ -103,7 +103,7 @@ module.exports = {
|
|
|
103
103
|
type: 'problem',
|
|
104
104
|
docs: {
|
|
105
105
|
description: 'enforce valid `wx:for` directives',
|
|
106
|
-
categories: [
|
|
106
|
+
categories: [],
|
|
107
107
|
url: 'https://eslint.vuejs.org/rules/valid-wx:for.html'
|
|
108
108
|
},
|
|
109
109
|
fixable: null,
|
package/lib/rules/valid-wx-if.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'problem',
|
|
21
21
|
docs: {
|
|
22
22
|
description: 'enforce valid `wx:if` directives',
|
|
23
|
-
categories: ['
|
|
23
|
+
categories: ['mpx-essential'],
|
|
24
24
|
url: 'https://eslint.vuejs.org/rules/valid-v-if.html'
|
|
25
25
|
},
|
|
26
26
|
fixable: null,
|
|
@@ -38,7 +38,7 @@ module.exports = {
|
|
|
38
38
|
node,
|
|
39
39
|
loc: node.loc,
|
|
40
40
|
message:
|
|
41
|
-
"'wx:if' and 'wx:
|
|
41
|
+
"'wx:if' and 'wx:else' directives can't exist on the same element. You may want 'wx:elif' directives."
|
|
42
42
|
})
|
|
43
43
|
}
|
|
44
44
|
if (utils.hasDirective(element, 'elif')) {
|
|
@@ -33,7 +33,7 @@ module.exports = {
|
|
|
33
33
|
type: 'problem',
|
|
34
34
|
docs: {
|
|
35
35
|
description: 'enforce valid `wx:model` directives',
|
|
36
|
-
categories: ['
|
|
36
|
+
// categories: ['mpx-essential'],
|
|
37
37
|
url: 'https://eslint.vuejs.org/rules/valid-wx:model.html'
|
|
38
38
|
},
|
|
39
39
|
fixable: null,
|
package/lib/utils/index.js
CHANGED
|
@@ -81,15 +81,15 @@
|
|
|
81
81
|
* @typedef { {key: string | null, value: BlockStatement | null} } ComponentComputedProperty
|
|
82
82
|
*/
|
|
83
83
|
/**
|
|
84
|
-
* @typedef { '
|
|
84
|
+
* @typedef { 'properties' | 'data' | 'computed' | 'watch' | 'methods' } GroupName
|
|
85
85
|
* @typedef { { type: 'array', name: string, groupName: GroupName, node: Literal | TemplateLiteral } } ComponentArrayPropertyData
|
|
86
86
|
* @typedef { { type: 'object', name: string, groupName: GroupName, node: Identifier | Literal | TemplateLiteral, property: Property } } ComponentObjectPropertyData
|
|
87
87
|
* @typedef { ComponentArrayPropertyData | ComponentObjectPropertyData } ComponentPropertyData
|
|
88
88
|
*/
|
|
89
89
|
/**
|
|
90
|
-
* @typedef {import('../../typings/eslint-plugin-
|
|
91
|
-
* @typedef {import('../../typings/eslint-plugin-
|
|
92
|
-
* @typedef {import('../../typings/eslint-plugin-
|
|
90
|
+
* @typedef {import('../../typings/eslint-plugin-mpx/util-types/utils').VueObjectType} VueObjectType
|
|
91
|
+
* @typedef {import('../../typings/eslint-plugin-mpx/util-types/utils').VueObjectData} VueObjectData
|
|
92
|
+
* @typedef {import('../../typings/eslint-plugin-mpx/util-types/utils').VueVisitor} VueVisitor
|
|
93
93
|
*/
|
|
94
94
|
|
|
95
95
|
// ------------------------------------------------------------------------------
|
|
@@ -670,8 +670,7 @@ module.exports = {
|
|
|
670
670
|
return (
|
|
671
671
|
p.type === 'Property' &&
|
|
672
672
|
p.key.type === 'Identifier' &&
|
|
673
|
-
(p.key.name === 'props' ||
|
|
674
|
-
p.key.name === 'properties' ) &&
|
|
673
|
+
(p.key.name === 'props' || p.key.name === 'properties') &&
|
|
675
674
|
(p.value.type === 'ObjectExpression' ||
|
|
676
675
|
p.value.type === 'ArrayExpression')
|
|
677
676
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[
|
|
2
|
-
"$data", "$props", "$el", "$options", "$parent", "$root", "$children", "$slots", "$scopedSlots", "$refs", "$isServer", "$attrs", "$listeners",
|
|
3
|
-
"$watch", "$set", "$delete", "$on", "$once", "$off", "$emit", "$mount", "$forceUpdate", "$nextTick", "$destroy"
|
|
2
|
+
"$data", "$props", "$el", "$options", "$parent", "$root", "$children", "$slots", "$scopedSlots", "$refs", "$isServer", "$attrs", "$listeners", "$i18n", "$hook", "$xfetch",
|
|
3
|
+
"$watch", "$set", "$delete", "$on", "$once", "$off", "$emit", "$mount", "$forceUpdate", "$nextTick", "$destroy" , "$remove"
|
|
4
4
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-mpx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Official ESLint plugin for Mpx.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"eslint-utils": "^2.1.0",
|
|
52
|
-
"mpx-eslint-parser": "0.0.
|
|
52
|
+
"mpx-eslint-parser": "0.0.8",
|
|
53
53
|
"natural-compare": "^1.4.0",
|
|
54
54
|
"semver": "^7.3.2",
|
|
55
55
|
"vue-eslint-parser": "^7.1.0"
|