File tree Expand file tree Collapse file tree 7 files changed +208
-1
lines changed Expand file tree Collapse file tree 7 files changed +208
-1
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,7 @@ For example:
301301| [ vue/no-deprecated-v-is] ( ./no-deprecated-v-is.md ) | disallow deprecated ` v-is ` directive (in Vue.js 3.1.0+) | :wrench : |
302302| [ vue/no-duplicate-attr-inheritance] ( ./no-duplicate-attr-inheritance.md ) | enforce ` inheritAttrs ` to be set to ` false ` when using ` v-bind="$attrs" ` | |
303303| [ vue/no-empty-component-block] ( ./no-empty-component-block.md ) | disallow the ` <template> ` ` <script> ` ` <style> ` block to be empty | |
304+ | [ vue/no-export-in-script-setup] ( ./no-export-in-script-setup.md ) | disallow ` export ` in ` <script setup> ` | |
304305| [ vue/no-invalid-model-keys] ( ./no-invalid-model-keys.md ) | require valid keys in model option | |
305306| [ vue/no-multiple-objects-in-class] ( ./no-multiple-objects-in-class.md ) | disallow to pass multiple objects into array to class | |
306307| [ vue/no-potential-component-option-typo] ( ./no-potential-component-option-typo.md ) | disallow a potential typo in your component property | |
Original file line number Diff line number Diff line change 1+ ---
2+ pageClass : rule-details
3+ sidebarDepth : 0
4+ title : vue/no-export-in-script-setup
5+ description : disallow `export` in `<script setup>`
6+ ---
7+ # vue/no-export-in-script-setup
8+
9+ > disallow ` export ` in ` <script setup> `
10+
11+ - :exclamation : <badge text =" This rule has not been released yet. " vertical =" middle " type =" error " > *** This rule has not been released yet.*** </badge >
12+
13+ ## :book : Rule Details
14+
15+ This rule warns ES module exports in ` <script setup> ` .
16+
17+ The previous version of ` <script setup> ` RFC used ` export ` to define variables used in templates, but the new ` <script setup> ` RFC has been updated to define without using ` export ` .
18+ See [ Vue RFCs - 0040-script-setup] for more details.
19+
20+ <eslint-code-block :rules =" {'vue/no-export-in-script-setup': ['error']} " >
21+
22+ ``` vue
23+ <script setup>
24+ /* ✓ GOOD */
25+ let msg = 'Hello!'
26+ </script>
27+ ```
28+
29+ </eslint-code-block >
30+
31+ <eslint-code-block :rules =" {'vue/no-export-in-script-setup': ['error']} " >
32+
33+ ``` vue
34+ <script setup>
35+ /* ✗ BAD */
36+ export let msg = 'Hello!'
37+ </script>
38+ ```
39+
40+ </eslint-code-block >
41+
42+ ## :wrench : Options
43+
44+ Nothing.
45+
46+ ## :books : Further Reading
47+
48+ - [ Vue RFCs - 0040-script-setup]
49+
50+ [ Vue RFCs - 0040-script-setup ] : https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md
51+
52+ ## :mag : Implementation
53+
54+ - [ Rule source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-export-in-script-setup.js )
55+ - [ Test source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-export-in-script-setup.js )
Original file line number Diff line number Diff line change @@ -103,6 +103,8 @@ If you want to use custom parsers such as [babel-eslint](https://www.npmjs.com/p
103103 }
104104```
105105
106+ The ` parserOptions.parser ` option can also specify an object to specify multiple parsers. See [ vue-eslint-parser README] ( https://github.com/vuejs/vue-eslint-parser#readme ) for more details.
107+
106108### How does ESLint detect components?
107109
108110All component-related rules are applied to code that passes any of the following checks:
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ module.exports = {
8181 'no-duplicate-attributes' : require ( './rules/no-duplicate-attributes' ) ,
8282 'no-empty-component-block' : require ( './rules/no-empty-component-block' ) ,
8383 'no-empty-pattern' : require ( './rules/no-empty-pattern' ) ,
84+ 'no-export-in-script-setup' : require ( './rules/no-export-in-script-setup' ) ,
8485 'no-extra-parens' : require ( './rules/no-extra-parens' ) ,
8586 'no-invalid-model-keys' : require ( './rules/no-invalid-model-keys' ) ,
8687 'no-irregular-whitespace' : require ( './rules/no-irregular-whitespace' ) ,
Original file line number Diff line number Diff line change 1+ /**
2+ * @author Yosuke Ota
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 : 'disallow `export` in `<script setup>`' ,
14+ // TODO Switch in the major version.
15+ // categories: ['vue3-essential'],
16+ categories : undefined ,
17+ url : 'https://eslint.vuejs.org/rules/no-export-in-script-setup.html'
18+ } ,
19+ fixable : null ,
20+ schema : [ ] ,
21+ messages : {
22+ forbidden : '`<script setup>` cannot contain ES module exports.'
23+ }
24+ } ,
25+ /** @param {RuleContext } context */
26+ create ( context ) {
27+ /** @param {ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration } node */
28+ function report ( node ) {
29+ context . report ( {
30+ node,
31+ messageId : 'forbidden'
32+ } )
33+ }
34+
35+ return utils . defineScriptSetupVisitor ( context , {
36+ ExportAllDeclaration : report ,
37+ ExportDefaultDeclaration : report ,
38+ ExportNamedDeclaration : report
39+ } )
40+ }
41+ }
Original file line number Diff line number Diff line change 5656 "eslint-utils" : " ^2.1.0" ,
5757 "natural-compare" : " ^1.4.0" ,
5858 "semver" : " ^7.3.2" ,
59- "vue-eslint-parser" : " ^7.7.2 "
59+ "vue-eslint-parser" : " ^7.8.0 "
6060 },
6161 "devDependencies" : {
6262 "@types/eslint" : " ^7.2.0" ,
Original file line number Diff line number Diff line change 1+ /**
2+ * @author Yosuke Ota
3+ * See LICENSE file in root directory for full license.
4+ */
5+ 'use strict'
6+
7+ // ------------------------------------------------------------------------------
8+ // Requirements
9+ // ------------------------------------------------------------------------------
10+
11+ const eslint = require ( 'eslint' )
12+ const rule = require ( '../../../lib/rules/no-export-in-script-setup' )
13+
14+ const RuleTester = eslint . RuleTester
15+ const ruleTester = new RuleTester ( {
16+ parser : require . resolve ( 'vue-eslint-parser' ) ,
17+ parserOptions : {
18+ ecmaVersion : 6 ,
19+ sourceType : 'module'
20+ }
21+ } )
22+
23+ // ------------------------------------------------------------------------------
24+ // Tests
25+ // ------------------------------------------------------------------------------
26+
27+ ruleTester . run ( 'no-export-in-script-setup' , rule , {
28+ valid : [
29+ {
30+ filename : 'test.vue' ,
31+ code : `
32+ <script>
33+ export * from 'foo'
34+ export default {}
35+ export class A {}
36+ </script>
37+ `
38+ } ,
39+ {
40+ filename : 'test.vue' ,
41+ code : `
42+ <script>
43+ export * from 'foo'
44+ export default {}
45+ export class A {}
46+ </script>
47+ <script setup>
48+ let foo;
49+ </script>
50+ `
51+ }
52+ ] ,
53+
54+ invalid : [
55+ {
56+ filename : 'test.vue' ,
57+ code : `
58+ <script setup>
59+ export * from 'foo'
60+ export default {}
61+ export class A {}
62+ </script>
63+ ` ,
64+ errors : [
65+ {
66+ message : '`<script setup>` cannot contain ES module exports.' ,
67+ line : 3
68+ } ,
69+ {
70+ message : '`<script setup>` cannot contain ES module exports.' ,
71+ line : 4
72+ } ,
73+ {
74+ message : '`<script setup>` cannot contain ES module exports.' ,
75+ line : 5
76+ }
77+ ]
78+ } ,
79+ {
80+ filename : 'test.vue' ,
81+ code : `
82+ <script>
83+ let foo;
84+ </script>
85+ <script setup>
86+ export * from 'foo'
87+ export default {}
88+ export class A {}
89+ </script>
90+ ` ,
91+ errors : [
92+ {
93+ message : '`<script setup>` cannot contain ES module exports.' ,
94+ line : 6
95+ } ,
96+ {
97+ message : '`<script setup>` cannot contain ES module exports.' ,
98+ line : 7
99+ } ,
100+ {
101+ message : '`<script setup>` cannot contain ES module exports.' ,
102+ line : 8
103+ }
104+ ]
105+ }
106+ ]
107+ } )
You can’t perform that action at this time.
0 commit comments