Skip to content

Commit

Permalink
qlty check --all --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Nov 21, 2024
1 parent 4aede17 commit 363d316
Show file tree
Hide file tree
Showing 111 changed files with 219 additions and 236 deletions.
2 changes: 1 addition & 1 deletion plugins/scripts/fetchLatestVersion/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function fetchLatestVersionFromGithub(
throw new Error(`GitHub API request failed with status ${response.status}`);
}

const data: any = await response.json();
const data = (await response.json()) as { tag_name: string };

const tag = data.tag_name as string;
if (!tag) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/scripts/updateLinterVersions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync, ExecException } from "child_process";
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
import toml from "toml";
Expand Down Expand Up @@ -174,4 +174,4 @@ async function main(): Promise<void> {
}
}

main();
void main();
6 changes: 4 additions & 2 deletions plugins/tests/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class QltyDriver {
let output = { stdout: "", stderr: "" };
let exitCode = 0;
try {
let env = {
const env = {
...executionEnv(this.sandboxPath ?? ""),
QLTY_LOG_STDERR: "1",
QLTY_LOG: process.env.QLTY_LOG ?? "debug",
Expand All @@ -192,7 +192,9 @@ export class QltyDriver {
let outputJson = [];
try {
outputJson = JSON.parse(output.stdout);
} catch {}
} catch {
/* empty */
}

return this.parseRunResult({
exitCode,
Expand Down
4 changes: 2 additions & 2 deletions qlty-analysis/src/git/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ fn infer_upstream(workspace: &Workspace) -> Result<Option<String>> {
}

fn default_upstream(repo: &Repository) -> Result<Option<String>> {
let known_default_branches = vec!["main", "master", "develop"];
let known_default_branches = ["main", "master", "develop"];

for branch_name in known_default_branches.iter() {
if repo.find_branch(&branch_name, git2::BranchType::Local).is_ok() {
if repo.find_branch(branch_name, git2::BranchType::Local).is_ok() {
debug!("Found {} branch. Using as upstream.", branch_name);
return Ok(Some(branch_name.to_string()));
}
Expand Down
2 changes: 1 addition & 1 deletion qlty-analysis/src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub trait Language {
let cursor = &mut parameters_node.walk();

for parameter_node in parameters_node.named_children(cursor) {
let parameter_name = node_source(&parameter_node, &source_file);
let parameter_name = node_source(&parameter_node, source_file);

let sanitized_parameter_name = self.sanitize_parameter_name(parameter_name);
match sanitized_parameter_name {
Expand Down
2 changes: 1 addition & 1 deletion qlty-analysis/src/lang/kotlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl Language for Kotlin {
}

fn sanitize_parameter_name(&self, parameter_name: String) -> Option<String> {
Some(String::from(parameter_name.split(":").next().unwrap()))
Some(String::from(parameter_name.split(':').next().unwrap()))
}

fn function_name_node<'a>(&'a self, node: &'a Node) -> Node<'a> {
Expand Down
4 changes: 2 additions & 2 deletions qlty-analysis/src/lang/tsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl Default for TSX {

Self {
common,
field_query: field_query,
class_query: class_query,
field_query,
class_query,
function_declaration_query,
}
}
Expand Down
10 changes: 5 additions & 5 deletions qlty-analysis/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Report {
invocation.project_id = self.metadata.project_id.clone();
invocation.reference = self.metadata.reference.clone();
invocation.build_id = self.metadata.build_id.clone();
invocation.build_timestamp = self.metadata.start_time.clone();
invocation.build_timestamp = self.metadata.start_time;
invocation.commit_sha = self.metadata.revision_oid.clone();
});

Expand All @@ -101,14 +101,14 @@ impl Report {
message.project_id = self.metadata.project_id.clone();
message.reference = self.metadata.reference.clone();
message.build_id = self.metadata.build_id.clone();
message.build_timestamp = self.metadata.start_time.clone();
message.build_timestamp = self.metadata.start_time;
message.commit_sha = self.metadata.revision_oid.clone();
});

self.issues.par_iter_mut().for_each(|issue| {
issue.workspace_id = self.metadata.workspace_id.clone();
issue.project_id = self.metadata.project_id.clone();
issue.analyzed_at = Some(self.metadata.start_time.clone().unwrap());
issue.analyzed_at = Some(self.metadata.start_time.unwrap());
issue.pull_request_number = self.metadata.pull_request_number.clone();
issue.tracked_branch_id = self.metadata.tracked_branch_id.clone();

Expand All @@ -120,7 +120,7 @@ impl Report {
self.stats.par_iter_mut().for_each(|stats| {
stats.workspace_id = self.metadata.workspace_id.clone();
stats.project_id = self.metadata.project_id.clone();
stats.analyzed_at = Some(self.metadata.start_time.clone().unwrap());
stats.analyzed_at = Some(self.metadata.start_time.unwrap());
stats.pull_request_number = self.metadata.pull_request_number.clone();
stats.tracked_branch_id = self.metadata.tracked_branch_id.clone();

Expand All @@ -136,7 +136,7 @@ impl Report {
.filter(|issue| issue.tool == "qlty" && issue.driver == "duplication")
.fold(HashMap::new(), |mut acc, issue| {
let structural_hash = issue.get_property_string("structural_hash");
let issues = acc.entry(structural_hash).or_insert(vec![]);
let issues = acc.entry(structural_hash).or_default();
issues.push(issue.clone());
acc
})
Expand Down
3 changes: 1 addition & 2 deletions qlty-analysis/src/utils/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ pub fn path_to_string<'path>(path: impl AsRef<Path>) -> String {

pub fn path_to_native_string(path: impl AsRef<Path>) -> String {
path_to_string(path)
.replace('\\', MAIN_SEPARATOR_STR)
.replace('/', MAIN_SEPARATOR_STR)
.replace(['\\', '/'], MAIN_SEPARATOR_STR)
}

mod test {
Expand Down
8 changes: 3 additions & 5 deletions qlty-analysis/src/workspace_entries/target_mode.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::git::DiffMode;

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default)]
pub enum TargetMode {
#[default]
All,
Sample(usize),
Paths(usize),
UpstreamDiff(String),
HeadDiff,
}

impl Default for TargetMode {
fn default() -> Self {
TargetMode::All
}
}


impl TargetMode {
pub fn diff_mode(&self) -> DiffMode {
Expand Down
6 changes: 3 additions & 3 deletions qlty-check/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Executor {
.invocations
.iter()
.for_each(|invocation: &InvocationPlan| {
if let Some(_) = &invocation.driver.prepare_script {
if invocation.driver.prepare_script.is_some() {
// Prevent multiple prepare scripts for the same driver and plugin and
// store invocation plan to run the prepare script later
prepare_scripts.insert(invocation.invocation_label(), invocation);
Expand All @@ -107,7 +107,7 @@ impl Executor {

for (key, invocation) in prepare_scripts {
let task = self.progress.task(&key, "Running prepare script...");
invocation.driver.run_prepare_script(&invocation, &task)?;
invocation.driver.run_prepare_script(invocation, &task)?;
task.clear();
}

Expand Down Expand Up @@ -263,7 +263,7 @@ impl Executor {

for config_file in &repository_config_files {
if let Err(err) = load_config_file_from_repository(
&config_file,
config_file,
&self.plan.workspace,
&self.plan.staging_area.destination_directory,
) {
Expand Down
28 changes: 8 additions & 20 deletions qlty-check/src/executor/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl Driver {
"{}/",
target_root
.strip_prefix("/private/")
.unwrap_or(&target_root)
.unwrap_or(target_root)
))
.unwrap_or(&path)
.into();
Expand All @@ -406,7 +406,7 @@ impl Driver {

fn parser(&self) -> Box<dyn Parser> {
let parser: Box<dyn Parser> = match self.output_format {
OutputFormat::Eslint => Box::new(Eslint::default()),
OutputFormat::Eslint => Box::<Eslint>::default(),
OutputFormat::Hadolint => Box::new(Hadolint {}),
OutputFormat::Markdownlint => Box::new(Markdownlint {}),
OutputFormat::Mypy => Box::new(Mypy {}),
Expand All @@ -422,7 +422,7 @@ impl Driver {
OutputFormat::Trufflehog => Box::new(Trufflehog {}),
OutputFormat::Tsc => Box::new(Tsc {}),
OutputFormat::Bandit => Box::new(Bandit {}),
OutputFormat::Clippy => Box::new(Clippy::default()),
OutputFormat::Clippy => Box::<Clippy>::default(),
OutputFormat::Ripgrep => Box::new(Ripgrep {}),
OutputFormat::Phpstan => Box::new(Phpstan {}),
OutputFormat::PhpCodesniffer => Box::new(PhpCodesniffer {}),
Expand All @@ -432,29 +432,17 @@ impl Driver {
OutputFormat::GolangciLint => Box::new(GolangciLint {}),

OutputFormat::Sarif => {
let level = match self.output_level {
Some(output_level) => Some(output_level.into()),
None => None,
};
let level = self.output_level.map(|output_level| output_level.into());

let category = match self.output_category {
Some(output_category) => Some(output_category.into()),
None => None,
};
let category = self.output_category.map(|output_category| output_category.into());

Box::new(Sarif::new(level, category))
}

OutputFormat::Regex => {
let level = match self.output_level {
Some(output_level) => Some(output_level.into()),
None => None,
};

let category = match self.output_category {
Some(output_category) => Some(output_category.into()),
None => None,
};
let level = self.output_level.map(|output_level| output_level.into());

let category = self.output_category.map(|output_category| output_category.into());

let regex = &self
.output_regex
Expand Down
2 changes: 1 addition & 1 deletion qlty-check/src/executor/invocation_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl InvocationResult {
output: &Output,
duration: f64,
) -> Result<Self> {
let exec_result = ExecResult::from_process_output(&output);
let exec_result = ExecResult::from_process_output(output);

let now = Utc::now();
let start_time = now - chrono::Duration::seconds(duration as i64);
Expand Down
8 changes: 3 additions & 5 deletions qlty-check/src/parser/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ impl ClippyIssue {
.split(' ')
.last()
.unwrap()
.replace('(', "")
.replace(')', "");
.replace(['(', ')'], "");
if let Ok(url) = Url::parse(&package_id) {
self.package_name = url.path_segments().unwrap().last().unwrap().to_string();
}
Expand Down Expand Up @@ -136,7 +135,7 @@ impl Parser for Clippy {

let message = clippy_issue.message.as_ref().unwrap();
let code = message.code.clone();
let suggestion = self.build_suggestion(&message, &clippy_issue);
let suggestion = self.build_suggestion(message, &clippy_issue);

let issue = Issue {
tool: "clippy".into(),
Expand Down Expand Up @@ -182,8 +181,7 @@ impl Clippy {
.children
.iter()
.filter(|child| child.level == "help")
.map(|child| self.collect_replacements(&child, issue))
.flatten()
.flat_map(|child| self.collect_replacements(child, issue))
.collect();

if replacements.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion qlty-check/src/parser/eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn category(rule_key: &str) -> Category {
}

fn generate_document_url(rule_key: String) -> String {
let rule_config: Vec<&str> = rule_key.split("/").collect();
let rule_config: Vec<&str> = rule_key.split('/').collect();

match rule_config.as_slice() {
[_] => {
Expand Down
4 changes: 2 additions & 2 deletions qlty-check/src/parser/markdownlint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ fn generate_document_url(rule_key: String) -> String {
.to_string()
.replace(
"${rule}",
&rule_key
.split(" ")
rule_key
.split(' ')
.next()
.unwrap_or_else(|| &rule_key)
)
Expand Down
2 changes: 1 addition & 1 deletion qlty-check/src/parser/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Regex {
if issue.tool == "yamllint" {
issue.documentation_url = format!(
"https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.{}",
issue.rule_key.replace("-", "_")
issue.rule_key.replace('-', "_")
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion qlty-check/src/parser/sarif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Parser for Sarif {
rule_key,
message: result.message.text.clone(),
category: self.category.unwrap_or(Category::Lint).into(),
level: self.get_level(&result, &rule_info).into(),
level: self.get_level(result, &rule_info).into(),
location,
..Default::default()
};
Expand Down
8 changes: 2 additions & 6 deletions qlty-check/src/parser/trufflehog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ impl Parser for Trufflehog {
let parsed_data: Output =
serde_json::from_str(trufflehog_source.trim()).expect("Error parsing JSON data");

let range = if let Some(line) = parsed_data.source_metadata.data.filesystem.line {
Some(Range {
let range = parsed_data.source_metadata.data.filesystem.line.map(|line| Range {
start_line: line + 1,
..Default::default()
})
} else {
None
};
});

let issue = Issue {
tool: "trufflehog".into(),
Expand Down
8 changes: 4 additions & 4 deletions qlty-check/src/parser/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ impl Parser for Tsc {
let check_string = parts[1];
let message = parts[2];

let location_parts: Vec<&str> = location_string.splitn(2, "(").collect();
let location_parts: Vec<&str> = location_string.splitn(2, '(').collect();
if location_parts.len() != 2 {
trace!("Location does not have 2 parts splitting on (: {}", line);
continue;
}

let path = location_parts[0];
let location_parts: Vec<&str> = location_parts[1].splitn(2, ",").collect();
let location_parts: Vec<&str> = location_parts[1].splitn(2, ',').collect();

if location_parts.len() != 2 {
trace!("Location does not have 2 parts splitting on ,: {}", line);
continue;
}

let line = location_parts[0].parse::<i32>()?;
let column = location_parts[1].replace(")", "").parse::<i32>()?;
let column = location_parts[1].replace(')', "").parse::<i32>()?;

let check_parts: Vec<&str> = check_string.splitn(2, " ").collect();
let check_parts: Vec<&str> = check_string.splitn(2, ' ').collect();
if check_parts.len() != 2 {
trace!("Check does not have 2 parts splitting on ' ': {}", line);
continue;
Expand Down
4 changes: 2 additions & 2 deletions qlty-check/src/planner/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn configure_plugins(planner: &Planner) -> Result<Vec<ActivePlugin>> {
}

let name = &enabled_plugin.name;
let plugin = configure_plugin(planner, name, &enabled_plugin)?;
let plugin = configure_plugin(planner, name, enabled_plugin)?;
enabled_plugins.push(ActivePlugin {
name: name.to_string(),
plugin,
Expand Down Expand Up @@ -181,7 +181,7 @@ fn configure_plugin(
}
}

Ok(plugin_def.into())
Ok(plugin_def)
} else {
bail!("Unknown plugin {}", name)
}
Expand Down
2 changes: 1 addition & 1 deletion qlty-check/src/planner/config_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn ignore_globset(ignore: &Vec<Ignore>) -> Result<GlobSet> {
}

pub fn plugin_configs(planner: &Planner) -> Result<HashMap<String, Vec<PluginConfigFile>>> {
let plugins = enabled_plugins(&planner)?;
let plugins = enabled_plugins(planner)?;
let mut plugins_configs = vec![];

for active_plugin in &plugins {
Expand Down
Loading

0 comments on commit 363d316

Please sign in to comment.