Skip to content

Commit

Permalink
Reserve names starting with a dollar sign, closes rojo-rbx#191.
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Jun 12, 2019
1 parent da8be6d commit 9876169
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 14 additions & 1 deletion server/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "legacy-0.5.x-reserved-names",
"tree": {
"$className": "Folder",
"$warn-about-me": {
"$className": "Folder"
}
}
}

0 comments on commit 9876169

Please sign in to comment.