From 750bf55cf735205624c45e6d4958b9c48c45ba78 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Fri, 18 Feb 2022 17:27:21 -0500 Subject: [PATCH] feat: do not indent lambdas with comments --- CHANGELOG.md | 12 ++++++++++++ src/rules/lambda.rs | 3 ++- tests/cases/idioms_lib_1/in | 9 +++++++++ tests/cases/idioms_lib_1/out | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/cases/idioms_lib_1/in create mode 100644 tests/cases/idioms_lib_1/out diff --git a/CHANGELOG.md b/CHANGELOG.md index 75f848f..eb8ca1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,18 @@ Types of changes - with pkgs; + binPath = with pkgs; ``` +- Nested lambdas are now not indented: + + ```diff + # comment + a: + - # comment + - b: + - _ + + # comment + + b: + + _ + ``` ## [0.2.0] - 2022-02-17 diff --git a/src/rules/lambda.rs b/src/rules/lambda.rs index 746839c..b2aab3e 100644 --- a/src/rules/lambda.rs +++ b/src/rules/lambda.rs @@ -79,10 +79,11 @@ pub fn rule( child.element.kind(), rnix::SyntaxKind::NODE_ATTR_SET | rnix::SyntaxKind::NODE_PAREN + | rnix::SyntaxKind::NODE_LAMBDA | rnix::SyntaxKind::NODE_LET_IN | rnix::SyntaxKind::NODE_LIST | rnix::SyntaxKind::NODE_STRING - ) && build_ctx.pos_new.column > 1; + ); if should_indent { steps.push_back(crate::builder::Step::Indent); diff --git a/tests/cases/idioms_lib_1/in b/tests/cases/idioms_lib_1/in new file mode 100644 index 0000000..93ebe7e --- /dev/null +++ b/tests/cases/idioms_lib_1/in @@ -0,0 +1,9 @@ +{ + traceIf = + # Predicate to check + pred: + # Message that should be traced + msg: + # Value to return + x: if pred then trace msg x else x; +} diff --git a/tests/cases/idioms_lib_1/out b/tests/cases/idioms_lib_1/out new file mode 100644 index 0000000..867596f --- /dev/null +++ b/tests/cases/idioms_lib_1/out @@ -0,0 +1,12 @@ +{ + traceIf = + # Predicate to check + pred: + # Message that should be traced + msg: + # Value to return + x: + if pred + then trace msg x + else x; +}