@gitlab/eslint-plugin 13.0.0 → 13.1.0
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [13.1.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v13.0.0...v13.1.0) (2022-07-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add vue-prefer-dollar-scopedslots rule ([93682d9](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/93682d9450aa4389c7b606abf56ead32e302ad33))
|
|
7
|
+
|
|
1
8
|
# [13.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.3.0...v13.0.0) (2022-07-05)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @gitlab/vue-prefer-dollar-scopedslots
|
|
2
|
+
|
|
3
|
+
Prefer $scopedSlots over $slots when using Vue 2.x.
|
|
4
|
+
|
|
5
|
+
Scoped slots are more flexible and powerful, ease migration to Vue 3.x, and
|
|
6
|
+
also work around https://github.com/vuejs/vue/issues/11084.
|
|
7
|
+
|
|
8
|
+
This rule should _not_ be used with Vue 3.x, since `$scopedSlots` was
|
|
9
|
+
[removed](https://v3-migration.vuejs.org/breaking-changes/slots-unification.html).
|
|
10
|
+
Instead, use
|
|
11
|
+
[`vue/no-deprecated-dollar-scopedslots-api`](https://eslint.vuejs.org/rules/no-deprecated-dollar-scopedslots-api.html).
|
|
12
|
+
It includes a fixer that will migrate `$scopedSlots` usage _back_ to `$slots`,
|
|
13
|
+
which is trivial since the API for Vue 2.x's `$scopedSlots` is identical to Vue
|
|
14
|
+
3.x's `$slots`.
|
|
15
|
+
|
|
16
|
+
## Rule Details
|
|
17
|
+
|
|
18
|
+
### Examples of **incorrect** code for this rule
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<div v-if="$slots.default">
|
|
22
|
+
<slot></slot>
|
|
23
|
+
</div>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
export default {
|
|
28
|
+
render(h) {
|
|
29
|
+
return this.$slots.foo ? this.$slots.foo : null;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Examples of **correct** code for this rule
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<div v-if="$scopedSlots.default">
|
|
38
|
+
<slot></slot>
|
|
39
|
+
</div>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
export default {
|
|
44
|
+
render(h) {
|
|
45
|
+
return this.$scopedSlots.foo
|
|
46
|
+
? this.$slots.foo() // Note the function call!
|
|
47
|
+
: null;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Options
|
|
53
|
+
|
|
54
|
+
Nothing
|
|
55
|
+
|
|
56
|
+
## Related rules
|
|
57
|
+
|
|
58
|
+
- [`vue/no-deprecated-dollar-scopedslots-api`](https://eslint.vuejs.org/rules/no-deprecated-dollar-scopedslots-api.html) (for Vue 3.x)
|
|
59
|
+
|
|
60
|
+
## When Not To Use It
|
|
61
|
+
|
|
62
|
+
When using Vue 3.x.
|
package/docs/rules.md
CHANGED
|
@@ -10,6 +10,7 @@ Available rules:
|
|
|
10
10
|
- [require-valid-i18n-helpers](./rules/require-valid-i18n-helpers.md): Enforces valid usage of translation helpers in JavaScript.
|
|
11
11
|
- [vue-no-data-toggle](./rules/vue-no-data-toggle.md): Restrict the use of `data-toggle` bootstrap behaviors within Vue templates
|
|
12
12
|
- [vue-no-new-non-primitive-in-template](./rules/vue-no-new-non-primitive-in-template.md): Prevents non-primitive values from being declared in templates
|
|
13
|
+
- [vue-prefer-dollar-scopedslots](./rules/vue-prefer-dollar-scopedslots.md): Prefer $scopedSlots over $slots for Vue 2.x.
|
|
13
14
|
- [vue-require-i18n-attribute-strings](./rules/vue-require-i18n-attribute-strings.md): Detect non externalized strings in vue `<template>` attributes
|
|
14
15
|
- [vue-require-i18n-strings](./rules/vue-require-i18n-strings.md): enforce no bare strings in vue `<template>`
|
|
15
16
|
- [vue-require-required-key](./rules/vue-require-required-key.md): Require the required key to be set
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports = {
|
|
|
9
9
|
'require-valid-i18n-helpers': require('./rules/require-valid-i18n-helpers.js'),
|
|
10
10
|
'vue-no-data-toggle': require('./rules/vue-no-data-toggle.js'),
|
|
11
11
|
'vue-no-new-non-primitive-in-template': require('./rules/vue-no-new-non-primitive-in-template.js'),
|
|
12
|
+
'vue-prefer-dollar-scopedslots': require('./rules/vue-prefer-dollar-scopedslots.js'),
|
|
12
13
|
'vue-require-i18n-attribute-strings': require('./rules/vue-require-i18n-attribute-strings.js'),
|
|
13
14
|
'vue-require-i18n-strings': require('./rules/vue-require-i18n-strings.js'),
|
|
14
15
|
'vue-require-required-key': require('./rules/vue-require-required-key.js'),
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// ------------------------------------------------------------------------------
|
|
2
|
+
// Requirements
|
|
3
|
+
// ------------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
const { DOCS_BASE_URL } = require('../constants');
|
|
6
|
+
const { defineTemplateBodyVisitor } = require('../utils/index');
|
|
7
|
+
const utils = require('eslint-plugin-vue/lib/utils');
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------------------------
|
|
10
|
+
// Helpers
|
|
11
|
+
// ------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
const DOLLAR_SLOTS = '$slots';
|
|
14
|
+
|
|
15
|
+
// ------------------------------------------------------------------------------
|
|
16
|
+
// Rule Definition
|
|
17
|
+
// ------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'error',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Prefer $scopedSlots over $slots for Vue 2.x.',
|
|
24
|
+
category: undefined,
|
|
25
|
+
url: DOCS_BASE_URL + '/vue-prefer-dollar-scopedslots.md',
|
|
26
|
+
},
|
|
27
|
+
messages: {
|
|
28
|
+
preferDollarScopedSlots:
|
|
29
|
+
'Prefer $scopedSlots over $slots for Vue 2.x. Scoped slots are more flexible and powerful, ease migration to Vue 3.x, and also work around https://github.com/vuejs/vue/issues/11084.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
create(context) {
|
|
33
|
+
const templateVisitor = {
|
|
34
|
+
VExpressionContainer(node) {
|
|
35
|
+
for (const ref of node.references) {
|
|
36
|
+
if (ref.id.name === DOLLAR_SLOTS) {
|
|
37
|
+
context.report({
|
|
38
|
+
node,
|
|
39
|
+
loc: ref.id.loc,
|
|
40
|
+
messageId: 'preferDollarScopedSlots',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const scriptVisitor = utils.defineVueVisitor(context, {
|
|
48
|
+
MemberExpression(node) {
|
|
49
|
+
if (node.computed) return;
|
|
50
|
+
|
|
51
|
+
const { property } = node;
|
|
52
|
+
if (property.name === DOLLAR_SLOTS) {
|
|
53
|
+
context.report({
|
|
54
|
+
node: property,
|
|
55
|
+
loc: property.loc,
|
|
56
|
+
messageId: 'preferDollarScopedSlots',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return defineTemplateBodyVisitor(context, templateVisitor, scriptVisitor);
|
|
63
|
+
},
|
|
64
|
+
};
|
package/package.json
CHANGED
package/scripts/createRule.js
CHANGED
|
@@ -36,7 +36,7 @@ TODO: or describe here
|
|
|
36
36
|
|
|
37
37
|
- TBA
|
|
38
38
|
|
|
39
|
-
## When Not To Use It
|
|
39
|
+
## When Not To Use It
|
|
40
40
|
|
|
41
41
|
TODO
|
|
42
42
|
`;
|
|
@@ -128,7 +128,7 @@ rl.question('How do you want to call your rule?\n', (answer) => {
|
|
|
128
128
|
|
|
129
129
|
console.log(`Successfully wrote ${rulePath}`);
|
|
130
130
|
|
|
131
|
-
const testPath = path.join(testDir, `${name}.js`);
|
|
131
|
+
const testPath = path.join(testDir, `${name}.spec.js`);
|
|
132
132
|
|
|
133
133
|
fs.writeFileSync(testPath, testTemplate(name));
|
|
134
134
|
|