@gitlab/eslint-plugin 12.2.1 → 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,34 @@
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
+
8
+ # [13.0.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.3.0...v13.0.0) (2022-07-05)
9
+
10
+
11
+ ### Features
12
+
13
+ * Disallow Composition API ([9fe6ffa](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/9fe6ffac9e1ae59c48aed619997e380d1f5b9115))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * This disallows the Composition API. Since we're still
19
+ using Vue 2.6 which doesn't support it anyway, this should have no
20
+ effect. Once we upgrade to Vue 2.7, we can consider relaxing this rule
21
+ as we develop guidelines around its usage.
22
+
23
+ See https://gitlab.com/gitlab-org/frontend/eslint-plugin/-/issues/52.
24
+
25
+ # [12.3.0](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.2.1...v12.3.0) (2022-05-20)
26
+
27
+
28
+ ### Features
29
+
30
+ * Enable no-dynamic-require rule to prevent import expressions ([c260068](https://gitlab.com/gitlab-org/frontend/eslint-plugin/commit/c260068542710f5a7417603d4ea0eddefdbb88a4))
31
+
1
32
  ## [12.2.1](https://gitlab.com/gitlab-org/frontend/eslint-plugin/compare/v12.2.0...v12.2.1) (2022-05-20)
2
33
 
3
34
 
@@ -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
@@ -31,6 +31,7 @@ module.exports = {
31
31
  'import/prefer-default-export': 'off',
32
32
  'import/no-default-export': 'error',
33
33
  'import/no-deprecated': 'error',
34
+ 'import/no-dynamic-require': ['error', { esmodule: true }],
34
35
  'no-implicit-coercion': [
35
36
  'error',
36
37
  {
@@ -115,6 +116,8 @@ module.exports = {
115
116
  groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
116
117
  },
117
118
  ],
119
+ // See https://gitlab.com/gitlab-org/frontend/eslint-plugin/-/issues/52.
120
+ 'vue/component-api-style': ['error', ['options']],
118
121
  // BEGIN rules to aid migration from Vue 2.x to 3.x.
119
122
  // See https://gitlab.com/groups/gitlab-org/-/epics/3174 for more details.
120
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": "12.2.1",
3
+ "version": "13.1.0",
4
4
  "description": "GitLab package for our custom eslint rules",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -36,7 +36,7 @@
36
36
  "eslint-config-airbnb-base": "^15.0.0",
37
37
  "eslint-config-prettier": "^6.10.0",
38
38
  "eslint-plugin-babel": "^5.3.0",
39
- "eslint-plugin-import": "^2.25.2",
39
+ "eslint-plugin-import": "^2.26.0",
40
40
  "eslint-plugin-jest": "^23.8.2",
41
41
  "eslint-plugin-promise": "^4.2.1",
42
42
  "eslint-plugin-unicorn": "^40.1.0",
@@ -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