Skip to content

Commit

Permalink
Make with prefixes default behaviour (#1158)
Browse files Browse the repository at this point in the history
Removes the `--with-prefixes` flag from `qlty init` and makes the
behaviour for prefix during init default.
  • Loading branch information
marschattha authored Nov 19, 2024
1 parent a82d382 commit f36ac01
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 79 deletions.
11 changes: 9 additions & 2 deletions qlty-cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ pub struct Init {
#[arg(long, value_parser = SourceSpec::new)]
pub source: Option<SourceSpec>,

/// Warning: this option has been deprecated!
/// Enable plugin prefix detection.
#[arg(long)]
#[arg(hide = true, long)]
pub with_prefixes: bool,
}

impl Init {
pub fn execute(&self, args: &Arguments) -> Result<CommandSuccess, CommandError> {
if self.with_prefixes {
eprintln!(
"{} The --with-prefixes option has been deprecated and is no longer needed.",
style("⚠").yellow()
);
}

if !args.no_upgrade_check {
QltyRelease::upgrade_check().ok();
}
Expand Down Expand Up @@ -77,7 +85,6 @@ impl Init {
skip_plugins: self.skip_plugins,
skip_default_source: self.skip_default_source,
source: self.source.clone(),
with_prefixes: self.with_prefixes,
})?;

initializer.prepare()?;
Expand Down
80 changes: 5 additions & 75 deletions qlty-cli/src/initializer/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl Scanner {
package_filters,
plugin_initializer,
path_osstr,
self.settings.with_prefixes,
);
}

Expand Down Expand Up @@ -355,7 +354,6 @@ impl Scanner {
package_filters: Vec<String>,
plugin_initializer: &PluginInitializer,
path: &str,
with_prefixes: bool,
) {
if let Some(plugin_to_activate) =
plugins_to_activate.get_mut(&plugin_initializer.plugin_name)
Expand All @@ -365,21 +363,12 @@ impl Scanner {
.extend(package_filters.clone());

if let Some(package_file) = &plugin_to_activate.package_file {
if with_prefixes {
plugin_to_activate.package_file = Self::process_plugin_package_file_prefix(
package_file,
&mut plugin_to_activate.prefixes,
);
plugin_to_activate.package_file = Self::process_plugin_package_file_prefix(
package_file,
&mut plugin_to_activate.prefixes,
);

Self::process_plugin_package_file_prefix(
path,
&mut plugin_to_activate.prefixes,
);
} else if PathBuf::from(path).components().count()
< PathBuf::from(package_file).components().count()
{
plugin_to_activate.package_file = Some(path.to_owned());
}
Self::process_plugin_package_file_prefix(path, &mut plugin_to_activate.prefixes);
} else {
plugin_to_activate.package_file = Some(path.to_owned());
}
Expand Down Expand Up @@ -501,7 +490,6 @@ config_files = ["config.toml"]
skip_plugins: false,
skip_default_source: true,
source: Some(source_spec.clone()),
with_prefixes: false,
};

(
Expand Down Expand Up @@ -628,62 +616,6 @@ config_files = ["config.toml"]
.is_none());
}

#[test]
fn test_insert_package_filters_and_package_file_simple() {
let mut plugins_to_activate = HashMap::new();
let plugin_initializer = PluginInitializer {
plugin_name: "test".to_string(),
package_file_candidate: None,
package_file_candidate_filters: vec![],
driver_initializers: vec![],
};

let path = "deep/package.json";

Scanner::insert_package_filters_and_package_file(
&mut plugins_to_activate,
vec!["test".to_string()],
&plugin_initializer,
path,
false,
);

assert_eq!(plugins_to_activate.len(), 1);
assert_eq!(
plugins_to_activate.get("test").unwrap().package_file,
Some(path.to_string())
);
assert_eq!(
plugins_to_activate.get("test").unwrap().package_filters,
vec!["test".to_string()]
);

let path = "package.json";

Scanner::insert_package_filters_and_package_file(
&mut plugins_to_activate,
vec!["test2".to_string()],
&plugin_initializer,
path,
false,
);

assert_eq!(plugins_to_activate.len(), 1);
assert_eq!(
plugins_to_activate.get("test").unwrap().package_file,
Some(path.to_string())
);
assert_eq!(
plugins_to_activate.get("test").unwrap().package_filters,
vec!["test".to_string(), "test2".to_string()]
);

assert_eq!(
plugins_to_activate.get("test").unwrap().prefixes,
HashSet::new()
);
}

#[test]
fn test_insert_package_filters_and_package_file_with_prefixes() {
let mut plugins_to_activate = HashMap::new();
Expand All @@ -701,7 +633,6 @@ config_files = ["config.toml"]
vec!["test".to_string()],
&plugin_initializer,
path,
false,
);

assert_eq!(plugins_to_activate.len(), 1);
Expand All @@ -726,7 +657,6 @@ config_files = ["config.toml"]
vec!["test2".to_string()],
&plugin_initializer,
path,
true,
);

assert_eq!(plugins_to_activate.len(), 1);
Expand Down
1 change: 0 additions & 1 deletion qlty-cli/src/initializer/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ pub struct Settings {
pub skip_plugins: bool,
pub skip_default_source: bool,
pub source: Option<SourceSpec>,
pub with_prefixes: bool,
}
2 changes: 1 addition & 1 deletion qlty-cli/tests/cmd/init/prefix.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin.name = "qlty"
args = ["init", "--dry-run", "--skip-default-source", "--source", "local=../plugins", "--no-upgrade-check", "--with-prefixes"]
args = ["init", "--dry-run", "--skip-default-source", "--source", "local=../plugins", "--no-upgrade-check"]

0 comments on commit f36ac01

Please sign in to comment.