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
30 changes: 29 additions & 1 deletion qlty-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use plugin::{
};
pub use release::ReleaseDef;
pub use source::SourceDef;
use console::style;

use crate::config::plugin::EnabledRuntimes;
pub use crate::config::plugin::PluginsConfig;
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,31 @@ 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: your qlty.toml is using a deprecated, repository-based, default source. Please change your default source in your qlty.toml to:
noahd1 marked this conversation as resolved.
Show resolved Hide resolved
[[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
6 changes: 5 additions & 1 deletion qlty-config/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ 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