Skip to content

Commit

Permalink
fix: compatibility with older versions of rust compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro committed Sep 6, 2024
1 parent 0742f9e commit 3dfd22a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 45 deletions.
71 changes: 37 additions & 34 deletions .github/workflows/sqlformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,51 @@ jobs:
strategy:
matrix:
conf:
- minimum
- latest-stable
- latest-beta
- latest-nightly
include:
- conf: minimum
toolchain: 1.61.0
- conf: latest-stable
toolchain: stable
- conf: latest-beta
toolchain: beta
- conf: latest-nightly
toolchain: nightly
steps:
- uses: actions/checkout@v2
- name: Install ${{ matrix.toolchain }}
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
components: clippy, rustfmt
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry/cache
key: ${{ runner.os }}-${{ matrix.conf }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.conf }}-cargo-registry-
- name: Run rustfmt
if: matrix.toolchain == 'stable'
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
- name: Run clippy
if: matrix.toolchain == 'stable'
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -- -D warnings
- name: Run tests
run: cargo test
- name: Build benchmarks
if: matrix.toolchain == 'stable'
run: cargo bench --no-run
- name: Build docs
run: cargo doc --no-deps
- uses: actions/checkout@v2
- name: Install ${{ matrix.toolchain }}
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
components: clippy, rustfmt
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry/cache
key: ${{ runner.os }}-${{ matrix.conf }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.conf }}-cargo-registry-
- name: Run rustfmt
if: matrix.toolchain == 'stable'
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
- name: Run clippy
if: matrix.toolchain == 'stable'
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -- -D warnings
- name: Run tests
run: cargo test
- name: Build benchmarks
if: matrix.toolchain == 'stable'
run: cargo bench --no-run
- name: Build docs
run: cargo doc --no-deps
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
### Version 0.2.5
### Version 0.2.6

- fix: ON UPDATE with two many blank formatted incorrectly (#46)
- fix: `EXCEPT` not handled well
- fix: REFERENCES xyz ON UPDATE .. causes formatter to treat the remaining as an UPDATE statement
- fix: Escaped strings formatted incorrectly
- fix: RETURNING is not placed on a new line
- fix: fix the issue of misaligned comments after formatting (#40)
- Update minimum rustc version to 1.61 (this is technically a breaking change, but 1.61 is over 2 years old at this point, so a compromise had to be made)

### Version 0.2.4

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "sqlformat"
version = "0.2.5"
version = "0.2.6"
authors = ["Josh Holmer <[email protected]>"]
edition = "2021"
rust-version = "1.56"
rust-version = "1.61"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/shssoichiro/sqlformat-rs"
repository = "https://github.com/shssoichiro/sqlformat-rs"
Expand All @@ -17,7 +17,7 @@ nom = "7.0.0"
unicode_categories = "0.1.1"

[dev-dependencies]
criterion = "0.5"
criterion = "0.4"
indoc = "2.0"

[[bench]]
Expand Down
2 changes: 0 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ fn issue_633(c: &mut Criterion) {
const SIZE: usize = 1000;

pub struct UserData {
pub id: i64,
pub first_name: String,
pub last_name: String,
pub address: String,
Expand All @@ -87,7 +86,6 @@ fn issue_633(c: &mut Criterion) {

fn sample() -> UserData {
UserData {
id: -1,
first_name: "FIRST_NAME".to_string(),
last_name: "LAST_NAME".to_string(),
address: "SOME_ADDRESS".to_string(),
Expand Down
11 changes: 6 additions & 5 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ impl<'a> Formatter<'a> {
}

fn format_with_spaces(&self, token: &Token<'_>, query: &mut String) {
let value = if token.kind == TokenKind::Reserved {
&self.equalize_whitespace(&self.format_reserved_word(token.value))
if token.kind == TokenKind::Reserved {
let value = self.equalize_whitespace(&self.format_reserved_word(token.value));
query.push_str(&value);
query.push(' ');
} else {
token.value
query.push_str(token.value);
query.push(' ');
};
query.push_str(value);
query.push(' ');
}

// Opening parentheses increase the block indent level and start a new line
Expand Down

0 comments on commit 3dfd22a

Please sign in to comment.