eslint-plugin-mpx 0.2.7 → 0.2.9

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.
@@ -14,6 +14,9 @@ module.exports = {
14
14
  'mpx/valid-wx-elif': 'error',
15
15
  'mpx/valid-wx-model': 'error',
16
16
  // 'mpx/script-setup-uses-vars': 'error',
17
- 'mpx/valid-setup-define-expose': 'error'
17
+ 'mpx/valid-setup-define-expose': 'error',
18
+ 'mpx/no-deprecated-mpx-createfunction': 'error',
19
+ 'mpx/no-deprecated-watch-second-param': 'error',
20
+ 'mpx/no-deprecated-lifecycle': 'error'
18
21
  }
19
22
  }
@@ -18,7 +18,6 @@ module.exports = {
18
18
  'mpx/valid-wx-if': 'error',
19
19
  'mpx/valid-wx-else': 'error',
20
20
  'mpx/valid-wx-elif': 'error',
21
- // 'mpx/valid-wx-for': 'error',
22
21
  'mpx/valid-wx-model': 'error',
23
22
  'mpx/valid-swiper-item-style': 'error',
24
23
  'mpx/valid-wx-key': 'error',
package/lib/index.js CHANGED
@@ -31,7 +31,10 @@ module.exports = {
31
31
  'valid-attribute-value': require('./rules/valid-attribute-value'),
32
32
  'valid-template-quote': require('./rules/valid-template-quote'),
33
33
  'valid-component-range': require('./rules/valid-component-range'),
34
- 'valid-setup-define-expose': require('./rules/valid-setup-define-expose')
34
+ 'valid-setup-define-expose': require('./rules/valid-setup-define-expose'),
35
+ 'no-deprecated-lifecycle': require('./rules/no-deprecated-lifecycle'),
36
+ 'no-deprecated-mpx-createfunction': require('./rules/no-deprecated-mpx-createfunction'),
37
+ 'no-deprecated-watch-second-param': require('./rules/no-deprecated-watch-second-param')
35
38
  },
36
39
  configs: {
37
40
  base: require('./configs/base'),
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @author pagnkelly
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ 'use strict'
6
+
7
+ const utils = require('../utils')
8
+
9
+ module.exports = {
10
+ meta: {
11
+ type: 'problem',
12
+ docs: {
13
+ description: 'pageShow/pageHide废弃的生命周期',
14
+ categories: ['composition-api-essential'],
15
+ url: 'https://mpx-ecology.github.io/eslint-plugin-mpx/rules/no-deprecated-lifecycle.html'
16
+ },
17
+ fixable: 'code',
18
+ schema: [],
19
+ messages: {
20
+ deprecatedPageShow:
21
+ 'The `pageShow` lifecycle hook is deprecated. Use `pageLifetimes.show` instead.',
22
+ deprecatedPageHide:
23
+ 'The `pageHide` lifecycle hook is deprecated. Use `pageLifetimes.hide` instead.'
24
+ }
25
+ },
26
+ /** @param {RuleContext} context */
27
+ create(context) {
28
+ return utils.executeOnMpx(context, (obj) => {
29
+ const pageShow = utils.findProperty(obj, 'pageShow')
30
+ if (pageShow) {
31
+ context.report({
32
+ node: pageShow.key,
33
+ messageId: 'deprecatedPageShow'
34
+ })
35
+ }
36
+
37
+ const pageHide = utils.findProperty(obj, 'pageHide')
38
+ if (pageHide) {
39
+ context.report({
40
+ node: pageHide.key,
41
+ messageId: 'deprecatedPageHide'
42
+ })
43
+ }
44
+ })
45
+ }
46
+ }
@@ -0,0 +1,46 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @author pagnkelly
4
+ * See LICENSE file in root directory for full license.
5
+ */
6
+ 'use strict'
7
+
8
+ module.exports = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'mpx.create*调用方式已经被废弃',
13
+ categories: ['composition-api-essential'],
14
+ url: 'https://mpx-ecology.github.io/eslint-plugin-mpx/rules/no-deprecated-mpx-createfunction'
15
+ },
16
+ fixable: 'code',
17
+ schema: []
18
+ },
19
+ /** @param {RuleContext} context */
20
+ create(context) {
21
+ return {
22
+ /** @param {import("mpx-eslint-parser/ast").ESLintStatement} node */
23
+ ExpressionStatement(node) {
24
+ if (
25
+ node.expression.callee &&
26
+ node.expression.callee.object &&
27
+ node.expression.callee.object.name === 'mpx' &&
28
+ node.expression.callee.property &&
29
+ [
30
+ 'createApp',
31
+ 'createStore',
32
+ 'createPage',
33
+ 'createComponent'
34
+ ].includes(node.expression.callee.property.name)
35
+ ) {
36
+ context.report({
37
+ node,
38
+ message:
39
+ 'The Mpx object of default export is no longer attached to the {{name}} runtime method.',
40
+ data: { name: node.expression.callee.property.name }
41
+ })
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,40 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @author pagnkelly
4
+ * See LICENSE file in root directory for full license.
5
+ */
6
+ 'use strict'
7
+
8
+ module.exports = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'watch第二个参数统一为函数,不再提供对象',
13
+ categories: ['composition-api-essential'],
14
+ url: 'https://mpx-ecology.github.io/eslint-plugin-mpx/rules/no-deprecated-watch-second-param'
15
+ },
16
+ fixable: 'code',
17
+ schema: []
18
+ },
19
+ /** @param {RuleContext} context */
20
+ create(context) {
21
+ return {
22
+ /** @param {import("mpx-eslint-parser/ast").ESLintStatement} node */
23
+ ExpressionStatement(node) {
24
+ if (
25
+ node.expression &&
26
+ node.expression.type === 'CallExpression' &&
27
+ node.expression.callee.name === 'watch' &&
28
+ node.expression.arguments[1] &&
29
+ node.expression.arguments[1].type === 'ObjectExpression'
30
+ ) {
31
+ context.report({
32
+ node,
33
+ message:
34
+ 'The watch API no longer accepts the second parameter as an object with the handler attribute.'
35
+ })
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
@@ -61,7 +61,7 @@ function handleProperties(properties, exposeSet, scriptVariableNames) {
61
61
  /**
62
62
  * @param {String} name - 展开节点
63
63
  * @param {Set<String>} exposeSet 存储定义的expose变量
64
- * @param {Object} scriptVariableNames 用于解析定义的展开的expose变量
64
+ * @param {any} scriptVariableNames 用于解析定义的展开的expose变量
65
65
  */
66
66
  function handleIdentifier(name, exposeSet, scriptVariableNames) {
67
67
  const props = scriptVariableNames[name]
@@ -77,10 +77,9 @@ module.exports = {
77
77
  docs: {
78
78
  description:
79
79
  'prevent `<script setup>` variables used in `<template>` to be marked as unused', // eslint-disable-line eslint-plugin/require-meta-docs-description
80
- categories: undefined,
80
+ categories: ['composition-api-essential'],
81
81
  url: 'https://eslint.vuejs.org/rules/script-setup-uses-vars.html'
82
82
  },
83
- categories: ['composition-api-essential'],
84
83
  schema: [],
85
84
  messages: {
86
85
  unexpected: "The variable '{{name}}' isn't expose in setup scripts."
@@ -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://mpx-ecology.github.io/eslint-plugin-mpx/rules/valid-wx-model.html'
38
38
  },
39
39
  fixable: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-mpx",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Official ESLint plugin for Mpx.js",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,189 +0,0 @@
1
- /**
2
- * @author pagnkelly
3
- * @copyright 2020 pagnkelly. All rights reserved.
4
- * See LICENSE file in root directory for full license.
5
- */
6
- 'use strict'
7
-
8
- // ------------------------------------------------------------------------------
9
- // Requirements
10
- // ------------------------------------------------------------------------------
11
-
12
- const utils = require('../utils')
13
-
14
- // ------------------------------------------------------------------------------
15
- // Helpers
16
- // ------------------------------------------------------------------------------
17
-
18
- /**
19
- * Check whether the given attribute is using the variables which are defined by `wx:for` directives.
20
- * @param {VDirective} vFor The attribute node of `wx:for` to check.
21
- * @param {VDirective} vBindKey The attribute node of `wx:bind:key` to check.
22
- * @returns {boolean} `true` if the node is using the variables which are defined by `wx:for` directives.
23
- */
24
- function isUsingIterationVar(vFor, vBindKey) {
25
- if (vBindKey.value == null) {
26
- return false
27
- }
28
- const references = vBindKey.value.references
29
- return references.some((reference) =>
30
- ['item', '*this'].includes(reference.id.name)
31
- )
32
- }
33
-
34
- /**
35
- * Check the child element in tempalte wx:for about `wx:bind:key` attributes.
36
- * @param {RuleContext} context The rule context to report.
37
- * @param {VDirective} vFor The attribute node of `wx:for` to check.
38
- * @param {VElement} child The child node to check.
39
- */
40
- function checkChildKey(context, vFor, child) {
41
- const childFor = utils.getDirective(child, 'for')
42
- // if child has wx:for, check if parent iterator is used in wx:for
43
- if (childFor != null) {
44
- const childForRefs = (childFor.value && childFor.value.references) || []
45
- const variables = vFor.parent.parent.variables
46
- const usedInFor = childForRefs.some((cref) =>
47
- variables.some(
48
- (variable) =>
49
- cref.id.name === variable.id.name && variable.kind === 'wx:for'
50
- )
51
- )
52
- // if parent iterator is used, skip other checks
53
- // iterator usage will be checked later by child wx:for
54
- if (usedInFor) {
55
- return
56
- }
57
- }
58
- // otherwise, check if parent iterator is directly used in child's key
59
- checkKey(context, vFor, child)
60
- }
61
-
62
- /**
63
- * Check the given element about `wx:bind:key` attributes.
64
- * @param {RuleContext} context The rule context to report.
65
- * @param {VDirective} vFor The attribute node of `wx:for` to check.
66
- * @param {VElement} element The element node to check.
67
- */
68
- function checkKey(context, vFor, element) {
69
- if (element.name === 'template') {
70
- for (const child of element.children) {
71
- if (child.type === 'VElement') {
72
- checkChildKey(context, vFor, child)
73
- }
74
- }
75
- return
76
- }
77
-
78
- const vBindKey = utils.getDirective(element, 'key')
79
- if (utils.isCustomComponent(element) && vBindKey == null) {
80
- context.report({
81
- node: element.startTag,
82
- loc: element.startTag.loc,
83
- message: "Custom elements in iteration require 'wx:key' directives."
84
- })
85
- }
86
- if (vBindKey != null && !isUsingIterationVar(vFor, vBindKey)) {
87
- context.report({
88
- node: vBindKey,
89
- loc: vBindKey.loc,
90
- message:
91
- "Expected 'wx:key' directive to use the variables which are defined by the 'wx:for' directive."
92
- })
93
- }
94
- }
95
-
96
- // ------------------------------------------------------------------------------
97
- // Rule Definition
98
- // ------------------------------------------------------------------------------
99
-
100
- module.exports = {
101
- meta: {
102
- type: 'problem',
103
- docs: {
104
- description: 'enforce valid `wx:for` directives',
105
- categories: [],
106
- url: 'https://mpx-ecology.github.io/eslint-plugin-mpx/rules/valid-wx-for.html'
107
- },
108
- fixable: null,
109
- schema: []
110
- },
111
- /** @param {RuleContext} context */
112
- create(context) {
113
- const sourceCode = context.getSourceCode()
114
-
115
- return utils.defineTemplateBodyVisitor(context, {
116
- /** @param {VDirective} node */
117
- "VAttribute[directive=true][key.name.name='for']"(node) {
118
- const element = node.parent.parent
119
-
120
- checkKey(context, node, element)
121
-
122
- if (node.key.argument) {
123
- context.report({
124
- node,
125
- loc: node.loc,
126
- message: "'wx:for' directives require no argument."
127
- })
128
- }
129
- if (node.key.modifiers.length > 0) {
130
- context.report({
131
- node,
132
- loc: node.loc,
133
- message: "'wx:for' directives require no modifier."
134
- })
135
- }
136
- if (!node.value || utils.isEmptyValueDirective(node, context)) {
137
- context.report({
138
- node,
139
- loc: node.loc,
140
- message: "'wx:for' directives require that attribute value."
141
- })
142
- return
143
- }
144
-
145
- const expr = node.value.expression
146
- if (expr == null) {
147
- return
148
- }
149
- if (expr.type !== 'VForExpression') {
150
- context.report({
151
- node: node.value,
152
- loc: node.value.loc,
153
- message:
154
- "'wx:for' directives require the special syntax '<alias> in <expression>'."
155
- })
156
- return
157
- }
158
-
159
- const lhs = expr.left
160
- const value = lhs[0]
161
- const key = lhs[1]
162
- const index = lhs[2]
163
-
164
- if (value === null) {
165
- context.report({
166
- node: expr,
167
- message: "Invalid alias ''."
168
- })
169
- }
170
- if (key !== undefined && (!key || key.type !== 'Identifier')) {
171
- context.report({
172
- node: key || expr,
173
- loc: key && key.loc,
174
- message: "Invalid alias '{{text}}'.",
175
- data: { text: key ? sourceCode.getText(key) : '' }
176
- })
177
- }
178
- if (index !== undefined && (!index || index.type !== 'Identifier')) {
179
- context.report({
180
- node: index || expr,
181
- loc: index && index.loc,
182
- message: "Invalid alias '{{text}}'.",
183
- data: { text: index ? sourceCode.getText(index) : '' }
184
- })
185
- }
186
- }
187
- })
188
- }
189
- }