Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/squawk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log
let mut clap_app = Opt::clap();
let is_stdin = !atty::is(Stream::Stdin);
let github_annotations = std::env::var("GITHUB_ACTIONS").is_ok()
&& !std::env::var("SQUAWK_DISABLE_GITHUB_ANNOTATIONS").is_ok();
&& std::env::var("SQUAWK_DISABLE_GITHUB_ANNOTATIONS").is_err();
match opts.cmd {
Some(Command::Server) => {
squawk_server::run().context("language server failed")?;
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_linter/src/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ alter table t drop column c cascade;
let errors: Vec<_> = linter
.lint(parse, sql)
.into_iter()
.map(|x| x.code.clone())
.map(|x| x.code)
.collect();
assert!(errors.is_empty());
}
Expand Down Expand Up @@ -355,7 +355,7 @@ alter table t2 drop column c2 cascade;
let errors: Vec<_> = linter
.lint(parse, sql)
.into_iter()
.map(|x| x.code.clone())
.map(|x| x.code)
.collect();

assert_debug_snapshot!(errors, @r"
Expand All @@ -379,7 +379,7 @@ alter table t2 drop column c2 cascade;
let errors: Vec<_> = linter
.lint(parse, sql)
.into_iter()
.map(|x| x.code.clone())
.map(|x| x.code)
.collect();

assert_debug_snapshot!(errors, @r"
Expand Down
37 changes: 37 additions & 0 deletions crates/squawk_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ignore::find_ignores;
use ignore_index::IgnoreIndex;
use lazy_static::lazy_static;
use rowan::TextRange;
use rowan::TextSize;
use serde::{Deserialize, Serialize};

use squawk_syntax::{Parse, SourceFile};
Expand Down Expand Up @@ -222,6 +223,36 @@ pub struct Violation {
pub message: String,
pub text_range: TextRange,
pub help: Option<String>,
pub fix: Option<Fix>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Fix {
pub title: String,
pub edits: Vec<Edit>,
}

impl Fix {
fn new<T: Into<String>>(title: T, edits: Vec<Edit>) -> Fix {
Fix {
title: title.into(),
edits,
}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Edit {
pub text_range: TextRange,
pub text: Option<String>,
}
impl Edit {
fn insert<T: Into<String>>(text: T, at: TextSize) -> Self {
Self {
text_range: TextRange::new(at, at),
text: Some(text.into()),
}
}
}

impl Violation {
Expand All @@ -237,8 +268,14 @@ impl Violation {
text_range,
message,
help: help.into(),
fix: None,
}
}

fn with_fix(mut self, fix: Option<Fix>) -> Violation {
self.fix = fix;
self
}
}

pub struct LinterSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lazy_static! {
.split('\n')
.map(|x| x.trim())
.filter(|x| !x.is_empty())
.map(|x| Identifier::new(x))
.map(Identifier::new)
.collect()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use squawk_syntax::{
ast::{self, AstNode},
};

use crate::{
Linter, Rule, Violation,
identifier::Identifier,
};
use crate::{Linter, Rule, Violation, identifier::Identifier};

pub fn tables_created_in_transaction(
assume_in_transaction: bool,
Expand Down Expand Up @@ -73,7 +70,8 @@ fn not_valid_validate_in_transaction(
if add_constraint.not_valid().is_some() {
if let Some(constraint) = add_constraint.constraint() {
if let Some(constraint_name) = constraint.name() {
not_valid_names.insert(Identifier::new(&constraint_name.text()));
not_valid_names
.insert(Identifier::new(&constraint_name.text()));
}
}
}
Expand Down
Loading
Loading