Skip to content

Commit be126c4

Browse files
authored
Merge pull request #125 from ony3000/fix-astro
Fix line wrapping inside callback function
2 parents 3441f4a + d842fba commit be126c4

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

src/core-parts/finder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,6 +2461,7 @@ export function findTargetClassNameNodesForAstro(
24612461
recursiveProps = ['attributes', 'children'];
24622462
break;
24632463
}
2464+
case 'expression':
24642465
case 'fragment':
24652466
case 'root': {
24662467
recursiveProps = ['children'];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`'(1) JSX inside the callback function …' > expectation 1`] = `
4+
"---
5+
// example.astro
6+
const navigation = [
7+
{ name: "Home", href: "/" },
8+
{ name: "About", href: "/about" },
9+
];
10+
---
11+
12+
<!-- ---------------------------------------------------------------------------| printWidth=80 (in snapshot) -->
13+
<nav class="flex space-x-2">
14+
{
15+
navigation.map((item) => (
16+
<a
17+
href={item.href}
18+
class="hover:[#363636]/80 bg-[#363636] px-3 py-1 font-bold text-zinc-300
19+
transition-[border-radius,colors,background-colors] duration-300
20+
hover:rounded-2xl hover:text-zinc-200 sm:px-4 sm:py-1.5 sm:text-lg"
21+
>
22+
{item.name}
23+
</a>
24+
))
25+
}
26+
</nav>
27+
"
28+
`;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`'(1) JSX inside the callback function …' > expectation 1`] = `
4+
"---
5+
// example.astro
6+
const navigation = [
7+
{ name: "Home", href: "/" },
8+
{ name: "About", href: "/about" },
9+
];
10+
---
11+
12+
<!-- ---------------------------------------------------------------------------| printWidth=80 (in snapshot) -->
13+
<nav class="flex space-x-2">
14+
{
15+
navigation.map((item) => (
16+
<a
17+
href={item.href}
18+
class="hover:[#363636]/80 bg-[#363636] px-3 py-1 font-bold text-zinc-300
19+
transition-[border-radius,colors,background-colors] duration-300
20+
hover:rounded-2xl hover:text-zinc-200 sm:px-4 sm:py-1.5 sm:text-lg"
21+
>
22+
{item.name}
23+
</a>
24+
))
25+
}
26+
</nav>
27+
"
28+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { thisPlugin, testSnapshotEach } from '../../adaptor';
2+
import { baseOptions } from '../../settings';
3+
import { fixtures } from './fixtures';
4+
5+
const options = {
6+
...baseOptions,
7+
plugins: ['prettier-plugin-astro', thisPlugin],
8+
parser: 'astro',
9+
endingPosition: 'absolute',
10+
};
11+
12+
testSnapshotEach(fixtures, options);

tests/astro/issue-123/fixtures.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Fixture } from '../../settings';
2+
3+
export const fixtures: Omit<Fixture, 'output'>[] = [
4+
{
5+
name: '(1) JSX inside the callback function must also be wrapped.',
6+
input: `
7+
---
8+
// example.astro
9+
const navigation = [
10+
{ name: "Home", href: "/" },
11+
{ name: "About", href: "/about" },
12+
];
13+
---
14+
15+
<!-- ---------------------------------------------------------------------------| printWidth=80 (in snapshot) -->
16+
<nav class="flex space-x-2">
17+
{
18+
navigation.map((item) => (
19+
<a
20+
href={item.href}
21+
class="hover:[#363636]/80 bg-[#363636] px-3 py-1 font-bold text-zinc-300 transition-[border-radius,colors,background-colors] duration-300 hover:rounded-2xl hover:text-zinc-200 sm:px-4 sm:py-1.5 sm:text-lg"
22+
>
23+
{item.name}
24+
</a>
25+
))
26+
}
27+
</nav>
28+
`,
29+
},
30+
];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { thisPlugin, testSnapshotEach } from '../../adaptor';
2+
import { baseOptions } from '../../settings';
3+
import { fixtures } from './fixtures';
4+
5+
const options = {
6+
...baseOptions,
7+
plugins: ['prettier-plugin-astro', thisPlugin],
8+
parser: 'astro',
9+
endingPosition: 'relative',
10+
};
11+
12+
testSnapshotEach(fixtures, options);

0 commit comments

Comments
 (0)