Repository: uber/piranha (language: python)

Issue:
Rename `PiranhaLanguage.name` to `extension`
              Probably a nit for a separate PR, but... are using the field `name` to refer to the string representation of the language (i.e. `"kotlin"`) or the extension (i.e. `"kt")? Seems like a weird choice for "name" to be the second...

_Originally posted by @lazaroclapp in https://github.com/uber/piranha/pull/363#discussion_r1103298558_

Field to be renamed - https://github.com/uber/piranha/blob/master/src/models/language.rs#L32 (rename to `extension`)

-----
This is also a good issue for someone new to rust and wants to familiarize themselves with rust tooling. At a higher level - setup vscode for with rust-analyzer,  trigger rename refactoring and regex-replace.
Check list: 
- [ ] update the field name, getter / setter 
- [ ] Update the code comments, variable names and method names with the pattern

How to check if all is well (locally)?
```
cd polyglot/piranha
cargo build
cargo test
```
For mac users - `cargo test --no-default-features`             


Discussion / hints:

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index a65257973..341ca6ea8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -202,7 +202,7 @@ impl Piranha {
     let temp_dir_path = temp_dir.path();
     let sample_file = temp_dir_path.join(format!(
       "sample.{}",
-      self.piranha_arguments.language().name()
+      self.piranha_arguments.language().extension()
     ));
     let mut file = File::create(sample_file).unwrap();
     file
diff --git a/src/models/language.rs b/src/models/language.rs
index fed70993c..9580606fe 100644
--- a/src/models/language.rs
+++ b/src/models/language.rs
@@ -30,7 +30,7 @@ use super::{
 pub struct PiranhaLanguage {
   /// The extension of the language FIXME: - https://github.com/uber/piranha/issues/365
   #[get = "pub"]
-  name: String,
+  extension: String,
   /// the language (enum)
   #[get = "pub"]
   supported_language: SupportedLanguage,
@@ -88,7 +88,7 @@ impl PiranhaLanguage {
   pub(crate) fn can_parse(&self, de: &jwalk::DirEntry<((), ())>) -> bool {
     de.path()
       .extension()
-      .and_then(|e| e.to_str().filter(|x| x.eq(&self.name())))
+      .and_then(|e| e.to_str().filter(|x| x.eq(&self.extension())))
       .is_some()
   }
 
@@ -120,7 +120,7 @@ impl std::str::FromStr for PiranhaLanguage {
         let rules: Rules = parse_toml(include_str!("../cleanup_rules/java/rules.toml"));
         let edges: Edges = parse_toml(include_str!("../cleanup_rules/java/edges.toml"));
         Ok(Self {
-          name: language.to_string(),
+          extension: language.to_string(),
           supported_language: SupportedLanguage::Java,
           language: tree_sitter_java::language(),
           rules: Some(rules),
@@ -137,7 +137,7 @@ impl std::str::FromStr for PiranhaLanguage {
         let rules: Rules = parse_toml(include_str!("../cleanup_rules/go/rules.toml"));
         let edges: Edges = parse_toml(include_str!("../cleanup_rules/go/edges.toml"));
         Ok(PiranhaLanguage {
-          name: language.to_string(),
+          extension: language.to_string(),
           supported_language: SupportedLanguage::Go,
           language: tree_sitter_go::language(),
           rules: Some(rules),
@@ -152,7 +152,7 @@ impl std::str::FromStr for PiranhaLanguage {
         let rules: Rules = parse_toml(include_str!("../cleanup_rules/kt/rules.toml"));
         let edges: Edges = parse_toml(include_str!("../cleanup_rules/kt/edges.toml"));
         Ok(PiranhaLanguage {
-          name: language.to_string(),
+          extension: language.to_string(),
           supported_language: SupportedLanguage::Kotlin,
           language: tree_sitter_kotlin::language(),
           rules: Some(rules),
@@ -164,7 +164,7 @@ impl std::str::FromStr for PiranhaLanguage {
         })
       }
       PYTHON => Ok(PiranhaLanguage {
-        name: language.to_string(),
+        extension: language.to_string(),
         supported_language: SupportedLanguage::Python,
         language: tree_sitter_python::language(),
         rules: None,
@@ -176,7 +176,7 @@ impl std::str::FromStr for PiranhaLanguage {
         let rules: Rules = parse_toml(include_str!("../cleanup_rules/swift/rules.toml"));
         let edges: Edges = parse_toml(include_str!("../cleanup_rules/swift/edges.toml"));
         Ok(PiranhaLanguage {
-          name: language.to_string(),
+          extension: language.to_string(),
           supported_language: SupportedLanguage::Swift,
           language: tree_sitter_swift::language(),
           scopes: parse_toml::<ScopeConfig>(include_str!(
@@ -190,7 +190,7 @@ impl std::str::FromStr for PiranhaLanguage {
         })
       }
       TYPESCRIPT => Ok(PiranhaLanguage {
-        name: language.to_string(),
+        extension: language.to_string(),
         supported_language: SupportedLanguage::Ts,
         language: tree_sitter_typescript::language_typescript(),
         rules: None,
@@ -199,7 +199,7 @@ impl std::str::FromStr for PiranhaLanguage {
         comment_nodes: vec![],
       }),
       TSX => Ok(PiranhaLanguage {
-        name: language.to_string(),
+        extension: language.to_string(),
         supported_language: SupportedLanguage::Tsx,
         language: tree_sitter_typescript::language_tsx(),
         rules: None,
@@ -208,7 +208,7 @@ impl std::str::FromStr for PiranhaLanguage {
         comment_nodes: vec![],
       }),
       THRIFT => Ok(PiranhaLanguage {
-        name: language.to_string(),
+        extension: language.to_string(),
         supported_language: SupportedLanguage::Thrift,
         language: tree_sitter_thrift::language(),
         rules: None,
diff --git a/src/models/piranha_arguments.rs b/src/models/piranha_arguments.rs
index 1dad59d5a..0007675ee 100644
--- a/src/models/piranha_arguments.rs
+++ b/src/models/piranha_arguments.rs
@@ -240,7 +240,7 @@ impl PiranhaArguments {
 
 impl PiranhaArguments {
   pub fn get_language(&self) -> String {
-    self.language.name().to_string()
+    self.language.extension().to_string()
   }
 
   pub fn from_cli() -> Self {


Test patch:
diff --git a/src/models/unit_tests/source_code_unit_test.rs b/src/models/unit_tests/source_code_unit_test.rs
index 2f5ad59fa..a44c20b1f 100644
--- a/src/models/unit_tests/source_code_unit_test.rs
+++ b/src/models/unit_tests/source_code_unit_test.rs
@@ -86,7 +86,7 @@ fn test_apply_edit_positive() {
   let mut parser = java.parser();
 
   let mut source_code_unit =
-    SourceCodeUnit::default(source_code, &mut parser, java.name().to_string());
+    SourceCodeUnit::default(source_code, &mut parser, java.extension().to_string());
 
   let _ = source_code_unit.apply_edit(
     &Edit::delete_range(source_code, range(49, 78, 3, 9, 3, 38)),
@@ -115,7 +115,7 @@ fn test_apply_edit_negative() {
   let java = get_java_tree_sitter_language();
   let mut parser = java.parser();
   let mut source_code_unit =
-    SourceCodeUnit::default(source_code, &mut parser, java.name().to_string());
+    SourceCodeUnit::default(source_code, &mut parser, java.extension().to_string());
 
   let _ = source_code_unit.apply_edit(
     &Edit::delete_range(source_code, range(1000, 2000, 0, 0, 0, 0)),