Skip to content

Commit

Permalink
Remove deprecated config key and template filters
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Aug 25, 2024
1 parent 2f68940 commit 048fde3
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 88 deletions.
34 changes: 2 additions & 32 deletions src/config/normalize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Normalize a raw config from the file into a [`Config`].
use std::str;
use std::str::FromStr;

use anyhow::{anyhow, bail, Context as ResultExt, Error, Result};
use indexmap::IndexMap;
Expand Down Expand Up @@ -83,31 +82,19 @@ fn normalize_plugin(
remote,
local,
inline,
mut proto,
proto,
reference,
dir,
uses,
apply,
profiles,
hooks,
mut rest,
rest,
} = raw_plugin;

let is_reference_some = reference.is_some();
let is_gist_or_github = gist.is_some() || github.is_some();

// Handle some deprecated items :/
if proto.is_none() {
if let Some(protocol) = try_pop_toml_value(&mut rest, "protocol") {
warnings.push(anyhow!(
"use of deprecated config key: `plugins.{name}.protocol`, please use \
`plugins.{name}.proto` instead",
name = name,
));
proto = Some(protocol);
}
}

check_extra_toml(rest, |key| {
warnings.push(anyhow!("unused config key: `plugins.{name}.{key}`"));
});
Expand Down Expand Up @@ -217,23 +204,6 @@ impl Source {
}
}

/// Try and pop the TOML value from the table.
fn try_pop_toml_value<T>(rest: &mut Option<toml::Value>, key: &str) -> Option<T>
where
T: FromStr,
{
if let Some(toml::Value::Table(table)) = rest {
if let Some(toml::Value::String(s)) = table.get(key) {
let result = s.parse().ok();
if result.is_some() {
table.remove(key);
}
return result;
}
}
None
}

/// Call the given function on all extra TOML keys.
fn check_extra_toml<F>(rest: Option<toml::Value>, mut f: F)
where
Expand Down
12 changes: 2 additions & 10 deletions src/lock/script.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Context as ResultExt, Error, Result};
use anyhow::{Context as ResultExt, Result};
use once_cell::sync::Lazy;
use serde::Serialize;
use std::collections::BTreeMap;
Expand All @@ -18,7 +18,7 @@ struct ExternalData<'a> {

impl LockedConfig {
/// Generate the script.
pub fn script(&self, ctx: &Context, warnings: &mut Vec<Error>) -> Result<String> {
pub fn script(&self, ctx: &Context) -> Result<String> {
static USED_GET: Lazy<Mutex<bool>> = Lazy::new(|| Mutex::new(false));

let mut engine = upon::Engine::new();
Expand Down Expand Up @@ -105,14 +105,6 @@ impl LockedConfig {
}
}

if *USED_GET.lock().unwrap() {
warnings.push(Error::msg(
"use of deprecated filter `get` in [templates], please use the `?.` operator \
instead.\nFor example: `{{ hooks | get: \"pre\" | nl }}` can be written `{{ \
hooks?.pre | nl }}`",
));
}

Ok(script)
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn source(ctx: &Context, warnings: &mut Vec<Error>) -> Result<()> {
};

let script = locked_config
.script(ctx, warnings)
.script(ctx)
.context("failed to render source")?;

if to_path && locked_config.errors.is_empty() {
Expand Down
8 changes: 0 additions & 8 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,6 @@ fn lock_and_source_hooks() -> io::Result<()> {
Ok(())
}

#[test]
fn lock_and_source_deprecated_get_filter() -> io::Result<()> {
let case = TestCase::load("deprecated_get_filter")?;
case.run()?;
check_sheldon_test(&case.dirs.data).unwrap();
Ok(())
}

#[test]
fn directories_default() -> io::Result<()> {
let dirs = TestDirs::default()?;
Expand Down
3 changes: 0 additions & 3 deletions tests/testdata/deprecated_get_filter/lock.stderr

This file was deleted.

21 changes: 0 additions & 21 deletions tests/testdata/deprecated_get_filter/plugins.lock

This file was deleted.

7 changes: 0 additions & 7 deletions tests/testdata/deprecated_get_filter/plugins.toml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/testdata/deprecated_get_filter/source.stderr

This file was deleted.

1 change: 0 additions & 1 deletion tests/testdata/deprecated_get_filter/source.stdout

This file was deleted.

0 comments on commit 048fde3

Please sign in to comment.