@@ -7,7 +7,7 @@ module.exports = {
7
7
} ,
8
8
fixable : 'code' ,
9
9
} ,
10
- create : function ( context ) {
10
+ create : function ( context ) {
11
11
return {
12
12
ObjectExpression ( node ) {
13
13
// Not adding __proto__ to module.exports as it will break a lot of libraries
@@ -44,12 +44,23 @@ module.exports = {
44
44
context . report ( {
45
45
node,
46
46
message : 'Every object must have __proto__: null' ,
47
- fix : function ( fixer ) {
47
+ fix : function ( fixer ) {
48
48
// Generate the fix suggestion to add __proto__: null
49
49
const sourceCode = context . getSourceCode ( ) ;
50
50
const firstProperty = properties [ 0 ] ;
51
51
const firstPropertyToken = sourceCode . getFirstToken ( firstProperty ) ;
52
- const fixText = '__proto__: null, ' ;
52
+
53
+ let fixText = `__proto__: null` ;
54
+
55
+ if ( properties . length > 1 ) {
56
+ fixText += ',' ;
57
+
58
+ if ( properties [ 0 ] . loc . start . line !== properties [ 1 ] . loc . start . line ) {
59
+ fixText += '\n' ;
60
+ } else {
61
+ fixText += ' ' ;
62
+ }
63
+ }
53
64
54
65
// Insert the fix suggestion before the first property
55
66
return fixer . insertTextBefore ( firstPropertyToken , fixText ) ;
@@ -62,7 +73,7 @@ module.exports = {
62
73
context . report ( {
63
74
node,
64
75
message : 'Every empty object must have __proto__: null' ,
65
- fix : function ( fixer ) {
76
+ fix : function ( fixer ) {
66
77
// Generate the fix suggestion to create the object with __proto__: null
67
78
const fixText = '{ __proto__: null }' ;
68
79
0 commit comments