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 6928bb3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 53 deletions.
77 changes: 43 additions & 34 deletions .github/workflows/sqlformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,57 @@ jobs:
strategy:
matrix:
conf:
- minimum
- latest-stable
- latest-beta
- latest-nightly
include:
- conf: minimum
toolchain: 1.62.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
# FIXME: criterion and its dependencies require a newer version than 1.62, but it is only used for benchmarks.
# Is there a way to not have criterion built when we run tests?
- name: Run cargo check
if: matrix.toolchain == '1.62.0'
run: cargo check
- name: Run tests
if: matrix.toolchain != '1.62.0'
run: cargo test
- name: Build benchmarks
if: matrix.toolchain == 'stable'
run: cargo bench --no-run
- name: Build docs
run: cargo doc --no-deps
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Version 0.2.5
### Version 0.2.6

- fix: ON UPDATE with two many blank formatted incorrectly (#46)
- fix: `EXCEPT` not handled well
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 <jholmer.in@gmail.com>"]
edition = "2021"
rust-version = "1.56"
rust-version = "1.62"
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
13 changes: 7 additions & 6 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 Expand Up @@ -248,7 +249,7 @@ impl<'a> Formatter<'a> {
}

fn trim_spaces_end(&self, query: &mut String) {
query.truncate(query.trim_end_matches(|c| c == ' ' || c == '\t').len());
query.truncate(query.trim_end_matches([' ', '\t']).len());
}

fn trim_all_spaces_end(&self, query: &mut String) {
Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ pub enum Indent {
Tabs,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub enum QueryParams {
Named(Vec<(String, String)>),
Indexed(Vec<String>),
#[default]
None,
}

impl Default for QueryParams {
fn default() -> Self {
QueryParams::None
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 6928bb3

Please sign in to comment.