Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Bugfix: Fix indentation for chained method #88

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/print/CallExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ const printCallExpression = (node, path, print) => {
// there is exactly one object parameter
parts.push(mappedArguments[0], ")");
} else {
parts.push(
indent([softline, join([",", line], mappedArguments)]),
softline,
")"
);
parts.push(indent([join([", "], mappedArguments)]), ")");
}

wrapExpressionIfNeeded(path, parts, node);
Expand Down
4 changes: 2 additions & 2 deletions src/print/MemberExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
wrapExpressionIfNeeded
} from "../util/index.js";

const { group } = doc.builders;
const { group, indent, softline } = doc.builders;

const printMemberExpression = (node, path, print) => {
node[EXPRESSION_NEEDED] = false;
node[STRING_NEEDS_QUOTES] = true;
const parts = [path.call(print, "object")];
parts.push(node.computed ? "[" : ".");
parts.push(node.computed ? "[" : indent([softline, "."]));
parts.push(path.call(print, "property"));
if (node.computed) {
parts.push("]");
Expand Down
25 changes: 25 additions & 0 deletions tests/Expressions/__snapshots__/chain_indentation.snap.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<a
class="task-edit"
href="{{
ea_url()
.setDashboard('App\\Controller\\Dashboard\\DashboardController')
.setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController')
.setAction('edit')
.setEntityId(tache.id)
.set('sort', null)
}}"
>
<i class="fa-solid fa-edit"></i>
</a>

{{
craft
.entries
.section('news')
.section('news')
.orderBy('postDate DESC')
.limit(10)
.all(a.b)
}}

{{ craft.entries.all() }}
26 changes: 26 additions & 0 deletions tests/Expressions/chain_indentation.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<a class="task-edit"
href="{{
ea_url().setDashboard(
'App\\Controller\\Dashboard\\DashboardController'
).setController(
'App\\Controller\\Dashboard\\CRUD\\TacheCrudController'
).setAction(
'edit'
).setEntityId(
tache.id
).set(
'sort',
null
)
}}">
<i class="fa-solid fa-edit"></i>
</a>

{{ craft.entries
.section("news")
.section("news")
.orderBy("postDate DESC")
.limit(10)
.all(a.b) }}

{{ craft.entries.all() }}
10 changes: 10 additions & 0 deletions tests/Expressions/jsfmt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "callExpression.twig"
});
await expect(actual).toMatchFileSnapshot(snapshotFile);

Check failure on line 27 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (18)

tests/Expressions/jsfmt.spec.js > Expressions > should handle call expressions

Error: Snapshot `Expressions > should handle call expressions 1` mismatched - Expected + Received @@ -8,14 +8,12 @@ <span class="{{ css.partner }}"> <div> <div> {{ - helpers.partner( - cheapestPrice.group.groupId, - cheapestPrice.name.value - ) + helpers.partner(cheapestPrice.group.groupId, cheapestPrice.name + .value) }} </div> </div> </span> @@ -31,7 +29,8 @@ {{ craft.someCoolObject.someMethodToUse({ foo: 'bar', bar: 'baz', baz: 'foo' - }).all() + }) + .all() }} ❯ tests/Expressions/jsfmt.spec.js:27:9

Check failure on line 27 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (20)

tests/Expressions/jsfmt.spec.js > Expressions > should handle call expressions

Error: Snapshot `Expressions > should handle call expressions 1` mismatched - Expected + Received @@ -8,14 +8,12 @@ <span class="{{ css.partner }}"> <div> <div> {{ - helpers.partner( - cheapestPrice.group.groupId, - cheapestPrice.name.value - ) + helpers.partner(cheapestPrice.group.groupId, cheapestPrice.name + .value) }} </div> </div> </span> @@ -31,7 +29,8 @@ {{ craft.someCoolObject.someMethodToUse({ foo: 'bar', bar: 'baz', baz: 'foo' - }).all() + }) + .all() }} ❯ tests/Expressions/jsfmt.spec.js:27:9

Check failure on line 27 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (22)

tests/Expressions/jsfmt.spec.js > Expressions > should handle call expressions

Error: Snapshot `Expressions > should handle call expressions 1` mismatched - Expected + Received @@ -8,14 +8,12 @@ <span class="{{ css.partner }}"> <div> <div> {{ - helpers.partner( - cheapestPrice.group.groupId, - cheapestPrice.name.value - ) + helpers.partner(cheapestPrice.group.groupId, cheapestPrice.name + .value) }} </div> </div> </span> @@ -31,7 +29,8 @@ {{ craft.someCoolObject.someMethodToUse({ foo: 'bar', bar: 'baz', baz: 'foo' - }).all() + }) + .all() }} ❯ tests/Expressions/jsfmt.spec.js:27:9
});
it("should handle conditional expressions", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
Expand All @@ -42,7 +42,7 @@
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "mappingExpression.twig"
});
await expect(actual).toMatchFileSnapshot(snapshotFile);

Check failure on line 45 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (18)

tests/Expressions/jsfmt.spec.js > Expressions > should handle mapping expressions

Error: Snapshot `Expressions > should handle mapping expressions 1` mismatched - Expected + Received @@ -62,11 +62,12 @@ success: 'alert-success', warning: 'alert-warning', error: 'alert-error' } } - }).apply({ + }) + .apply({ theme }) }) }} ></div> ❯ tests/Expressions/jsfmt.spec.js:45:9

Check failure on line 45 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (20)

tests/Expressions/jsfmt.spec.js > Expressions > should handle mapping expressions

Error: Snapshot `Expressions > should handle mapping expressions 1` mismatched - Expected + Received @@ -62,11 +62,12 @@ success: 'alert-success', warning: 'alert-warning', error: 'alert-error' } } - }).apply({ + }) + .apply({ theme }) }) }} ></div> ❯ tests/Expressions/jsfmt.spec.js:45:9

Check failure on line 45 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (22)

tests/Expressions/jsfmt.spec.js > Expressions > should handle mapping expressions

Error: Snapshot `Expressions > should handle mapping expressions 1` mismatched - Expected + Received @@ -62,11 +62,12 @@ success: 'alert-success', warning: 'alert-warning', error: 'alert-error' } } - }).apply({ + }) + .apply({ theme }) }) }} ></div> ❯ tests/Expressions/jsfmt.spec.js:45:9
});
it("should handle member expressions", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
Expand Down Expand Up @@ -91,4 +91,14 @@
});
await expect(actual).toMatchFileSnapshot(snapshotFile);
});

it("Properly indent chain method", async () => {
const { actual, snapshotFile } = await run_spec(import.meta.url, {
source: "chain_indentation.twig",
formatOptions: {
experimentalMethodChainIndentation: true
}
});
await expect(actual).toMatchFileSnapshot(snapshotFile);

Check failure on line 102 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (18)

tests/Expressions/jsfmt.spec.js > Expressions > Properly indent chain method

Error: Snapshot `Expressions > Properly indent chain method 1` mismatched - Expected + Received <a class="task-edit" href="{{ - ea_url() - .setDashboard('App\\Controller\\Dashboard\\DashboardController') - .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController') - .setAction('edit') - .setEntityId(tache.id) - .set('sort', null) + ea_url().setDashboard('App\\Controller\\Dashboard\\DashboardController') + .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController') + .setAction('edit') + .setEntityId(tache.id) + .set('sort', null) }}" > <i class="fa-solid fa-edit"></i> </a> {{ - craft - .entries - .section('news') - .section('news') - .orderBy('postDate DESC') + craft.entries.section('news').section('news').orderBy('postDate DESC') .limit(10) .all(a.b) }} {{ craft.entries.all() }} ❯ tests/Expressions/jsfmt.spec.js:102:9

Check failure on line 102 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (20)

tests/Expressions/jsfmt.spec.js > Expressions > Properly indent chain method

Error: Snapshot `Expressions > Properly indent chain method 1` mismatched - Expected + Received <a class="task-edit" href="{{ - ea_url() - .setDashboard('App\\Controller\\Dashboard\\DashboardController') - .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController') - .setAction('edit') - .setEntityId(tache.id) - .set('sort', null) + ea_url().setDashboard('App\\Controller\\Dashboard\\DashboardController') + .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController') + .setAction('edit') + .setEntityId(tache.id) + .set('sort', null) }}" > <i class="fa-solid fa-edit"></i> </a> {{ - craft - .entries - .section('news') - .section('news') - .orderBy('postDate DESC') + craft.entries.section('news').section('news').orderBy('postDate DESC') .limit(10) .all(a.b) }} {{ craft.entries.all() }} ❯ tests/Expressions/jsfmt.spec.js:102:9

Check failure on line 102 in tests/Expressions/jsfmt.spec.js

View workflow job for this annotation

GitHub Actions / Test (22)

tests/Expressions/jsfmt.spec.js > Expressions > Properly indent chain method

Error: Snapshot `Expressions > Properly indent chain method 1` mismatched - Expected + Received <a class="task-edit" href="{{ - ea_url() - .setDashboard('App\\Controller\\Dashboard\\DashboardController') - .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController') - .setAction('edit') - .setEntityId(tache.id) - .set('sort', null) + ea_url().setDashboard('App\\Controller\\Dashboard\\DashboardController') + .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController') + .setAction('edit') + .setEntityId(tache.id) + .set('sort', null) }}" > <i class="fa-solid fa-edit"></i> </a> {{ - craft - .entries - .section('news') - .section('news') - .orderBy('postDate DESC') + craft.entries.section('news').section('news').orderBy('postDate DESC') .limit(10) .all(a.b) }} {{ craft.entries.all() }} ❯ tests/Expressions/jsfmt.spec.js:102:9
});
});
Loading