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
14 changes: 12 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ jobs:
with:
paths_ignore: '["docs/**", "*.md"]'

lint_pre_job:
runs-on: ubuntu-22.04
outputs:
should_skip_lint: ${{ steps.skip_check_lint.outputs.should_skip }}
steps:
- id: skip_check_lint
uses: fkirc/skip-duplicate-actions@c449d86cf33a2a6c7a4193264cc2578e2c3266d4 # pin@v4
with:
paths: '["**/*.rs", "**/Cargo.toml", "Cargo.lock", "s/lint"]'

build:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')
Expand Down Expand Up @@ -273,8 +283,8 @@ jobs:
NETLIFY_SITE_ID: ${{ secrets.PLAYGROUND_NETLIFY_SITE_ID }}

lint:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
needs: lint_pre_job
if: needs.lint_pre_job.outputs.should_skip_lint != 'true'

runs-on: ubuntu-22.04

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ coverage/
.pytest_cache/
target/
docs
squawk-vscode/.vscode-test/
squawk-vscode/dist/
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
alter table t add column c timestamptz default now() - interval '100 years';
```


## Fixed

- parser: parse materialized views using a paren select (#651).
Expand Down
4 changes: 1 addition & 3 deletions crates/squawk/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{io, path::PathBuf};

use annotate_snippets::{
Annotation, AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle,
};
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
use anyhow::Result;
use serde_json::json;
use squawk_syntax::{ast::AstNode, syntax_error::SyntaxError};
Expand Down
4 changes: 2 additions & 2 deletions crates/squawk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum Command {
/// Run the language server
Server,
/// Comment on a PR with Squawk's results.
UploadToGithub(UploadToGithubArgs),
UploadToGithub(Box<UploadToGithubArgs>),
}

#[derive(Debug, ValueEnum, Clone)]
Expand Down Expand Up @@ -232,7 +232,7 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log
}
Some(Command::UploadToGithub(args)) => {
github::check_and_comment_on_pr(
args,
*args,
&conf,
is_stdin,
opts.stdin_filepath,
Expand Down
4 changes: 1 addition & 3 deletions crates/squawk/src/reporter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use annotate_snippets::{
Annotation, AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle,
};
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
use anyhow::Result;
use console::style;
use line_index::LineIndex;
Expand Down
10 changes: 5 additions & 5 deletions crates/squawk_github/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn create_access_token(
install_id: i64,
) -> Result<GithubAccessToken, GithubError> {
Ok(reqwest::blocking::Client::new()
.post(&format!(
.post(format!(
"{github_api_url}/app/installations/{install_id}/access_tokens",
))
.header(AUTHORIZATION, format!("Bearer {jwt}"))
Expand All @@ -66,7 +66,7 @@ pub(crate) fn create_comment(
}
let comment_body = CommentBody { body: comment.body };
reqwest::blocking::Client::new()
.post(&format!(
.post(format!(
"{github_api_url}/repos/{owner}/{repo}/issues/{issue_number}/comments",
owner = comment.owner,
repo = comment.repo,
Expand All @@ -89,7 +89,7 @@ pub struct GitHubAppInfo {
/// Get the bot name for finding existing comments on a PR
pub fn get_app_info(github_api_url: &str, jwt: &str) -> Result<GitHubAppInfo, GithubError> {
Ok(reqwest::blocking::Client::new()
.get(&format!("{github_api_url}/app"))
.get(format!("{github_api_url}/app"))
.header(AUTHORIZATION, format!("Bearer {jwt}"))
.header(USER_AGENT, SQUAWK_USER_AGENT)
.send()?
Expand Down Expand Up @@ -173,7 +173,7 @@ pub(crate) fn list_comments(
// TODO(sbdchd): use the next links to get _all_ the comments
// see: https://developer.github.com/v3/guides/traversing-with-pagination/
Ok(reqwest::blocking::Client::new()
.get(&format!(
.get(format!(
"{github_api_url}/repos/{owner}/{repo}/issues/{issue_number}/comments",
owner = pr.owner,
repo = pr.repo,
Expand Down Expand Up @@ -205,7 +205,7 @@ pub(crate) fn update_comment(
}

reqwest::blocking::Client::new()
.patch(&format!(
.patch(format!(
"{github_api_url}/repos/{owner}/{repo}/issues/comments/{comment_id}",
))
.header(AUTHORIZATION, format!("Bearer {secret}"))
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_github/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::error::Error;
use log::info;
use serde::{Deserialize, Serialize};

pub(crate) const DEFAULT_GITHUB_API_URL: &'static str = "https://api.github.com";
pub(crate) const DEFAULT_GITHUB_API_URL: &str = "https://api.github.com";

#[derive(Debug)]
pub enum GithubError {
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ mod tests {
}
}

fn lex(input: &str) -> Vec<TokenDebug> {
fn lex(input: &str) -> Vec<TokenDebug<'_>> {
let mut tokens = vec![];
let mut start = 0;

Expand Down
59 changes: 29 additions & 30 deletions crates/squawk_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ impl Violation {

let start = node
.children_with_tokens()
.filter(|x| !x.kind().is_trivia())
.next()
.find(|x| !x.kind().is_trivia())
.map(|x| x.text_range().start())
// Not sure we actually hit this, but just being safe
.unwrap_or_else(|| range.start());
Expand Down Expand Up @@ -333,91 +332,91 @@ impl Linter {
#[must_use]
pub fn lint(&mut self, file: &Parse<SourceFile>, text: &str) -> Vec<Violation> {
if self.rules.contains(&Rule::AddingFieldWithDefault) {
adding_field_with_default(self, &file);
adding_field_with_default(self, file);
}
if self.rules.contains(&Rule::AddingForeignKeyConstraint) {
adding_foreign_key_constraint(self, &file);
adding_foreign_key_constraint(self, file);
}
if self.rules.contains(&Rule::AddingNotNullableField) {
adding_not_null_field(self, &file);
adding_not_null_field(self, file);
}
if self.rules.contains(&Rule::AddingSerialPrimaryKeyField) {
adding_primary_key_constraint(self, &file);
adding_primary_key_constraint(self, file);
}
if self.rules.contains(&Rule::AddingRequiredField) {
adding_required_field(self, &file);
adding_required_field(self, file);
}
if self.rules.contains(&Rule::BanDropDatabase) {
ban_drop_database(self, &file);
ban_drop_database(self, file);
}
if self.rules.contains(&Rule::BanCharField) {
ban_char_field(self, &file);
ban_char_field(self, file);
}
if self
.rules
.contains(&Rule::BanConcurrentIndexCreationInTransaction)
{
ban_concurrent_index_creation_in_transaction(self, &file);
ban_concurrent_index_creation_in_transaction(self, file);
}
if self.rules.contains(&Rule::BanDropColumn) {
ban_drop_column(self, &file);
ban_drop_column(self, file);
}
if self.rules.contains(&Rule::BanDropNotNull) {
ban_drop_not_null(self, &file);
ban_drop_not_null(self, file);
}
if self.rules.contains(&Rule::BanDropTable) {
ban_drop_table(self, &file);
ban_drop_table(self, file);
}
if self.rules.contains(&Rule::ChangingColumnType) {
changing_column_type(self, &file);
changing_column_type(self, file);
}
if self.rules.contains(&Rule::ConstraintMissingNotValid) {
constraint_missing_not_valid(self, &file);
constraint_missing_not_valid(self, file);
}
if self.rules.contains(&Rule::DisallowedUniqueConstraint) {
disallow_unique_constraint(self, &file);
disallow_unique_constraint(self, file);
}
if self.rules.contains(&Rule::PreferBigintOverInt) {
prefer_bigint_over_int(self, &file);
prefer_bigint_over_int(self, file);
}
if self.rules.contains(&Rule::PreferBigintOverSmallint) {
prefer_bigint_over_smallint(self, &file);
prefer_bigint_over_smallint(self, file);
}
if self.rules.contains(&Rule::PreferIdentity) {
prefer_identity(self, &file);
prefer_identity(self, file);
}
if self.rules.contains(&Rule::PreferRobustStmts) {
prefer_robust_stmts(self, &file);
prefer_robust_stmts(self, file);
}
if self.rules.contains(&Rule::PreferTextField) {
prefer_text_field(self, &file);
prefer_text_field(self, file);
}
if self.rules.contains(&Rule::PreferTimestampTz) {
prefer_timestamptz(self, &file);
prefer_timestamptz(self, file);
}
if self.rules.contains(&Rule::RenamingColumn) {
renaming_column(self, &file);
renaming_column(self, file);
}
if self.rules.contains(&Rule::RenamingTable) {
renaming_table(self, &file);
renaming_table(self, file);
}
if self.rules.contains(&Rule::RequireConcurrentIndexCreation) {
require_concurrent_index_creation(self, &file);
require_concurrent_index_creation(self, file);
}
if self.rules.contains(&Rule::RequireConcurrentIndexDeletion) {
require_concurrent_index_deletion(self, &file);
require_concurrent_index_deletion(self, file);
}
if self.rules.contains(&Rule::BanCreateDomainWithConstraint) {
ban_create_domain_with_constraint(self, &file);
ban_create_domain_with_constraint(self, file);
}
if self.rules.contains(&Rule::BanAlterDomainWithAddConstraint) {
ban_alter_domain_with_add_constraint(self, &file);
ban_alter_domain_with_add_constraint(self, file);
}
if self.rules.contains(&Rule::TransactionNesting) {
transaction_nesting(self, &file);
transaction_nesting(self, file);
}
if self.rules.contains(&Rule::BanTruncateCascade) {
ban_truncate_cascade(self, &file);
ban_truncate_cascade(self, file);
}
// xtask:new-rule:rule-call

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_linter/src/rules/ban_char_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ lazy_static! {
}

fn is_char_type(x: TokenText<'_>) -> bool {
CHAR_TYPES.contains(&Identifier::new(&x.to_string()))
CHAR_TYPES.contains(&Identifier::new(x.as_ref()))
}

fn create_fix(range: TextRange, args: Option<ast::ArgList>) -> Fix {
if let Some(args_list) = args {
let end = args_list.syntax().text_range().start();
let edit = Edit::replace(TextRange::new(range.start(), end), "varchar");
Fix::new(format!("Replace with `varchar`"), vec![edit])
Fix::new("Replace with `varchar`".to_string(), vec![edit])
} else {
let edit = Edit::replace(range, "text");
Fix::new(format!("Replace with `text`"), vec![edit])
Fix::new("Replace with `text`".to_string(), vec![edit])
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_parser/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Input {
#[inline]
fn push_impl(&mut self, kind: SyntaxKind, contextual_kind: SyntaxKind) {
let idx = self.len();
if idx % (bits::BITS as usize) == 0 {
if idx.is_multiple_of(bits::BITS as usize) {
self.joint.push(0);
}
self.kind.push(kind);
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_server/src/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn ignore_file_edit(

fn is_ignore_comment(token: &SyntaxToken) -> bool {
assert_eq!(token.kind(), SyntaxKind::COMMENT);
squawk_linter::ignore::ignore_rule_info(&token).is_some()
squawk_linter::ignore::ignore_rule_info(token).is_some()
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn lint(text: String) -> Result<JsValue, Error> {
let edits = fix
.edits
.into_iter()
.filter_map(|edit| {
.map(|edit| {
let start_pos = line_index.line_col(edit.text_range.start());
let end_pos = line_index.line_col(edit.text_range.end());
let start_wide = line_index
Expand All @@ -144,13 +144,13 @@ pub fn lint(text: String) -> Result<JsValue, Error> {
.to_wide(line_index::WideEncoding::Utf16, end_pos)
.unwrap();

Some(TextEdit {
TextEdit {
start_line_number: start_wide.line,
start_column: start_wide.col,
end_line_number: end_wide.line,
end_column: end_wide.col,
text: edit.text.unwrap_or_default(),
})
}
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion s/lint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
set -e

if [ -z "$CI" ]; then
if [ -n "$CI" ]; then
cargo fmt -- --check
cargo clippy --all-targets --all-features -- -D warnings
else
Expand Down
2 changes: 1 addition & 1 deletion s/prettier
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex

main() {
if [ -z "$CI" ]; then
if [ -n "$CI" ]; then
./node_modules/.bin/prettier --check '**/*.{js,md,yml,json}'
else
./node_modules/.bin/prettier '**/*.{js,md,yml,json}' --write
Expand Down
6 changes: 3 additions & 3 deletions squawk-vscode/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const esbuildProblemMatcherPlugin = {
build.onStart(() => {
console.log("[watch] build started")
})
build.onEnd((result) => {
build.onEnd(result => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`)
console.error(
` ${location.file}:${location.line}:${location.column}:`,
` ${location.file}:${location.line}:${location.column}:`
)
})
console.log("[watch] build finished")
Expand Down Expand Up @@ -50,7 +50,7 @@ async function main() {
}
}

main().catch((e) => {
main().catch(e => {
console.error(e)
process.exit(1)
})
Loading