Skip to content

Commit

Permalink
chore: move to stable for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed Sep 28, 2024
1 parent 2ebd276 commit b1dac16
Show file tree
Hide file tree
Showing 155 changed files with 6,090 additions and 2,469 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: cargo r -F codegen-docs
- uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand All @@ -21,6 +21,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: cargo r --bin sqruff -F codegen-docs
- run: git diff --quiet || exit 1
13 changes: 6 additions & 7 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: cargo check --all --all-features --tests --benches
compile:
name: Compile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --locked --release --all-features
compile-wasm:
name: Compile wasm32-unknown-unknown
Expand Down Expand Up @@ -73,15 +73,14 @@ jobs:
cache: "pnpm"
- run: pnpm install --frozen-lockfile
- uses: dtolnay/rust-toolchain@nightly
- run: rustup component add rust-src --toolchain nightly-2024-07-22-x86_64-unknown-linux-gnu
- run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run: pnpm run ci
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@nextest
- name: Run tests
Expand All @@ -93,7 +92,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run benchmarks
run: cargo run --color=always --bin bench --manifest-path ./crates/cli/Cargo.toml
Expand All @@ -104,7 +103,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Checkout sources
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run cargo fmt
Expand All @@ -116,7 +115,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-hack
- uses: taiki-e/install-action@cargo-machete
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Checkout sources
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
node-version-file: ".nvmrc"
cache: "pnpm"
- run: pnpm install --frozen-lockfile
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
- run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run: cd editors/code && pnpm run build
- run: cd editors/code && pnpm run package
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
with:
command: build
target: ${{ matrix.platform.target }}
toolchain: nightly
toolchain: stable
args: --locked --release
strip: true
- name: Package as archive
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repository.workspace = true
edition.workspace = true
license.workspace = true
default-run = "sqruff"
rust-version = "1.81.0"

[lints]
workspace = true
Expand Down
12 changes: 10 additions & 2 deletions crates/cli/src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ use std::process::Command;
use std::time::Instant;

fn main() {
Command::new("cargo").args(["build", "--release"]).status().unwrap();
Command::new("cargo")
.args(["build", "--release"])
.status()
.unwrap();

let start = Instant::now();

let output = Command::new("target/release/sqruff")
.args(["lint", "crates/lib-dialects/test/fixtures/dialects/ansi", "-f", "human"])
.args([
"lint",
"crates/lib-dialects/test/fixtures/dialects/ansi",
"-f",
"human",
])
.output()
.expect("Failed to execute process");

Expand Down
6 changes: 5 additions & 1 deletion crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub(crate) enum Format {

impl Default for Format {
fn default() -> Self {
if is_in_github_action() { Format::GithubAnnotationNative } else { Format::Human }
if is_in_github_action() {
Format::GithubAnnotationNative
} else {
Format::Human
}
}
}
40 changes: 31 additions & 9 deletions crates/cli/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ pub(crate) fn codegen_docs() {
// Rules Docs
let mut env = Environment::new();
let crate_dir = env!("CARGO_MANIFEST_DIR");
let template_path =
Path::new(crate_dir).join("src").join("docs").join("generate_rule_docs_template.md");
let template_path = Path::new(crate_dir)
.join("src")
.join("docs")
.join("generate_rule_docs_template.md");
let template = std::fs::read_to_string(template_path).expect("Failed to read template file");
env.add_template("rules", &template).unwrap();

Expand All @@ -30,22 +32,35 @@ pub(crate) fn codegen_docs() {
let rules = rules.into_iter().map(Rule::from).collect::<Vec<_>>();
let file_rules = std::fs::File::create("docs/rules.md").unwrap();
let mut writer = std::io::BufWriter::new(file_rules);
writer.write_all(tmpl.render(context!(rules => rules)).unwrap().as_bytes()).unwrap();
writer
.write_all(tmpl.render(context!(rules => rules)).unwrap().as_bytes())
.unwrap();

// Templaters Docs
let mut env = Environment::new();
let crate_dir = env!("CARGO_MANIFEST_DIR");
let template_path =
Path::new(crate_dir).join("src").join("docs").join("generate_templater_docs_template.md");
let template_path = Path::new(crate_dir)
.join("src")
.join("docs")
.join("generate_templater_docs_template.md");
let template = std::fs::read_to_string(template_path).expect("Failed to read template file");
env.add_template("templaters", &template).unwrap();

let tmpl = env.get_template("templaters").unwrap();
let templater = templaters();
let templaters = templater.into_iter().map(Templater::from).collect::<Vec<_>>();
let templaters = templater
.into_iter()
.map(Templater::from)
.collect::<Vec<_>>();
let file_templaters = std::fs::File::create("docs/templaters.md").unwrap();
let mut writer = std::io::BufWriter::new(file_templaters);
writer.write_all(tmpl.render(context!(templaters => templaters)).unwrap().as_bytes()).unwrap();
writer
.write_all(
tmpl.render(context!(templaters => templaters))
.unwrap()
.as_bytes(),
)
.unwrap();
}

#[derive(Debug, Clone, Serialize)]
Expand All @@ -56,7 +71,10 @@ struct Templater {

impl From<Box<dyn sqruff_lib::templaters::Templater>> for Templater {
fn from(value: Box<dyn sqruff_lib::templaters::Templater>) -> Self {
Templater { name: value.name(), description: value.description() }
Templater {
name: value.name(),
description: value.description(),
}
}
}

Expand Down Expand Up @@ -84,7 +102,11 @@ impl From<ErasedRule> for Rule {
long_description: value.long_description(),
groups: value.groups().iter().map(|g| g.as_ref()).collect(),
has_dialects: !value.dialect_skip().is_empty(),
dialects: value.dialect_skip().iter().map(|dialect| dialect.as_ref()).collect(),
dialects: value
.dialect_skip()
.iter()
.map(|dialect| dialect.as_ref())
.collect(),
}
}
}
29 changes: 24 additions & 5 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ mod github_action;
#[cfg(all(
not(target_os = "windows"),
not(target_os = "openbsd"),
any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")
any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "powerpc64"
)
))]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
Expand Down Expand Up @@ -70,14 +74,23 @@ fn main() {
linter.formatter_mut().unwrap().completion_message();

std::process::exit(
if linter.formatter().unwrap().has_fail.load(std::sync::atomic::Ordering::SeqCst) {
if linter
.formatter()
.unwrap()
.has_fail
.load(std::sync::atomic::Ordering::SeqCst)
{
1
} else {
0
},
)
}
Commands::Fix(FixArgs { paths, force, format }) => {
Commands::Fix(FixArgs {
paths,
force,
format,
}) => {
let mut linter = linter(config, format);
let result = linter.lint_paths(paths, true);

Expand All @@ -87,7 +100,11 @@ fn main() {
.map(|path| path.files.iter().all(|file| file.violations.is_empty()))
.all(|v| v)
{
let count_files = result.paths.iter().map(|path| path.files.len()).sum::<usize>();
let count_files = result
.paths
.iter()
.map(|path| path.files.len())
.sum::<usize>();
println!("{} files processed, nothing to fix.", count_files);
return;
}
Expand Down Expand Up @@ -138,7 +155,9 @@ fn check_user_input() -> Option<bool> {
use std::io::Write;

let mut term = console::Term::stdout();
_ = term.write(b"Are you sure you wish to attempt to fix these? [Y/n] ").unwrap();
_ = term
.write(b"Are you sure you wish to attempt to fix these? [Y/n] ")
.unwrap();
term.flush().unwrap();

let ret = match term.read_char().unwrap().to_ascii_lowercase() {
Expand Down
6 changes: 5 additions & 1 deletion crates/cli/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use assert_cmd::Command;
use expect_test::expect_file;

fn main() {
let profile = if cfg!(debug_assertions) { "debug" } else { "release" };
let profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
test_dir.push("tests/ui");

Expand Down
28 changes: 21 additions & 7 deletions crates/lib-core/src/dialects/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ impl PartialEq for Dialect {

impl Dialect {
pub fn new() -> Self {
Dialect { name: DialectKind::Ansi, ..Default::default() }
Dialect {
name: DialectKind::Ansi,
..Default::default()
}
}

pub fn name(&self) -> DialectKind {
Expand All @@ -45,7 +48,11 @@ impl Dialect {
}

pub fn grammar(&self, name: &str) -> Matchable {
match self.library.get(name).unwrap_or_else(|| panic!("not found {name}")) {
match self
.library
.get(name)
.unwrap_or_else(|| panic!("not found {name}"))
{
DialectElementType::Matchable(matchable) => matchable.clone(),
DialectElementType::SegmentGenerator(_) => {
unreachable!("Attempted to fetch non grammar [{name}] with `Dialect::grammar`.")
Expand Down Expand Up @@ -109,8 +116,10 @@ impl Dialect {
panic!("Lexer struct must be defined before it can be patched!");
}

let patch_dict: AHashMap<&'static str, Matcher> =
lexer_patch.into_iter().map(|elem| (elem.name(), elem)).collect();
let patch_dict: AHashMap<&'static str, Matcher> = lexer_patch
.into_iter()
.map(|elem| (elem.name(), elem))
.collect();

for elem in self.lexer_matchers.take().unwrap() {
if let Some(patch) = patch_dict.get(elem.name()) {
Expand Down Expand Up @@ -166,7 +175,10 @@ impl Dialect {
"Invalid bracket set. Consider using another identifier instead."
);

self.bracket_collections.get(label).cloned().unwrap_or_default()
self.bracket_collections
.get(label)
.cloned()
.unwrap_or_default()
}

pub fn bracket_sets_mut(&mut self, label: &'static str) -> &mut AHashSet<BracketPair> {
Expand Down Expand Up @@ -229,8 +241,10 @@ impl Dialect {
if !self.library.contains_key(n.as_str()) {
let parser = StringParser::new(&kw.to_lowercase(), SyntaxKind::Keyword);

self.library
.insert(n.into(), DialectElementType::Matchable(parser.to_matchable()));
self.library.insert(
n.into(),
DialectElementType::Matchable(parser.to_matchable()),
);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/lib-core/src/dialects/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::parser::segments::base::ErasedSegment;

/// Details about a table alias.
#[derive(Debug, Eq, Hash, Clone)]
#[allow(clippy::field_reassign_with_default, clippy::derived_hash_with_manual_eq)]
#[allow(
clippy::field_reassign_with_default,
clippy::derived_hash_with_manual_eq
)]
pub struct AliasInfo {
/// Name given to the alias
pub ref_str: SmolStr,
Expand Down
6 changes: 4 additions & 2 deletions crates/lib-core/src/dialects/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use strum_macros::AsRefStr;
PartialOrd,
Eq,
PartialEq,
Hash
Hash,
)]
#[strum(serialize_all = "snake_case")]
pub enum DialectKind {
Expand All @@ -33,7 +33,9 @@ pub enum DialectKind {

/// Generate a readout of available dialects.
pub fn dialect_readout() -> Vec<String> {
DialectKind::iter().map(|x| x.as_ref().to_string()).collect()
DialectKind::iter()
.map(|x| x.as_ref().to_string())
.collect()
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit b1dac16

Please sign in to comment.