diff --git a/.github/workflows/sqlformat.yml b/.github/workflows/sqlformat.yml index ef5caee..0542637 100644 --- a/.github/workflows/sqlformat.yml +++ b/.github/workflows/sqlformat.yml @@ -14,10 +14,13 @@ 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 @@ -25,37 +28,37 @@ jobs: - 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 72f13f2..527c768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -6,6 +6,7 @@ - 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 diff --git a/Cargo.toml b/Cargo.toml index 582efbf..55f1154 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "sqlformat" -version = "0.2.5" +version = "0.2.6" authors = ["Josh Holmer "] 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" @@ -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]] diff --git a/benches/bench.rs b/benches/bench.rs index b10b315..a461597 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -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, @@ -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(), diff --git a/src/formatter.rs b/src/formatter.rs index 66126d4..ee202c2 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -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