@gitlab/eslint-plugin 12.3.0 → 14.0.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,41 @@
|
|
|
1
|
+
# [14.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v13.1.0...v14.0.0) (2022-07-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* update eslint to 8 ([09a0b36](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/09a0b363082124809825cb3b11c6c803710b86a5))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* Check the ESLint 8 release notes
|
|
12
|
+
for more information.
|
|
13
|
+
https://eslint.org/docs/8.0.0/user-guide/migrating-to-8.0.0
|
|
14
|
+
|
|
15
|
+
# [13.1.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v13.0.0...v13.1.0) (2022-07-08)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* Add vue-prefer-dollar-scopedslots rule ([93682d9](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/93682d9450aa4389c7b606abf56ead32e302ad33))
|
|
21
|
+
|
|
22
|
+
# [13.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.3.0...v13.0.0) (2022-07-05)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* Disallow Composition API ([9fe6ffa](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/9fe6ffac9e1ae59c48aed619997e380d1f5b9115))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### BREAKING CHANGES
|
|
31
|
+
|
|
32
|
+
* This disallows the Composition API. Since we're still
|
|
33
|
+
using Vue 2.6 which doesn't support it anyway, this should have no
|
|
34
|
+
effect. Once we upgrade to Vue 2.7, we can consider relaxing this rule
|
|
35
|
+
as we develop guidelines around its usage.
|
|
36
|
+
|
|
37
|
+
See https://gitlab.com/gitlab-org/frontend/eslint-plugin/-/issues/52.
|
|
38
|
+
|
|
1
39
|
# [12.3.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.2.1...v12.3.0) (2022-05-20)
|
|
2
40
|
|
|
3
41
|
|
|
@@ -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/configs/default.js
CHANGED
|
@@ -116,6 +116,8 @@ module.exports = {
|
|
|
116
116
|
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
|
|
117
117
|
},
|
|
118
118
|
],
|
|
119
|
+
// See https://gitlab.com/gitlab-org/frontend/eslint-plugin/-/issues/52.
|
|
120
|
+
'vue/component-api-style': ['error', ['options']],
|
|
119
121
|
// BEGIN rules to aid migration from Vue 2.x to 3.x.
|
|
120
122
|
// See https://gitlab.com/groups/gitlab-org/-/epics/3174 for more details.
|
|
121
123
|
'vue/no-deprecated-data-object-declaration': 'error',
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitlab/eslint-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "GitLab package for our custom eslint rules",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"lodash": "^4.17.21"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"eslint": "^
|
|
47
|
+
"eslint": "^8.19.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"eslint": "^
|
|
50
|
+
"eslint": "^8.19.0",
|
|
51
51
|
"glob": "^7.2.0",
|
|
52
52
|
"jest": "^27.5.1",
|
|
53
53
|
"prettier": "^2.6.1",
|
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
|
|