Skip to content

Commit

Permalink
Merge pull request #137 from TheSignPainter98/lint/min-version
Browse files Browse the repository at this point in the history
Add minimum version to lints
  • Loading branch information
TheSignPainter98 authored Nov 13, 2023
2 parents 11ee83a + ec6caf0 commit ac16394
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 65 deletions.
42 changes: 38 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,23 @@ where

fn load_manifest(ctx: &mut Context, src: &str, args: &Args) -> Result<()> {
let manifest = DocManifest::try_from(src)?;
ctx.set_name(manifest.metadata.name);
ctx.set_version(manifest.metadata.version.into());

let doc_info = ctx.doc_params_mut();
doc_info.set_name(manifest.metadata.name);
doc_info.set_emblem_version(manifest.metadata.emblem_version.into());

if let Some(authors) = manifest.metadata.authors {
doc_info.set_authors(authors);
}

if let Some(keywords) = manifest.metadata.keywords {
doc_info.set_keywords(keywords);
}

let lua_info = ctx.lua_params_mut();

let mut specific_args: HashMap<_, Vec<_>> = HashMap::new();
if let Some(lua_args) = args.lua_args() {
lua_info.set_sandbox_level(lua_args.sandbox_level.into());
lua_info.set_max_mem(lua_args.max_mem.into());
lua_info.set_max_steps(lua_args.max_steps.into());

let mut general_args = Vec::with_capacity(lua_args.args.len());
for arg in &lua_args.args {
let name = arg.name();
Expand All @@ -109,7 +105,6 @@ fn load_manifest(ctx: &mut Context, src: &str, args: &Args) -> Result<()> {

lua_info.set_general_args(general_args);
}

let modules = manifest
.dependencies
.unwrap_or_default()
Expand All @@ -125,13 +120,11 @@ fn load_manifest(ctx: &mut Context, src: &str, args: &Args) -> Result<()> {
module
})
.collect();

if !specific_args.is_empty() {
return Err(Error::unused_args(
specific_args.keys().map(ToString::to_string).collect(),
));
}

lua_info.set_modules(modules);

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl DocManifest {
pub(crate) struct DocMetadata {
pub(crate) name: String,
#[serde(rename = "emblem")]
pub(crate) emblem_version: Version,
pub(crate) version: Version,
pub(crate) authors: Option<Vec<String>>,
pub(crate) keywords: Option<Vec<String>>,
}
Expand Down Expand Up @@ -163,7 +163,7 @@ mod test {
let manifest = DocManifest::try_from(raw).unwrap();

assert_eq!("foo", manifest.metadata.name);
assert_eq!(Version::V1_0, manifest.metadata.emblem_version);
assert_eq!(Version::V1_0, manifest.metadata.version);
assert_eq!(None, manifest.metadata.authors);
assert_eq!(None, manifest.dependencies);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ mod test {
&["DARGH!", "NO!", "STAHP!", "HUEAG!"],
manifest.metadata.keywords.unwrap().as_slice()
);
assert_eq!(Version::V1_0, manifest.metadata.emblem_version);
assert_eq!(Version::V1_0, manifest.metadata.version);

{
let dependencies = manifest.dependencies.unwrap();
Expand Down Expand Up @@ -241,7 +241,7 @@ mod test {
}

#[test]
fn incorrect_emblem_version() {
fn incorrect_version() {
let missing = indoc::indoc!(
r#"
[document]
Expand Down
3 changes: 3 additions & 0 deletions crates/emblem_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ derive-new = "0.5.9"
derive_more = "0.99.17"
git2 = { version = "0.16.1", optional = true }
indoc = "2.0.1"
itertools = "0.11.0"
kinded = "0.3.0"
lalrpop = "0.19.8"
lalrpop-util = "0.19.8"
Expand All @@ -30,6 +31,8 @@ parking_lot = "0.12.1"
phf = { version = "0.11.1", features = ["macros"] }
regex = "1"
sealed = "0.5.0"
strum = { version = "0.25.0", features = ["derive"] }
strum_macros = "0.25.3"
thiserror = "1.0.48"
typed-arena = "2.0.1"
uniquote = "3.3.0"
Expand Down
40 changes: 20 additions & 20 deletions crates/emblem_core/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use std::fmt::Debug;

#[derive(Default)]
pub struct Context {
name: Option<String>,
version: Option<Version>,
doc_params: DocumentParameters,
lua_params: LuaParameters,
typesetter_params: TypesetterParameters,
Expand All @@ -37,6 +39,22 @@ impl Context {
}
}

pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}

pub fn set_name(&mut self, name: impl Into<String>) {
self.name = Some(name.into());
}

pub fn version(&self) -> Option<Version> {
self.version
}

pub fn set_version(&mut self, version: Version) {
self.version = Some(version);
}

pub fn alloc_file_name(&self, name: impl AsRef<str>) -> FileName {
FileName::new(name.as_ref())
}
Expand Down Expand Up @@ -90,6 +108,8 @@ impl Context {
impl Context {
pub fn test_new() -> Self {
Self {
name: Some("On the Origin of Burnt Toast".into()),
version: Some(Version::latest()),
doc_params: DocumentParameters::test_new(),
lua_params: LuaParameters::test_new(),
typesetter_params: TypesetterParameters::test_new(),
Expand All @@ -102,29 +122,11 @@ impl Context {
#[derive(Debug, Default)]
pub struct DocumentParameters {
// TODO(kcza): use a nice Rc<str>-like representation
name: Option<String>,
emblem_version: Option<Version>,
authors: Option<Vec<String>>,
keywords: Option<Vec<String>>,
}

impl DocumentParameters {
pub fn set_name(&mut self, name: impl Into<String>) {
self.name = Some(name.into());
}

pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}

pub fn set_emblem_version(&mut self, emblem_version: Version) {
self.emblem_version = Some(emblem_version);
}

pub fn emblem_version(&self) -> &Option<Version> {
&self.emblem_version
}

pub fn set_authors(&mut self, authors: Vec<String>) {
self.authors = Some(authors);
}
Expand All @@ -145,8 +147,6 @@ impl DocumentParameters {
impl DocumentParameters {
pub fn test_new() -> Self {
Self {
name: Some("On the Origin of Burnt Toast".into()),
emblem_version: Some(Version::V1_0),
authors: Some(vec!["kcza".into()]),
keywords: Some(
["toast", "burnt", "backstory"]
Expand Down
5 changes: 5 additions & 0 deletions crates/emblem_core/src/lint/lints/attr_ordering.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::ast::parsed::{Attr, Content};
use crate::lint::{Lint, LintId};
use crate::log::{Log, Note, Src};
use crate::Version;
use derive_new::new;

#[derive(new)]
pub struct AttrOrdering {}

impl Lint for AttrOrdering {
fn min_version(&self) -> Version {
Version::V1_0
}

fn id(&self) -> LintId {
"attr-ordering".into()
}
Expand Down
5 changes: 5 additions & 0 deletions crates/emblem_core/src/lint/lints/command_naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ast::parsed::Content;
use crate::context::file_content::FileSlice;
use crate::lint::{Lint, LintId};
use crate::log::{Log, Note, Src};
use crate::Version;
use derive_new::new;
use lazy_static::lazy_static;
use regex::Regex;
Expand All @@ -14,6 +15,10 @@ lazy_static! {
}

impl Lint for CommandNaming {
fn min_version(&self) -> Version {
Version::V1_0
}

fn id(&self) -> LintId {
"command-naming".into()
}
Expand Down
5 changes: 5 additions & 0 deletions crates/emblem_core/src/lint/lints/duplicate_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ use crate::context::file_content::FileSlice;
use crate::lint::Lint;
use crate::lint::LintId;
use crate::log::{Log, Note, Src};
use crate::Version;
use derive_new::new;

#[derive(new)]
pub struct DuplicateAttrs {}

impl Lint for DuplicateAttrs {
fn min_version(&self) -> Version {
Version::V1_0
}

fn id(&self) -> LintId {
"duplicate-attrs".into()
}
Expand Down
5 changes: 5 additions & 0 deletions crates/emblem_core/src/lint/lints/emph_delimiters.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::ast::parsed::{Content, Sugar};
use crate::lint::{Lint, LintId};
use crate::log::{Log, Note, Src};
use crate::Version;
use derive_new::new;

#[derive(new)]
pub struct EmphDelimiters {}

impl Lint for EmphDelimiters {
fn min_version(&self) -> Version {
Version::V1_0
}

fn id(&self) -> LintId {
"emph-delimiters".into()
}
Expand Down
5 changes: 5 additions & 0 deletions crates/emblem_core/src/lint/lints/empty_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::ast::parsed::Content;
use crate::lint::{Lint, LintId};
use crate::log::{Log, Note, Src};
use crate::Version;
use derive_new::new;

#[derive(new)]
pub struct EmptyAttrs {}

impl Lint for EmptyAttrs {
fn min_version(&self) -> Version {
Version::V1_0
}

fn id(&self) -> LintId {
"empty-attrs".into()
}
Expand Down
Loading

0 comments on commit ac16394

Please sign in to comment.