Skip to content

Commit e879554

Browse files
authored
fix: remove broken handling of prettier-ignore-start and -end,… (#1350)
1 parent d102069 commit e879554

4 files changed

Lines changed: 53 additions & 1 deletion

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,40 @@ Prettier for PHP supports the following options:
171171
| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) |
172172
| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) |
173173

174+
## Ignoring code
175+
176+
A comment `// prettier-ignore` will exclude the next node in the abstract syntax tree from formatting.
177+
178+
For example:
179+
180+
```php
181+
matrix(
182+
1, 0, 0,
183+
0, 1, 0,
184+
0, 0, 1
185+
);
186+
187+
// prettier-ignore
188+
matrix(
189+
1, 0, 0,
190+
0, 1, 0,
191+
0, 0, 1
192+
);
193+
```
194+
195+
will be transformed to
196+
197+
```php
198+
matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
199+
200+
// prettier-ignore
201+
matrix(
202+
1, 0, 0,
203+
0, 1, 0,
204+
0, 0, 1
205+
)
206+
```
207+
174208
## Editor integration
175209

176210
### Atom

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ const printers = {
117117
},
118118
hasPrettierIgnore(path) {
119119
const node = path.getNode();
120+
const isSimpleIgnore = comment =>
121+
comment.value.includes("prettier-ignore") &&
122+
!comment.value.includes("prettier-ignore-start") &&
123+
!comment.value.includes("prettier-ignore-end");
120124
return (
121125
node &&
122126
node.comments &&
123127
node.comments.length > 0 &&
124-
node.comments.some(comment => comment.value.includes("prettier-ignore"))
128+
node.comments.some(isSimpleIgnore)
125129
);
126130
}
127131
}

tests/ignore/__snapshots__/jsfmt.spec.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ function Foo ($veryLongVeryLongVeryLongVeryLongVeryLongVeryLongVeryLong) { retur
3434
]
3535
];}
3636
37+
38+
// prettier-ignore-start
39+
$info = "prettier-ignore-start and -end is currently not supported" ;
40+
// prettier-ignore-end
41+
3742
=====================================output=====================================
3843
<?php
3944
// prettier-ignore
@@ -63,5 +68,9 @@ function Foo ($veryLongVeryLongVeryLongVeryLongVeryLongVeryLongVeryLong) { retur
6368
]
6469
];}
6570
71+
// prettier-ignore-start
72+
$info = "prettier-ignore-start and -end is currently not supported";
73+
// prettier-ignore-end
74+
6675
================================================================================
6776
`;

tests/ignore/ignore.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ function Foo ($veryLongVeryLongVeryLongVeryLongVeryLongVeryLongVeryLong) { retur
2525
"php"
2626
]
2727
];}
28+
29+
30+
// prettier-ignore-start
31+
$info = "prettier-ignore-start and -end is currently not supported" ;
32+
// prettier-ignore-end

0 commit comments

Comments
 (0)