Skip to content

Commit

Permalink
internal: add [workspace.lints.rust] to workspace Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
gvozdvmozgu authored and benfdking committed Sep 21, 2024
1 parent 02da258 commit c7f795a
Show file tree
Hide file tree
Showing 32 changed files with 79 additions and 48 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ license = "Apache-2.0"
members = ["crates/*"]
resolver = "2"

[workspace.lints.rust]
unreachable_pub = "warn"
unused_qualifications = "warn"

# https://github.com/rustwasm/wasm-bindgen/issues/3451#issuecomment-1562982835
[profile.dev]
opt-level = "s"
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition.workspace = true
license.workspace = true
default-run = "sqruff"

[lints]
workspace = true

[[bin]]
name = "bench"
path = "src/bin/bench.rs"
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::{Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[command(name = "sqruff")]
#[command(about = "sqruff is a sql formatter and linter", long_about = None, version=env!("CARGO_PKG_VERSION"))]
pub struct Cli {
pub(crate) struct Cli {
#[command(subcommand)]
pub command: Commands,
/// Path to a configuration file.
Expand All @@ -14,7 +14,7 @@ pub struct Cli {
}

#[derive(Debug, Subcommand)]
pub enum Commands {
pub(crate) enum Commands {
#[command(name = "lint", about = "lint files")]
Lint(LintArgs),
#[command(name = "fix", about = "fix files")]
Expand All @@ -24,14 +24,14 @@ pub enum Commands {
}

#[derive(Debug, Parser)]
pub struct LintArgs {
pub(crate) struct LintArgs {
pub paths: Vec<PathBuf>,
#[arg(default_value = "human", short, long)]
pub format: Format,
}

#[derive(Debug, Parser)]
pub struct FixArgs {
pub(crate) struct FixArgs {
pub paths: Vec<PathBuf>,
/// Skip the confirmation prompt and go straight to applying fixes.
#[arg(long)]
Expand All @@ -41,7 +41,7 @@ pub struct FixArgs {
}

#[derive(Debug, Default, Clone, Copy, ValueEnum)]
pub enum Format {
pub(crate) enum Format {
#[default]
Human,
GithubAnnotationNative,
Expand Down
3 changes: 3 additions & 0 deletions crates/lib-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ repository.workspace = true
edition.workspace = true
license.workspace = true

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

Expand Down
4 changes: 2 additions & 2 deletions crates/lib-core/src/parser/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::segments::base::ErasedSegment;

pub fn join_segments_raw(segments: &[ErasedSegment]) -> String {
pub(crate) fn join_segments_raw(segments: &[ErasedSegment]) -> String {
segments.iter().map(|s| s.raw()).collect::<Vec<_>>().concat()
}

pub fn check_still_complete(
pub(crate) fn check_still_complete(
segments_in: &[ErasedSegment],
matched_segments: &[ErasedSegment],
unmatched_segments: &[ErasedSegment],
Expand Down
3 changes: 3 additions & 0 deletions crates/lib-dialects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ repository.workspace = true
edition.workspace = true
license.workspace = true

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/ansi_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A list of all SQL keywords.

pub const ANSI_RESERVED_KEYWORDS: &str = "SELECT
pub(crate) const ANSI_RESERVED_KEYWORDS: &str = "SELECT
JOIN
ON
USING
Expand All @@ -24,7 +24,7 @@ SET
NATURAL
";

pub const ANSI_UNRESERVED_KEYWORDS: &str = "ABORT
pub(crate) const ANSI_UNRESERVED_KEYWORDS: &str = "ABORT
ABS
ABSOLUTE
ACCESS
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/athena_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const ATHENA_RESERVED_KEYWORDS: &[&str] = &[
pub(crate) const ATHENA_RESERVED_KEYWORDS: &[&str] = &[
"ALL",
"ALTER",
"AND",
Expand Down Expand Up @@ -131,7 +131,7 @@ pub const ATHENA_RESERVED_KEYWORDS: &[&str] = &[
"WITH",
];

pub const ATHENA_UNRESERVED_KEYWORDS: &[&str] = &[
pub(crate) const ATHENA_UNRESERVED_KEYWORDS: &[&str] = &[
"ABORT",
"ADD",
"ADMIN",
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/bigquery_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const BIGQUERY_RESERVED_KEYWORDS: &str = r#"ALL
pub(crate) const BIGQUERY_RESERVED_KEYWORDS: &str = r#"ALL
AND
ANY
ARRAY
Expand Down Expand Up @@ -95,7 +95,7 @@ WINDOW
WITH
WITHIN"#;

pub const BIGQUERY_UNRESERVED_KEYWORDS: &str = r#"ACCOUNT
pub(crate) const BIGQUERY_UNRESERVED_KEYWORDS: &str = r#"ACCOUNT
ADD
ADMIN
AFTER
Expand Down
2 changes: 1 addition & 1 deletion crates/lib-dialects/src/clickhouse_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const UNRESERVED_KEYWORDS: &[&str] = &[
pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[
"ADD",
"AFTER",
"ALIAS",
Expand Down
6 changes: 3 additions & 3 deletions crates/lib-dialects/src/postgres_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn priority_keyword_merge(
base_list
}

pub fn get_keywords(
pub(crate) fn get_keywords(
keyword_list: &[(&'static str, &'static str)],
keyword_type: &str,
) -> Vec<&'static str> {
Expand Down Expand Up @@ -969,7 +969,7 @@ const POSTGRES_NONDOCS_KEYWORDS: &[(&str, &str)] = &[
("WAL", "non-reserved"),
];

pub const POSTGRES_POSTGIS_DATATYPE_KEYWORDS: &[(&str, &str)] = &[
pub(crate) const POSTGRES_POSTGIS_DATATYPE_KEYWORDS: &[(&str, &str)] = &[
("POINT", "non-reserved"),
("LINESTRING", "non-reserved"),
("POLYGON", "non-reserved"),
Expand Down Expand Up @@ -1011,7 +1011,7 @@ pub const POSTGRES_POSTGIS_DATATYPE_KEYWORDS: &[(&str, &str)] = &[
const POSTGRES_POSTGIS_OTHER_KEYWORDS: &[(&str, &str)] =
&[("GEOMETRY", "non-reserved"), ("GEOGRAPHY", "non-reserved"), ("EMPTY", "non-reserved")];

pub fn postgres_keywords() -> Vec<(&'static str, &'static str)> {
pub(crate) fn postgres_keywords() -> Vec<(&'static str, &'static str)> {
priority_keyword_merge(&[
POSTGRES_DOCS_KEYWORDS,
POSTGRES_NONDOCS_KEYWORDS,
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/redshift_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const REDSHIFT_RESERVED_KEYWORDS: &str = "AES128
pub(crate) const REDSHIFT_RESERVED_KEYWORDS: &str = "AES128
AES256
ALL
ALLOWOVERWRITE
Expand Down Expand Up @@ -155,7 +155,7 @@ WITH
WITHIN
WITHOUT";

pub const REDSHIFT_UNRESERVED_KEYWORDS: &str = "A
pub(crate) const REDSHIFT_UNRESERVED_KEYWORDS: &str = "A
ABORT
ABS
ABSENT
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/snowflake_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const SNOWFLAKE_RESERVED_KEYWORDS: &str = "ALL
pub(crate) const SNOWFLAKE_RESERVED_KEYWORDS: &str = "ALL
ALTER
AND
ANY
Expand Down Expand Up @@ -84,7 +84,7 @@ WHENEVER
WHERE
WITH";

pub const SNOWFLAKE_UNRESERVED_KEYWORDS: &str = "ABORT
pub(crate) const SNOWFLAKE_UNRESERVED_KEYWORDS: &str = "ABORT
ABORT_STATEMENT
ACCESS
ACCOUNT
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/sparksql_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const RESERVED_KEYWORDS: &[&str] = &[
pub(crate) const RESERVED_KEYWORDS: &[&str] = &[
"ALL",
"AND",
"ANY",
Expand Down Expand Up @@ -68,7 +68,7 @@ pub const RESERVED_KEYWORDS: &[&str] = &[
"WITH",
];

pub const UNRESERVED_KEYWORDS: &[&str] = &[
pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[
"ADD",
"AFTER",
"ALTER",
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/sqlite_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://www.sqlite.org/lang_keywords.html
// Augmented with data types, and a couple of omitted keywords.

pub const RESERVED_KEYWORDS: &[&str] = &[
pub(crate) const RESERVED_KEYWORDS: &[&str] = &[
"ABORT",
"ACTION",
"ADD",
Expand Down Expand Up @@ -152,7 +152,7 @@ pub const RESERVED_KEYWORDS: &[&str] = &[
"WITHOUT",
];

pub const UNRESERVED_KEYWORDS: &[&str] = &[
pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[
"INT",
"INTEGER",
"TINYINT",
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/src/trino_keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const TRINO_RESERVED_KEYWORDS: &str = "ALTER
pub(crate) const TRINO_RESERVED_KEYWORDS: &str = "ALTER
AND
AS
BETWEEN
Expand Down Expand Up @@ -82,7 +82,7 @@ WHERE
WITH
";

pub const TRINO_UNRESERVED_KEYWORDS: &str = "ABSENT
pub(crate) const TRINO_UNRESERVED_KEYWORDS: &str = "ABSENT
ADD
ADMIN
AFTER
Expand Down
4 changes: 2 additions & 2 deletions crates/lib-dialects/tests/dialects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub struct Args {
}

impl Args {
fn parse_args(&mut self, mut iter: impl Iterator<Item = String>) {
while let Some(arg) = iter.next() {
fn parse_args(&mut self, iter: impl Iterator<Item = String>) {
for arg in iter {
if arg == "--" {
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions crates/lib-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ repository.workspace = true
edition.workspace = true
license.workspace = true

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "rlib"]
bench = false
Expand Down
3 changes: 3 additions & 0 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ repository.workspace = true
edition.workspace = true
license.workspace = true

[lints]
workspace = true

[package.metadata.cargo-machete]
ignored = ["strum"] # false positive result, crate is used in macro expansion

Expand Down
14 changes: 9 additions & 5 deletions crates/lib/src/core/linter/runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::core::Linter;
use super::linted_file::LintedFile;

pub trait Runner: Sized {
pub(crate) trait Runner: Sized {
fn run(
&mut self,
paths: Vec<String>,
Expand All @@ -10,24 +10,28 @@ pub trait Runner: Sized {
) -> impl Iterator<Item = LintedFile>;
}

pub struct RunnerContext<'me, R> {
pub(crate) struct RunnerContext<'me, R> {
linter: &'me mut Linter,
runner: R,
}

impl<'me> RunnerContext<'me, ParallelRunner> {
pub fn sequential(linter: &'me mut Linter) -> Self {
pub(crate) fn sequential(linter: &'me mut Linter) -> Self {
Self { linter, runner: ParallelRunner }
}
}

impl<R: Runner> RunnerContext<'_, R> {
pub fn run(&mut self, paths: Vec<String>, fix: bool) -> impl Iterator<Item = LintedFile> + '_ {
pub(crate) fn run(
&mut self,
paths: Vec<String>,
fix: bool,
) -> impl Iterator<Item = LintedFile> + '_ {
self.runner.run(paths, fix, self.linter)
}
}

pub struct ParallelRunner;
pub(crate) struct ParallelRunner;

impl Runner for ParallelRunner {
fn run(
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(trait_upcasting)]
#![feature(let_chains)]
#![deny(unused_qualifications)]

mod ansi;
pub mod api;
pub mod cli;
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod tests {
#[test]
fn no_rule_should_not_include_all_as_that_is_default() {
rules().iter().for_each(|rule| {
assert_eq!(*rule.groups().get(0).unwrap(), RuleGroups::All);
assert_eq!(*rule.groups().first().unwrap(), RuleGroups::All);
});
}

Expand All @@ -71,7 +71,7 @@ mod tests {
fn if_rule_contains_core_is_second_in_list() {
rules().iter().for_each(|rule| {
let groups = rule.groups();
if groups.into_iter().find(|&&rule| rule == RuleGroups::Core).is_some() {
if groups.iter().any(|&rule| rule == RuleGroups::Core) {
assert_eq!(groups.get(1).unwrap(), &RuleGroups::Core);
}
})
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/rules/structure/st05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct NestedSubQuerySummary<'a> {
}

#[derive(Clone, Debug, Default)]
pub struct RuleST05 {
pub(crate) struct RuleST05 {
forbid_subquery_in: String,
}

Expand Down Expand Up @@ -712,7 +712,7 @@ fn create_table_ref(tables: &Tables, table_name: &str, dialect: &Dialect) -> Era
.finish()
}

pub struct SegmentCloneMap {
pub(crate) struct SegmentCloneMap {
root: ErasedSegment,
segment_map: AHashMap<usize, ErasedSegment>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/templaters/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod test {
#[test]
/// Test the raw templater
fn test_templater_raw() {
let templater = RawTemplater::default();
let templater = RawTemplater;
let in_str = "SELECT * FROM {{blah}}";

let outstr = templater.process(in_str, "test.sql", None, None).unwrap();
Expand Down
1 change: 0 additions & 1 deletion crates/lib/src/utils/reflow/respace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ mod tests {
assert_eq!(new_pnt.raw(), raw_point_sql_out);

let fixes = fixes_from_results(results.into_iter())
.into_iter()
.map(|fix| (fix.edit_type, fix.anchor.raw().to_smolstr()))
.collect_vec();

Expand Down
2 changes: 1 addition & 1 deletion crates/lib/tests/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Args {

impl Args {
fn parse_args(&mut self, mut iter: impl Iterator<Item = String>) {
while let Some(arg) = iter.next() {
for arg in iter {
if arg == "--" {
continue;
}
Expand Down
Loading

0 comments on commit c7f795a

Please sign in to comment.