Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn user is using deprecated default source (repository reference instead of default = true) #1355

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.qlty/results
.qlty/logs
.qlty/out
.qlty/sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config_version = "0"

[[source]]
name = "default"
repository = "https://github.com/qltysh/qlty.git"
tag = "v0.463.0"
10 changes: 10 additions & 0 deletions qlty-cli/tests/cmd/check/using_deprecated_default_source.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

⚠ Warning: qlty.toml is using a deprecated, repository-based, default source.

Please change the default source in your qlty.toml to:

[[source]]
name = "default"
default = true

✔ No issues
Empty file.
2 changes: 2 additions & 0 deletions qlty-cli/tests/cmd/check/using_deprecated_default_source.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.name = "qlty"
args = ["check", "--all", "--no-cache"]
42 changes: 41 additions & 1 deletion qlty-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use self::ignore::{Ignore, ALL_WILDCARD};
pub use self::overrides::Override;
use self::smells::Smells;
pub use builder::Builder;
use console::style;
pub use coverage::Coverage;
pub use download::{Cpu, DownloadDef, DownloadFileType, OperatingSystem, System};
pub use file_type::FileType;
Expand All @@ -37,7 +38,7 @@ use anyhow::{bail, Result};
use semver::Version;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tracing::debug;
use tracing::{debug, warn};

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct QltyConfig {
Expand Down Expand Up @@ -86,6 +87,8 @@ pub struct QltyConfig {
pub source: Vec<SourceDef>,
}

const OLD_DEFAULT_SOURCE_REPOSITORY: &str = "https://github.com/qltysh/qlty";
brynary marked this conversation as resolved.
Show resolved Hide resolved

impl QltyConfig {
pub fn validate_cli_version(&self) -> Result<()> {
if self.cli_version.is_none() {
Expand Down Expand Up @@ -136,6 +139,43 @@ impl QltyConfig {
.map(|(name, settings)| (name.clone(), f(settings)))
.collect::<HashMap<_, _>>()
}

pub fn default_source(&self) -> Option<&SourceDef> {
self.source
.iter()
.find(|s| s.name.as_deref() == Some("default"))
}

pub fn print_deprecation_warnings(&self) {
match self.default_source() {
Some(source) => {
if source.repository.is_some()
&& source
.repository
.as_ref()
.unwrap()
.starts_with(OLD_DEFAULT_SOURCE_REPOSITORY)
{
warn!("qlty.toml default source is a repository-style reference to qltysh.");
eprintln!(
r#"
{} Warning: qlty.toml is using a deprecated, repository-based, default source.

Please change the default source in your qlty.toml to:

[[source]]
name = "default"
default = true
"#,
style("⚠").yellow()
);
}
}
None => {
warn!("No default source defined in qlty.toml.");
}
}
}
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions qlty-config/src/config/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ impl SourceDef {
}))
} else if self.repository.is_some() {
if self.tag.is_some() && self.branch.is_some() {
bail!("Source defines both a tag and branch");
bail!("Repository source defines both a tag and branch");
}

if self.tag.is_none() && self.branch.is_none() {
bail!("Source defines neither a tag nor branch");
bail!("Repository source defines neither a tag nor branch");
}

let reference = if self.tag.is_some() {
Expand Down
8 changes: 7 additions & 1 deletion qlty-config/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ impl Workspace {
}

pub fn config(&self) -> Result<QltyConfig> {
Builder::full_config_for_workspace(self)
let config = Builder::full_config_for_workspace(self);

if let Ok(config) = &config {
config.print_deprecation_warnings();
}

config
noahd1 marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn sources_list(&self) -> Result<SourcesList> {
Expand Down
Loading