-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Backport and release 0.4000.0-rc.1 (#396)
* Bump crate version * feat: Create links from/to `ExternalHash` (#380) * add ExternalHash field types and option to target this type when scaffolding a link-type * ensure external hash is imported in type declarations * feat: create links from/to AnyLinkableHash * Add AnyLinkablehHash field type templates and add to reserved words * fix failed to resolve errors * improve checking for reserved keywords * fix invalid link-type delete method in test template * simplify reserved_words hashsets * update cli * Extend reserved keywords to check for javascript keywords * Update AnyLinkableHash sample value * Extend reserved words check tests * fix AnyLinkableHash link-type tests * Fix AnyLinkableHash link-type tests and remove redundant AND/OR hbs helpers * update inner_choose_referenceable * /AnyLinkableHash/ExternalHash * Update invalid serserved word error message * Refactor entry/link type utils * Add some context to the [None] option when scaffolding a link-type * /AnyLinkableHash/ExternalHash in link-type template * Fix option placement * Prevent UI from getting generated where the base type of a link is an ExternalHash * ExternalHash links can be bidirectional * Only skip ui if to_referenceable is some and the field_type is of ExternalHash * Remove unnecessary into call in delete link function * Fix rustfmt ci failure * Fix missing conversion * Fix react link-type template * feat: Improve `hc-scaffold entry-type` developer experience (#383) * refactor enum type selection; add option to restart field type selection; refactor FieldType parsing * Improve EntryTypeReference parsing * Improve parse_enum parsing logic * Update field_type parsing logic * fix: Optimize nix flake (#384) * optimize nix flake * Supress clippy warnings * Nix flake update
- Loading branch information
Showing
33 changed files
with
908 additions
and
660 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,120 @@ | ||
use std::collections::HashSet; | ||
|
||
use crate::error::{ScaffoldError, ScaffoldResult}; | ||
|
||
const RESERVED_WORDS: [&str; 27] = [ | ||
"type", | ||
/// Returns an error if the given string is invalid due to it being a reserved word | ||
pub fn check_for_reserved_keywords(string_to_check: &str) -> ScaffoldResult<()> { | ||
let reserved_holochain_words_set = HashSet::from(HOLOCHAIN_RESERVED_KEYWORDS); | ||
let reserved_rust_words_set = HashSet::from(RUST_RESERVED_KEYWORDS); | ||
let reserved_javascript_words_set = HashSet::from(JAVASCRIPT_RESERVED_KEYWORDS); | ||
|
||
if reserved_holochain_words_set.contains(string_to_check.to_ascii_lowercase().as_str()) { | ||
return Err(ScaffoldError::InvalidReservedWord { | ||
context: "holochain".to_string(), | ||
word: string_to_check.to_string(), | ||
}); | ||
} | ||
|
||
if reserved_rust_words_set.contains(string_to_check.to_ascii_lowercase().as_str()) { | ||
return Err(ScaffoldError::InvalidReservedWord { | ||
context: "rust".to_string(), | ||
word: string_to_check.to_string(), | ||
}); | ||
} | ||
|
||
if reserved_javascript_words_set.contains(string_to_check.to_ascii_lowercase().as_str()) { | ||
return Err(ScaffoldError::InvalidReservedWord { | ||
context: "javascript".to_string(), | ||
word: string_to_check.to_string(), | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
const HOLOCHAIN_RESERVED_KEYWORDS: [&str; 16] = [ | ||
"role", | ||
"enum", | ||
"pub", | ||
"fn", | ||
"mod", | ||
"struct", | ||
"const", | ||
"Option", | ||
"Result", | ||
"crate", | ||
"hdi", | ||
"hdk", | ||
"return", | ||
"if", | ||
"action", | ||
"entry", | ||
"record", | ||
"zome", | ||
"dna", | ||
"entrytype", | ||
"entryhash", | ||
"actionhash", | ||
"agentpubkey", | ||
"anylinkablehash", | ||
"holohash", | ||
"externalhash", | ||
"call", | ||
]; | ||
|
||
// <https://doc.rust-lang.org/reference/keywords.html> | ||
const RUST_RESERVED_KEYWORDS: [&str; 50] = [ | ||
"as", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn", "for", | ||
"if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", | ||
"self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", | ||
"while", "abstract", "async", "await", "become", "box", "do", "final", "macro", "override", | ||
"priv", "try", "typeof", "unsized", "virtual", "yield", | ||
]; | ||
|
||
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words> | ||
const JAVASCRIPT_RESERVED_KEYWORDS: [&str; 35] = [ | ||
"break", | ||
"case", | ||
"catch", | ||
"class", | ||
"const", | ||
"continue", | ||
"debugger", | ||
"default", | ||
"delete", | ||
"do", | ||
"else", | ||
"match", | ||
"Action", | ||
"Entry", | ||
"Record", | ||
"Zome", | ||
"Dna", | ||
"EntryType", | ||
"EntryHash", | ||
"ActionHash", | ||
"AgentPubKey", | ||
"Call", | ||
"export", | ||
"extends", | ||
"false", | ||
"finally", | ||
"for", | ||
"function", | ||
"if", | ||
"import", | ||
"in", | ||
"instanceof", | ||
"new", | ||
"null", | ||
"return", | ||
"super", | ||
"switch", | ||
"this", | ||
"throw", | ||
"true", | ||
"try", | ||
"typeof", | ||
"var", | ||
"void", | ||
"while", | ||
"with", | ||
]; | ||
|
||
/// Returns an error if the given string is invalid due to it being a reserved word | ||
pub fn check_for_reserved_words(string_to_check: &str) -> ScaffoldResult<()> { | ||
if RESERVED_WORDS | ||
.iter() | ||
.any(|w| string_to_check.eq_ignore_ascii_case(w)) | ||
{ | ||
return Err(ScaffoldError::InvalidReservedWord( | ||
string_to_check.to_string(), | ||
)); | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn check_for_reserved_keywords_works() { | ||
let valid = check_for_reserved_keywords("Value"); | ||
assert!(valid.is_ok()); | ||
|
||
let invalid = check_for_reserved_keywords("static"); | ||
assert!(invalid.is_err()); | ||
|
||
let invalid = check_for_reserved_keywords("EntryType"); | ||
assert!(invalid.is_err()); | ||
|
||
let invalid = check_for_reserved_keywords("new"); | ||
assert!(invalid.is_err()); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.