@gitlab/eslint-plugin 13.0.0 → 15.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,37 @@
1
+ # [15.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v14.0.0...v15.0.0) (2022-07-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * Prefer $scopedSlots by default ([c6a5be9](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/c6a5be943f63871784aef5df0ae98c776466bec0))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * The `@gitlab/vue-prefer-dollar-scopedslots` rule is now
12
+ enabled by default.
13
+
14
+ # [14.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v13.1.0...v14.0.0) (2022-07-12)
15
+
16
+
17
+ ### Features
18
+
19
+ * update eslint to 8 ([09a0b36](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/09a0b363082124809825cb3b11c6c803710b86a5))
20
+
21
+
22
+ ### BREAKING CHANGES
23
+
24
+ * Check the ESLint 8 release notes
25
+ for more information.
26
+ https://eslint.org/docs/8.0.0/user-guide/migrating-to-8.0.0
27
+
28
+ # [13.1.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v13.0.0...v13.1.0) (2022-07-08)
29
+
30
+
31
+ ### Features
32
+
33
+ * Add vue-prefer-dollar-scopedslots rule ([93682d9](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/93682d9450aa4389c7b606abf56ead32e302ad33))
34
+
1
35
  # [13.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.3.0...v13.0.0) (2022-07-05)
2
36
 
3
37
 
@@ -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.$scopedSlots.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
@@ -108,6 +108,7 @@ module.exports = {
108
108
  },
109
109
  ],
110
110
  '@gitlab/vue-no-data-toggle': 'error',
111
+ '@gitlab/vue-prefer-dollar-scopedslots': 'error',
111
112
  '@gitlab/vue-slot-name-casing': 'error',
112
113
  '@gitlab/no-runtime-template-compiler': 'error',
113
114
  'import/order': [
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": "13.0.0",
3
+ "version": "15.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": "^7.27.0 || ^8.0.0"
47
+ "eslint": "^8.19.0"
48
48
  },
49
49
  "devDependencies": {
50
- "eslint": "^7.27.0",
50
+ "eslint": "^8.19.0",
51
51
  "glob": "^7.2.0",
52
52
  "jest": "^27.5.1",
53
53
  "prettier": "^2.6.1",
@@ -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