Skip to content

Commit

Permalink
feat: slight output improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed Nov 27, 2024
1 parent ecd0cca commit 857fd7c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
22 changes: 9 additions & 13 deletions crates/lib/src/utils/reflow/respace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ pub fn handle_respace_inline_with_space(
if (matches!(post_constraint, Spacing::Align { .. }) && next_block.is_some())
|| pre_constraint == Spacing::Single && post_constraint == Spacing::Single
{
let mut desired_space;
let mut desc;

match (post_constraint, next_block) {
let (desc, desired_space) = match (post_constraint, next_block) {
(
Spacing::Align {
seg_type,
Expand All @@ -395,11 +392,8 @@ pub fn handle_respace_inline_with_space(
None
};

desired_space = " ".to_string();
desc = "TODO".to_string();

if let Some(next_pos) = next_pos {
desired_space = determine_aligned_inline_spacing(
let desired_space = determine_aligned_inline_spacing(
root_segment,
&last_whitespace,
next_block.segments.first().unwrap(),
Expand All @@ -408,12 +402,13 @@ pub fn handle_respace_inline_with_space(
within,
scope,
);

desc = "TODO".to_string();
("Item misaligned".to_string(), desired_space)
} else {
("Item misaligned".to_string(), " ".to_string())
}
}
_ => {
desc = if let Some(next_block) = next_block {
let desc = if let Some(next_block) = next_block {
format!(
"Expected only single space before {:?}. Found {:?}.",
&next_block.segments[0].raw(),
Expand All @@ -425,9 +420,10 @@ pub fn handle_respace_inline_with_space(
last_whitespace.raw()
)
};
desired_space = " ".to_string();
let desired_space = " ".to_string();
(desc, desired_space)
}
}
};

let mut new_results = Vec::new();
if last_whitespace.raw().as_str() != desired_space {
Expand Down
33 changes: 33 additions & 0 deletions docs/sample_configurations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Sample Configurations

The followbng document outlines sample configurations that may be used to achieve certain formattting/linting outcomes.

## Alinging AS statements

Suppose you want to align as statements in a `select` to return the following outcome.

```sql
--before
select
aaaa as a,
bbb as b,
cc as c
from table;

--after
select
aaaa as a,
bbb as b,
cc as c
from table
```

This can be achieved withe following configuration addition:

```
[sqruff:layout:type:alias_expression]
spacing_before = align
align_within = select_clause
align_scope = bracketed
```

0 comments on commit 857fd7c

Please sign in to comment.