File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,16 +115,29 @@ const printers = {
115115 }
116116 } ,
117117 hasPrettierIgnore ( path ) {
118- const node = path . getNode ( ) ;
119118 const isSimpleIgnore = ( comment ) =>
120119 comment . value . includes ( "prettier-ignore" ) &&
121120 ! comment . value . includes ( "prettier-ignore-start" ) &&
122121 ! comment . value . includes ( "prettier-ignore-end" ) ;
122+
123+ const parentNode = path . getParentNode ( ) ;
124+ const node = path . getNode ( ) ;
125+
123126 return (
124- node &&
125- node . comments &&
126- node . comments . length > 0 &&
127- node . comments . some ( isSimpleIgnore )
127+ ( node &&
128+ node . kind !== "classconstant" &&
129+ node . comments &&
130+ node . comments . length > 0 &&
131+ node . comments . some ( isSimpleIgnore ) ) ||
132+ // For proper formatting, the classconstant ignore formatting should
133+ // run on the "constant" child
134+ ( node &&
135+ node . kind === "constant" &&
136+ parentNode &&
137+ parentNode . kind === "classconstant" &&
138+ parentNode . comments &&
139+ parentNode . comments . length > 0 &&
140+ parentNode . comments . some ( isSimpleIgnore ) )
128141 ) ;
129142 } ,
130143 } ,
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ printWidth: 80
77 | printWidth
88=====================================input======================================
99<?php
10+
11+ // prettier-ignore
12+ define("FOO", "something");
13+
1014// prettier-ignore
1115$var1 = 1;
1216
@@ -39,8 +43,24 @@ function Foo ($veryLongVeryLongVeryLongVeryLongVeryLongVeryLongVeryLong) { retur
3943$info = "prettier-ignore-start and -end is currently not supported" ;
4044// prettier-ignore-end
4145
46+ class ExampleClass {
47+ // prettier-ignore
48+ const SOME_CONST = 1 ;
49+ const ANOTHER_CONST = 2 ;
50+
51+ // prettier-ignore
52+ const CONST_ARRAY = [
53+ ' test' => 0 ,
54+ ' another_key' => 1
55+ ];
56+ }
57+
4258=====================================output=====================================
4359<?php
60+
61+ // prettier-ignore
62+ define("FOO", "something");
63+
4464// prettier-ignore
4565$var1 = 1;
4666
@@ -72,5 +92,18 @@ function Foo ($veryLongVeryLongVeryLongVeryLongVeryLongVeryLongVeryLong) { retur
7292$info = "prettier-ignore-start and -end is currently not supported";
7393// prettier-ignore-end
7494
95+ class ExampleClass
96+ {
97+ // prettier-ignore
98+ const SOME_CONST = 1 ;
99+ const ANOTHER_CONST = 2 ;
100+
101+ // prettier-ignore
102+ const CONST_ARRAY = [
103+ ' test' => 0 ,
104+ ' another_key' => 1
105+ ];
106+ }
107+
75108================================================================================
76109` ;
Original file line number Diff line number Diff line change 11<?php
2+
3+ // prettier-ignore
4+ define ("FOO " , "something " );
5+
26// prettier-ignore
37$ var1 = 1 ;
48
@@ -30,3 +34,15 @@ function Foo ($veryLongVeryLongVeryLongVeryLongVeryLongVeryLongVeryLong) { retur
3034// prettier-ignore-start
3135$ info = "prettier-ignore-start and -end is currently not supported " ;
3236// prettier-ignore-end
37+
38+ class ExampleClass {
39+ // prettier-ignore
40+ const SOME_CONST = 1 ;
41+ const ANOTHER_CONST = 2 ;
42+
43+ // prettier-ignore
44+ const CONST_ARRAY = [
45+ 'test ' => 0 ,
46+ 'another_key ' => 1
47+ ];
48+ }
You can’t perform that action at this time.
0 commit comments