File tree 5 files changed +122
-0
lines changed
5 files changed +122
-0
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
396
396
| [ vue/object-curly-newline] ( ./object-curly-newline.md ) | enforce consistent line breaks after opening and before closing braces | :wrench : |
397
397
| [ vue/object-curly-spacing] ( ./object-curly-spacing.md ) | enforce consistent spacing inside braces | :wrench : |
398
398
| [ vue/object-property-newline] ( ./object-property-newline.md ) | enforce placing object properties on separate lines | :wrench : |
399
+ | [ vue/object-shorthand] ( ./object-shorthand.md ) | require or disallow method and property shorthand syntax for object literals | :wrench : |
399
400
| [ vue/operator-linebreak] ( ./operator-linebreak.md ) | enforce consistent linebreak style for operators | :wrench : |
400
401
| [ vue/prefer-template] ( ./prefer-template.md ) | require template literals instead of string concatenation | :wrench : |
401
402
| [ vue/space-in-parens] ( ./space-in-parens.md ) | enforce consistent spacing inside parentheses | :wrench : |
Original file line number Diff line number Diff line change
1
+ ---
2
+ pageClass : rule-details
3
+ sidebarDepth : 0
4
+ title : vue/object-shorthand
5
+ description : require or disallow method and property shorthand syntax for object literals
6
+ ---
7
+ # vue/object-shorthand
8
+
9
+ > require or disallow method and property shorthand syntax for object literals
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
+ - :wrench : The ` --fix ` option on the [ command line] ( https://eslint.org/docs/user-guide/command-line-interface#fixing-problems ) can automatically fix some of the problems reported by this rule.
13
+
14
+ This rule is the same rule as core [ object-shorthand] rule but it applies to the expressions in ` <template> ` .
15
+
16
+ ## :books : Further Reading
17
+
18
+ - [ object-shorthand]
19
+
20
+ [ object-shorthand ] : https://eslint.org/docs/rules/object-shorthand
21
+
22
+ ## :mag : Implementation
23
+
24
+ - [ Rule source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/object-shorthand.js )
25
+ - [ Test source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/object-shorthand.js )
26
+
27
+ <sup >Taken with ❤️ [ from ESLint core] ( https://eslint.org/docs/rules/object-shorthand ) </sup >
Original file line number Diff line number Diff line change @@ -151,6 +151,7 @@ module.exports = {
151
151
'object-curly-newline' : require ( './rules/object-curly-newline' ) ,
152
152
'object-curly-spacing' : require ( './rules/object-curly-spacing' ) ,
153
153
'object-property-newline' : require ( './rules/object-property-newline' ) ,
154
+ 'object-shorthand' : require ( './rules/object-shorthand' ) ,
154
155
'one-component-per-file' : require ( './rules/one-component-per-file' ) ,
155
156
'operator-linebreak' : require ( './rules/operator-linebreak' ) ,
156
157
'order-in-components' : require ( './rules/order-in-components' ) ,
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 { wrapCoreRule } = require ( '../utils' )
8
+
9
+ // eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
10
+ module . exports = wrapCoreRule ( 'object-shorthand' , {
11
+ skipDynamicArguments : true
12
+ } )
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 RuleTester = require ( 'eslint' ) . RuleTester
8
+ const rule = require ( '../../../lib/rules/object-shorthand' )
9
+
10
+ const tester = new RuleTester ( {
11
+ parser : require . resolve ( 'vue-eslint-parser' ) ,
12
+ parserOptions : {
13
+ ecmaVersion : 2020 ,
14
+ sourceType : 'module'
15
+ }
16
+ } )
17
+
18
+ tester . run ( 'object-shorthand' , rule , {
19
+ valid : [
20
+ {
21
+ filename : 'test.vue' ,
22
+ code : `
23
+ <template>
24
+ <div :style="{height}"></div>
25
+ </template>
26
+ `
27
+ } ,
28
+ {
29
+ filename : 'test.vue' ,
30
+ code : `
31
+ <template>
32
+ <div :style="{height: height}"></div>
33
+ </template>
34
+ ` ,
35
+ options : [ 'never' ]
36
+ }
37
+ ] ,
38
+ invalid : [
39
+ {
40
+ filename : 'test.vue' ,
41
+ code : `
42
+ <template>
43
+ <div :style="{height: height}"></div>
44
+ </template>
45
+ ` ,
46
+ output : `
47
+ <template>
48
+ <div :style="{height}"></div>
49
+ </template>
50
+ ` ,
51
+ errors : [
52
+ {
53
+ message : 'Expected property shorthand.' ,
54
+ line : 3 ,
55
+ column : 23
56
+ }
57
+ ]
58
+ } ,
59
+ {
60
+ filename : 'test.vue' ,
61
+ code : `
62
+ <template>
63
+ <div :style="{height}"></div>
64
+ </template>
65
+ ` ,
66
+ output : `
67
+ <template>
68
+ <div :style="{height: height}"></div>
69
+ </template>
70
+ ` ,
71
+ options : [ 'never' ] ,
72
+ errors : [
73
+ {
74
+ message : 'Expected longform property syntax.' ,
75
+ line : 3 ,
76
+ column : 23
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ } )
You can’t perform that action at this time.
0 commit comments