From 94cbe15b545f8db4339f8a0ee1fd0defa183dbdf Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 12 Jun 2019 15:54:28 -0700 Subject: [PATCH] Reserve names starting with a dollar sign, closes #191. --- CHANGELOG.md | 1 + server/src/project.rs | 15 ++++++++++++++- .../default.project.json | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test-projects/legacy-0.5.x-reserved-names/default.project.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be0f4c6..6bce35a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Added support for live-syncing `CollectionService` tags. * Added a warning when building binary place files, since they're still experimental and have bugs. * Added a warning when trying to use Rojo 0.5.x with a Rojo 0.4.x-only project. +* Added a warning when a Rojo project contains keys that start with `$`, which are reserved names. ([#191](https://github.com/LPGhatguy/rojo/issues/191)) * Added an icon to the plugin's toolbar button * Changed the plugin to use a docking widget for all UI. * Changed the plugin to ignore unknown properties when live-syncing. diff --git a/server/src/project.rs b/server/src/project.rs index ae2662ec..9a96dad7 100644 --- a/server/src/project.rs +++ b/server/src/project.rs @@ -20,7 +20,7 @@ pub static COMPAT_PROJECT_FILENAME: &'static str = "roblox-project.json"; /// want to do things like transforming paths to be absolute before handing them /// off to the rest of Rojo, we use this intermediate struct. #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] +#[serde(deny_unknown_fields, rename_all = "camelCase")] struct SourceProject { name: String, tree: SourceProjectNode, @@ -274,6 +274,17 @@ pub struct ProjectNode { } impl ProjectNode { + fn validate_reserved_names(&self) { + for (name, child) in &self.children { + if name.starts_with('$') { + warn!("Keys starting with '$' are reserved by Rojo to ensure forward compatibility."); + warn!("This project uses the key '{}', which should be renamed.", name); + } + + child.validate_reserved_names(); + } + } + fn to_source_node(&self, project_file_location: &Path) -> SourceProjectNode { let children = self.children.iter() .map(|(key, value)| (key.clone(), value.to_source_node(project_file_location))) @@ -513,6 +524,8 @@ impl Project { warn!(".project.json extension. This helps Rojo differentiate project files from"); warn!("other JSON files!"); } + + self.tree.validate_reserved_names(); } /// Issues a warning if no Rojo 0.5.x project is found, but there's a legacy diff --git a/test-projects/legacy-0.5.x-reserved-names/default.project.json b/test-projects/legacy-0.5.x-reserved-names/default.project.json new file mode 100644 index 00000000..7901b391 --- /dev/null +++ b/test-projects/legacy-0.5.x-reserved-names/default.project.json @@ -0,0 +1,9 @@ +{ + "name": "legacy-0.5.x-reserved-names", + "tree": { + "$className": "Folder", + "$warn-about-me": { + "$className": "Folder" + } + } +} \ No newline at end of file