├── .github └── workflows │ ├── polyglot_build.yml │ ├── polyglot_release.yml │ └── release_playground.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE ├── NOTICE ├── POLYGLOT_README.md ├── README.md ├── RELEASING.md ├── build.rs ├── demo ├── feature_flag_cleanup │ ├── java │ │ ├── SampleClass.java │ │ ├── TestEnum.java │ │ └── configurations │ │ │ └── rules.toml │ └── kt │ │ ├── SampleClass.kt │ │ ├── TestEnum.kt │ │ └── configurations │ │ └── rules.toml ├── feature_flag_cleanup_using_py_api │ └── java │ │ └── SampleClass.java ├── find_replace │ ├── java │ │ ├── TestEnum.java │ │ └── configurations │ │ │ └── rules.toml │ ├── swift │ │ ├── Sample.swift │ │ └── configurations │ │ │ └── rules.toml │ └── thrift │ │ └── sample.thrift ├── find_replace_custom_cleanup │ ├── java │ │ ├── AnotherClass.java │ │ ├── SomeClass.java │ │ └── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ └── python │ │ ├── configurations │ │ ├── edges.toml │ │ └── rules.toml │ │ └── only_lists.py ├── find_replace_custom_cleanup_demos.py ├── find_replace_demos.py ├── match_only │ ├── go │ │ ├── configurations │ │ │ └── rules.toml │ │ └── sample.go │ ├── java │ │ ├── Sample.java │ │ └── configurations │ │ │ └── rules.toml │ ├── ts │ │ ├── configurations │ │ │ └── rules.toml │ │ └── sample.ts │ └── tsx │ │ ├── configurations │ │ └── rules.toml │ │ └── sample.tsx ├── match_only_demos.py ├── stale_feature_flag_cleanup_demos.py ├── stale_feature_flag_cleanup_demos_using_py_api.py └── thrift_demos.py ├── experimental ├── CHANGELOG.md ├── MANIFEST.in ├── README.md ├── RELEASE.md ├── piranha_playground │ ├── __init__.py │ ├── data_validation.py │ ├── demo │ │ ├── after.java │ │ └── before.java │ ├── main.py │ ├── rule_inference │ │ ├── __init__.py │ │ ├── controller.py │ │ ├── graph_parser.py │ │ ├── piranha_agent.py │ │ ├── piranha_chat.py │ │ ├── rule_application.py │ │ ├── static_inference.py │ │ ├── template_parser.py │ │ ├── tests │ │ │ ├── __init__.py │ │ │ ├── test_codebase_refactorer.py │ │ │ ├── test_controller.py │ │ │ ├── test_graph_parser.py │ │ │ ├── test_inference.py │ │ │ ├── test_piranha_agent.py │ │ │ ├── test_server.py │ │ │ └── test_template_parser.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── logger_formatter.py │ │ │ ├── node_utils.py │ │ │ ├── pretty_toml.py │ │ │ └── rule_utils.py │ ├── static │ │ ├── script.js │ │ └── styles.css │ └── templates │ │ └── index.html ├── requirements.txt └── setup.py ├── images ├── go_prebuilt_rules.svg ├── java_prebuilt_rules.svg ├── kotlin_prebuilt_rules.svg └── piranha_architecture.svg ├── license_header.txt ├── plugins ├── pyproject.toml ├── spark_upgrade │ ├── IDF_model_signature_change.py │ ├── README.md │ ├── accessing_execution_plan.py │ ├── calculator_signature_change.py │ ├── execute_piranha.py │ ├── gradient_boost_trees.py │ ├── java_spark_context │ │ └── __init__.py │ ├── main.py │ ├── query_test_check_answer_change.py │ ├── requirements.txt │ ├── scala_session_builder │ │ └── __init__.py │ ├── spark_config │ │ └── __init__.py │ ├── sql_new_execution.py │ ├── tests │ │ ├── __init__.py │ │ ├── resources │ │ │ ├── accessing_execution_plan │ │ │ │ ├── expected │ │ │ │ │ └── sample.scala │ │ │ │ └── input │ │ │ │ │ └── sample.scala │ │ │ ├── calculator_signature_change │ │ │ │ ├── expected │ │ │ │ │ └── sample.scala │ │ │ │ └── input │ │ │ │ │ └── sample.scala │ │ │ ├── gradient_boost_trees │ │ │ │ ├── expected │ │ │ │ │ ├── sample.scala │ │ │ │ │ └── sample2.scala │ │ │ │ └── input │ │ │ │ │ ├── sample.scala │ │ │ │ │ └── sample2.scala │ │ │ ├── idf_model_signature_change │ │ │ │ ├── expected │ │ │ │ │ └── sample.scala │ │ │ │ └── input │ │ │ │ │ └── sample.scala │ │ │ ├── spark_conf │ │ │ │ ├── expected │ │ │ │ │ ├── sample.java │ │ │ │ │ ├── sample.scala │ │ │ │ │ ├── sample2.java │ │ │ │ │ ├── sample2.scala │ │ │ │ │ ├── sample3.java │ │ │ │ │ └── sample3.scala │ │ │ │ └── input │ │ │ │ │ ├── sample.java │ │ │ │ │ ├── sample.scala │ │ │ │ │ ├── sample2.java │ │ │ │ │ ├── sample2.scala │ │ │ │ │ ├── sample3.java │ │ │ │ │ └── sample3.scala │ │ │ ├── sql_new_execution │ │ │ │ ├── expected │ │ │ │ │ └── sample.scala │ │ │ │ └── input │ │ │ │ │ └── sample.scala │ │ │ └── update_calendar_interval │ │ │ │ ├── expected │ │ │ │ └── sample.scala │ │ │ │ └── input │ │ │ │ └── sample.scala │ │ └── test_spark_upgrade.py │ └── update_calendar_interval.py └── zap-transformation │ ├── __main__.py │ └── resource │ └── sample.go ├── polyglot_piranha.pyi ├── pyproject.toml ├── report.pdf ├── rustfmt.toml ├── src ├── cleanup_rules │ ├── go │ │ ├── edges.toml │ │ ├── rules.toml │ │ └── scope_config.toml │ ├── java │ │ ├── edges.toml │ │ ├── rules.toml │ │ └── scope_config.toml │ ├── java_cs │ │ ├── edges.toml │ │ ├── rules.toml │ │ └── scope_config.toml │ ├── kt │ │ ├── edges.toml │ │ ├── rules.toml │ │ └── scope_config.toml │ ├── ruby │ │ ├── edges.toml │ │ ├── rules.toml │ │ └── scope_config.toml │ ├── scala │ │ └── scope_config.toml │ └── swift │ │ ├── edges.toml │ │ ├── rules.toml │ │ └── scope_config.toml ├── df │ ├── README.md │ ├── analysis.rs │ ├── mod.rs │ ├── tag_analysis.rs │ ├── unit_tests │ │ └── tag_analysis_test.rs │ └── utils.rs ├── lib.rs ├── main.rs ├── models │ ├── capture_group_patterns.rs │ ├── concrete_syntax.rs │ ├── default_configs.rs │ ├── edit.rs │ ├── filter.rs │ ├── language.rs │ ├── matches.rs │ ├── mod.rs │ ├── outgoing_edges.rs │ ├── piranha_arguments.rs │ ├── piranha_output.rs │ ├── rule.rs │ ├── rule_graph.rs │ ├── rule_store.rs │ ├── scopes.rs │ ├── source_code_unit.rs │ └── unit_tests │ │ ├── concrete_syntax_test.rs │ │ ├── piranha_arguments_test.rs │ │ ├── rule_graph_validation_test.rs │ │ ├── rule_test.rs │ │ ├── scopes_test.rs │ │ ├── source_code_unit_test.rs │ │ └── testdata │ │ └── custom_builtin │ │ ├── edges.toml │ │ └── rules.toml ├── tests │ ├── mod.rs │ ├── test_piranha_go.rs │ ├── test_piranha_java.rs │ ├── test_piranha_kt.rs │ ├── test_piranha_python.rs │ ├── test_piranha_scala.rs │ ├── test_piranha_scm.rs │ ├── test_piranha_strings.rs │ ├── test_piranha_swift.rs │ ├── test_piranha_thrift.rs │ ├── test_piranha_ts.rs │ ├── test_piranha_tsx.rs │ └── test_piranha_yaml.rs └── utilities │ ├── mod.rs │ ├── regex_utilities.rs │ ├── tree_sitter_utilities.rs │ └── unit_tests │ ├── tree_sitter_utilities_test.rs │ └── utilities_test.rs ├── test-resources ├── go │ ├── feature_flag │ │ ├── builtin_rules │ │ │ ├── boolean_expression_simplify │ │ │ │ ├── configurations │ │ │ │ │ └── rules.toml │ │ │ │ ├── expected │ │ │ │ │ └── sample.go │ │ │ │ └── input │ │ │ │ │ └── sample.go │ │ │ └── statement_cleanup │ │ │ │ ├── configurations │ │ │ │ └── rules.toml │ │ │ │ ├── expected │ │ │ │ └── sample.go │ │ │ │ └── input │ │ │ │ └── sample.go │ │ └── system_1 │ │ │ └── const_same_file │ │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ └── sample.go │ │ │ └── input │ │ │ └── sample.go │ └── structural_find │ │ ├── expression_with_string_literal │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── sample.go │ │ ├── for_loop │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── sample.go │ │ └── go_stmt_for_loop │ │ ├── configurations │ │ └── rules.toml │ │ └── input │ │ └── sample.go ├── java │ ├── consecutive_scope_level_rules │ │ ├── expected │ │ │ └── TestClass.java │ │ └── input │ │ │ └── TestClass.java │ ├── custom_rules │ │ ├── custom_rules │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── delete_comments │ │ ├── expected │ │ │ └── Test.java │ │ └── input │ │ │ └── Test.java │ ├── delete_method_invocation_argument │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── delete_method_invocation_argument_invalid │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── delete_method_invocation_argument_no_op │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── delete_unused_field │ │ ├── expected │ │ │ └── TestClass.java │ │ └── input │ │ │ └── TestClass.java │ ├── feature_flag_system_1 │ │ ├── control │ │ │ ├── configurations │ │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ │ ├── TestEnum.java │ │ │ │ └── XPFlagCleanerPositiveCases.java │ │ │ └── input │ │ │ │ ├── TestEnum.java │ │ │ │ └── XPFlagCleanerPositiveCases.java │ │ └── treated │ │ │ ├── configurations │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ └── XPFlagCleanerPositiveCases.java │ │ │ └── input │ │ │ ├── TestEnum.java │ │ │ └── XPFlagCleanerPositiveCases.java │ ├── feature_flag_system_2 │ │ ├── control │ │ │ ├── configurations │ │ │ │ ├── edges.toml │ │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ │ ├── ExperimentInterface.java │ │ │ │ ├── ExperimentInterfaceAnnotatedInterface.java │ │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.java │ │ │ │ ├── XPFlagCleanerInterfaceMethod.java │ │ │ │ └── XPMethodChainCases.java │ │ │ └── input │ │ │ │ ├── ExperimentInterface.java │ │ │ │ ├── ExperimentInterfaceAnnotatedInterface.java │ │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.java │ │ │ │ ├── XPFlagCleanerInterfaceMethod.java │ │ │ │ └── XPMethodChainCases.java │ │ └── treated │ │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ ├── ExperimentInterface.java │ │ │ ├── ExperimentInterfaceAnnotatedInterface.java │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.java │ │ │ ├── XPFlagCleanerInterfaceMethod.java │ │ │ └── XPMethodChainCases.java │ │ │ └── input │ │ │ ├── ExperimentInterface.java │ │ │ ├── ExperimentInterfaceAnnotatedInterface.java │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.java │ │ │ ├── XPFlagCleanerInterfaceMethod.java │ │ │ └── XPMethodChainCases.java │ ├── find_and_propagate │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── TestClass.java │ │ │ └── TestSubClass.java │ │ └── input │ │ │ ├── TestClass.java │ │ │ └── TestSubClass.java │ ├── find_and_propagate_invalid_substitutions │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── TestClass.java │ │ │ └── TestSubClass.java │ │ └── input │ │ │ ├── TestClass.java │ │ │ └── TestSubClass.java │ ├── handle_syntactically_incorrect_tree │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── incorrect_rule │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── Sample.java │ ├── insert_field_and_import │ │ ├── expected │ │ │ └── TestClass.java │ │ └── input │ │ │ └── TestClass.java │ ├── insert_field_and_initializer │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── AnotherClass.java │ │ │ └── TestClass.java │ │ └── input │ │ │ ├── AnotherClass.java │ │ │ └── TestClass.java │ ├── new_line_character_used_in_string_literal │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── SomeClass.java │ │ └── input │ │ │ └── SomeClass.java │ ├── non_seed_user_rule │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── AnotherClass.java │ │ │ └── SomeClass.java │ │ └── input │ │ │ ├── AnotherClass.java │ │ │ └── SomeClass.java │ ├── parent_iterative │ │ ├── negative │ │ │ ├── configurations │ │ │ │ ├── edges.toml │ │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ │ └── sample.java │ │ │ └── input │ │ │ │ └── sample.java │ │ └── positive │ │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ └── sample.java │ │ │ └── input │ │ │ └── sample.java │ ├── regex_based_matcher │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── structural_find │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ └── input │ │ │ ├── SampleEnum.java │ │ │ └── XPFlagCleanerPositiveCases.java │ ├── structural_find_replace_multiple_code_bases │ │ ├── folder_1 │ │ │ └── Sample.java │ │ ├── folder_2 │ │ │ └── Sample.java │ │ └── folder_3 │ │ │ └── Sample.java │ ├── structural_find_with_include_exclude │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ └── input │ │ │ ├── folder_1 │ │ │ ├── SomeEnum.java │ │ │ └── SomeOtherClass.java │ │ │ └── folder_2 │ │ │ ├── SampleEnum.java │ │ │ ├── XPFlagCleanerPositiveCases.java │ │ │ └── folder_2_1 │ │ │ └── SomeClass.java │ ├── user_option_delete_consecutive_lines │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ ├── user_option_delete_if_empty │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── .placeholder │ │ └── input │ │ │ └── Sample.java │ ├── user_option_do_not_delete_consecutive_lines │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.java │ │ └── input │ │ │ └── Sample.java │ └── user_option_do_not_delete_if_empty │ │ ├── configurations │ │ └── rules.toml │ │ ├── expected │ │ └── Sample.java │ │ └── input │ │ └── Sample.java ├── kt │ ├── feature_flag_system_1 │ │ ├── control │ │ │ ├── configurations │ │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ │ ├── TestEnum.kt │ │ │ │ └── XPFlagCleanerCases.kt │ │ │ └── input │ │ │ │ ├── TestEnum.kt │ │ │ │ └── XPFlagCleanerCases.kt │ │ └── treated │ │ │ ├── configurations │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ ├── TestEnum.kt │ │ │ └── XPFlagCleanerCases.kt │ │ │ └── input │ │ │ ├── TestEnum.kt │ │ │ └── XPFlagCleanerCases.kt │ ├── feature_flag_system_2 │ │ ├── control │ │ │ ├── configurations │ │ │ │ ├── edges.toml │ │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ │ ├── ExperimentInterface.kt │ │ │ │ ├── ExperimentInterfaceAnnotatedInterface.kt │ │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.kt │ │ │ │ ├── XPFlagCleanerInterfaceMethod.kt │ │ │ │ └── XPMethodChainCases.kt │ │ │ └── input │ │ │ │ ├── ExperimentInterface.kt │ │ │ │ ├── ExperimentInterfaceAnnotatedInterface.kt │ │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.kt │ │ │ │ ├── XPFlagCleanerInterfaceMethod.kt │ │ │ │ └── XPMethodChainCases.kt │ │ └── treated │ │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ ├── ExperimentInterface.kt │ │ │ ├── ExperimentInterfaceAnnotatedInterface.kt │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.kt │ │ │ ├── XPFlagCleanerInterfaceMethod.kt │ │ │ └── XPMethodChainCases.kt │ │ │ └── input │ │ │ ├── ExperimentInterface.kt │ │ │ ├── ExperimentInterfaceAnnotatedInterface.kt │ │ │ ├── OtherXPFlagCleanerInterfaceMethod.kt │ │ │ ├── XPFlagCleanerInterfaceMethod.kt │ │ │ └── XPMethodChainCases.kt │ └── file_scoped_chain_rules │ │ ├── configurations │ │ ├── edges.toml │ │ └── rules.toml │ │ ├── expected │ │ └── Sample.kt │ │ └── input │ │ └── Sample.kt ├── python │ ├── delete_cleanup_str_in_list │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── only_lists.py │ │ └── input │ │ │ └── only_lists.py │ └── structural_find │ │ ├── configurations │ │ └── rules.toml │ │ └── input │ │ ├── list_as_arg.py │ │ └── only_lists.py ├── ruby │ ├── delete_lines_after_return │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── delete_lines_after_return.rb │ │ └── input │ │ │ └── delete_lines_after_return.rb │ ├── replace_empty_if_or_unless_statement │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── test_empty_if_unless_rules.rb │ │ └── input │ │ │ └── test_empty_if_unless_rules.rb │ ├── replace_if_statement │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── test_if_rules_inline.rb │ │ │ ├── test_if_rules_with_else_block.rb │ │ │ └── test_if_rules_without_else_block.rb │ │ └── input │ │ │ ├── test_if_rules_inline.rb │ │ │ ├── test_if_rules_with_else_block.rb │ │ │ └── test_if_rules_without_else_block.rb │ ├── replace_ternary_operator │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── test_if_rules_ternary.rb │ │ └── input │ │ │ └── test_if_rules_ternary.rb │ ├── replace_unless_statement │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── test_unless_rules_inline.rb │ │ │ ├── test_unless_rules_with_else_block.rb │ │ │ └── test_unless_rules_without_else_block.rb │ │ └── input │ │ │ ├── test_unless_rules_inline.rb │ │ │ ├── test_unless_rules_with_else_block.rb │ │ │ └── test_unless_rules_without_else_block.rb │ ├── simplify_boolean_expressions │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── boolean_simplify.rb │ │ └── input │ │ │ └── boolean_simplify.rb │ ├── simplify_if_lambda_conditional_statements │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── simplify_if_lambda_conditional_statements.rb │ │ └── input │ │ │ └── simplify_if_lambda_conditional_statements.rb │ ├── simplify_if_proc_conditional_statements │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── simplify_if_proc_conditional_statements.rb │ │ └── input │ │ │ └── simplify_if_proc_conditional_statements.rb │ ├── simplify_rspec_block_expressions │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── simplify_rspec_block_expressions.rb │ │ └── input │ │ │ └── simplify_rspec_block_expressions.rb │ ├── simplify_unless_lambda_conditional_statements │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── simplify_unless_lambda_conditional_statements.rb │ │ └── input │ │ │ └── simplify_unless_lambda_conditional_statements.rb │ ├── simplify_unless_proc_conditional_statements │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── simplify_unless_proc_conditional_statements.rb │ │ └── input │ │ │ └── simplify_unless_proc_conditional_statements.rb │ └── simplify_variable_assigned_flag_check │ │ ├── configurations │ │ ├── edges.toml │ │ └── rules.toml │ │ ├── expected │ │ └── simplify_variable_assigned_flag_check.rb │ │ └── input │ │ └── simplify_variable_assigned_flag_check.rb ├── scala │ └── simple_match_replace │ │ ├── configurations │ │ └── rules.toml │ │ ├── expected │ │ └── Sample.scala │ │ └── input │ │ └── Sample.scala ├── scm │ └── simple_rename │ │ ├── configurations │ │ └── rules.toml │ │ ├── expected │ │ └── sample.scm │ │ └── input │ │ └── sample.scm ├── strings │ └── sample_strings │ │ ├── configurations │ │ └── rules.toml │ │ ├── expected │ │ └── sample_en.strings │ │ └── input │ │ └── sample_en.strings ├── swift │ ├── cascade_file_delete │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── Experiment.swift │ │ │ ├── Factory.swift │ │ │ └── SomeProtocols.swift │ │ └── input │ │ │ ├── Experiment.swift │ │ │ ├── Factory.swift │ │ │ └── SomeProtocols.swift │ ├── cascade_file_delete_custom_global_tag │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── Experiment.swift │ │ │ ├── Factory.swift │ │ │ └── SomeProtocols.swift │ │ └── input │ │ │ ├── Experiment.swift │ │ │ ├── Factory.swift │ │ │ └── SomeProtocols.swift │ ├── cleanup_rules │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── SampleClass.swift │ │ └── input │ │ │ └── SampleClass.swift │ ├── cleanup_with_derivatives │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.swift │ │ └── input │ │ │ └── Sample.swift │ ├── leading_comma │ │ ├── configurations │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── Sample.swift │ │ └── input │ │ │ └── Sample.swift │ ├── post_processing_cleanup │ │ ├── clean_empty_switch_entry │ │ │ ├── configurations │ │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ │ └── SampleClass.swift │ │ │ └── input │ │ │ │ └── SampleClass.swift │ │ └── delete_statements_after_return │ │ │ ├── configurations │ │ │ └── rules.toml │ │ │ ├── expected │ │ │ └── SampleClass.swift │ │ │ └── input │ │ │ └── SampleClass.swift │ └── variable_inline │ │ ├── adhoc_variable_inline │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ └── AdhocVariableInlining.swift │ │ └── input │ │ │ └── AdhocVariableInlining.swift │ │ ├── constructor_variable_inline │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── test1.swift │ │ │ ├── test2.swift │ │ │ ├── test3.swift │ │ │ ├── test4.swift │ │ │ └── test5.swift │ │ └── input │ │ │ ├── test1.swift │ │ │ ├── test2.swift │ │ │ ├── test3.swift │ │ │ ├── test4.swift │ │ │ └── test5.swift │ │ ├── field_variable_inline │ │ ├── configurations │ │ │ ├── edges.toml │ │ │ └── rules.toml │ │ ├── expected │ │ │ ├── FieldVariableInline.swift │ │ │ └── NonFieldVariableInline.swift │ │ └── input │ │ │ ├── FieldVariableInline.swift │ │ │ └── NonFieldVariableInline.swift │ │ └── local_variable_inline │ │ ├── configurations │ │ ├── edges.toml │ │ └── rules.toml │ │ ├── expected │ │ └── VariableInlining.swift │ │ └── input │ │ └── VariableInlining.swift ├── thrift │ └── match_exception_type │ │ ├── configurations │ │ └── rules.toml │ │ ├── expected │ │ └── sample.thrift │ │ └── input │ │ └── sample.thrift ├── tsx │ └── structural_find │ │ ├── find_jsx_elements │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── sample.tsx │ │ ├── find_props_identifiers_within_b_jsx_elements │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── sample.tsx │ │ └── find_props_identifiers_within_variable_declarators_not_within_divs │ │ ├── configurations │ │ └── rules.toml │ │ └── input │ │ └── sample.tsx ├── typescript │ └── structural_find │ │ ├── find_fors │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── sample.ts │ │ ├── find_fors_within_functions │ │ ├── configurations │ │ │ └── rules.toml │ │ └── input │ │ │ └── sample.ts │ │ └── find_fors_within_functions_not_within_whiles │ │ ├── configurations │ │ └── rules.toml │ │ └── input │ │ └── sample.ts ├── utility_tests │ └── sample.toml └── yaml │ └── find_replace │ ├── configurations │ └── rules.toml │ ├── expected │ └── sample.yaml │ └── input │ └── sample.yaml ├── tests └── tests.py └── visualize_rules_graph.py /.github/workflows/release_playground.yml: -------------------------------------------------------------------------------- 1 | name: Release Piranha Playground 2 | 3 | on: 4 | workflow_dispatch: 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | defaults: 9 | run: 10 | working-directory: ./experimental 11 | steps: 12 | - name: Checkout code 13 | uses: actions/checkout@v3 14 | 15 | - name: Set up Python 3.9 16 | uses: actions/setup-python@v4 17 | with: 18 | python-version: 3.9 19 | 20 | - name: Create virtualenv and install dependencies 21 | run: | 22 | python -m venv .env 23 | source .env/bin/activate 24 | pip install -r requirements.txt 25 | 26 | - name: Build and check package 27 | run: | 28 | source .env/bin/activate 29 | pip install wheel 30 | pip install twine 31 | python setup.py sdist bdist_wheel 32 | twine check dist/* 33 | twine upload --skip-existing -u __token__ -p ${{ secrets.PYPI_TOKEN_PLAYGROUND }} dist/* 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | java/.gradle 2 | java/build/ 3 | java/*/build/ 4 | .idea 5 | .DS_STORE 6 | piranha.iml 7 | objc/process 8 | objc/piranha-objc 9 | swift/artifact 10 | swift/Piranha.xcodeproj 11 | swift/Package.resolved 12 | **/*.iml 13 | polyglot/piranha/target 14 | polyglot/piranha/Cargo.lock 15 | polyglot/piranha/.idea 16 | .history 17 | .vscode 18 | **/*.log 19 | polyglot/piranha/demo/piranha 20 | **/.env/** 21 | **.pyc 22 | target 23 | Cargo.lock 24 | tmp_test* 25 | env/ 26 | 27 | 28 | # Dependencies 29 | **/node_modules 30 | 31 | # Production 32 | **/build 33 | 34 | # Generated files 35 | .docusaurus 36 | .cache-loader 37 | 38 | # Misc 39 | .DS_Store 40 | .env.local 41 | .env.development.local 42 | .env.test.local 43 | .env.production.local 44 | 45 | npm-debug.log* 46 | yarn-debug.log* 47 | yarn-error.log* 48 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | [Piranha] 2 | Copyright (c) 2018 Uber Technologies, Inc. 3 | 4 | This product includes software developed at 5 | Uber Technologies, Inc. (http://www.uber.com/). 6 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | Releasing 2 | ========= 3 | 4 | 1. `git checkout master && git pull` to get latest master. 5 | 2. Change the version in `Cargo.toml` to the next version. 6 | 3. `git commit -am "Release X.Y.Z."` (where X.Y.Z is the new version) 7 | 4. `git tag -a vX.Y.Z -m "Piranha X.Y.Z"` (where X.Y.Z is the new version) 8 | 5. `git push && git push --tags` 9 | 6. The release workflow will automatically be triggered to build wheels and source distributions, and automatically upload to PyPI. 10 | 7. Visit [polyglot-piranha](https://pypi.org/project/polyglot-piranha/) to see if new release is there. 11 | 8. Create a [GitHub Release](https://github.com/uber/piranha/releases). 12 | -------------------------------------------------------------------------------- /demo/feature_flag_cleanup/java/SampleClass.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Uber Technologies, Inc. 2 | // 3 | //
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | //
http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | //
Unless required by applicable law or agreed to in writing, software distributed under the 8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | // express or implied. See the License for the specific language governing permissions and 10 | // limitations under the License. 11 | 12 | class SampleJava { 13 | 14 | public void sampleMethod(ExperimentInterface exp) { 15 | if (exp.isToggleEnabled(SAMPLE_STALE_FLAG)) { 16 | System.out.println("SAMPLE_STALE_FLAG is enabled"); 17 | } else { 18 | System.out.println("SAMPLE_STALE_FLAG is disabled"); 19 | } 20 | } 21 | 22 | public void sampleMethod1(ExperimentInterface exp) { 23 | if (exp.isToggleDisabled(ExpEnum.SAMPLE_STALE_FLAG)) { 24 | System.out.println("SAMPLE_STALE_FLAG is disabled"); 25 | } else { 26 | System.out.println("SAMPLE_STALE_FLAG is enabled"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /demo/feature_flag_cleanup/java/TestEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2023 Uber Technologies, Inc. 3 | * 4 | *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *
http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *
Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.uber.piranha; 15 | 16 | enum TestEnum { 17 | SAMPLE_STALE_FLAG 18 | } 19 | -------------------------------------------------------------------------------- /demo/feature_flag_cleanup/kt/SampleClass.kt: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Uber Technologies, Inc. 2 | // 3 | //
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | //
http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | //
Unless required by applicable law or agreed to in writing, software distributed under the 8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | // express or implied. See the License for the specific language governing permissions and 10 | // limitations under the License. 11 | 12 | class SampleKotlin { 13 | 14 | fun print_status_enabled() { 15 | if (experimentation.isToggleEnabled(SAMPLE_STALE_FLAG)) { 16 | println("SAMPLE_STALE_FLAG is enabled") 17 | } else { 18 | println("SAMPLE_STALE_FLAG is disabled") 19 | } 20 | } 21 | 22 | fun print_status_disabled() { 23 | if (experimentation.isToggleDisabled(SAMPLE_STALE_FLAG)) { 24 | println("SAMPLE_STALE_FLAG is disabled") 25 | } else { 26 | println("SAMPLE_STALE_FLAG is enabled") 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /demo/feature_flag_cleanup/kt/TestEnum.kt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 Uber Technologies, Inc. 3 | 4 |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | except in compliance with the License. You may obtain a copy of the License at 6 |
http://www.apache.org/licenses/LICENSE-2.0 7 | 8 |
Unless required by applicable law or agreed to in writing, software distributed under the 9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 10 | express or implied. See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | package com.uber.input 15 | 16 | enum class TestEnum { 17 | @Autorollout 18 | SAMPLE_STALE_FLAG, 19 | } 20 | -------------------------------------------------------------------------------- /demo/feature_flag_cleanup_using_py_api/java/SampleClass.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Uber Technologies, Inc. 2 | // 3 | //
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | //
http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | //
Unless required by applicable law or agreed to in writing, software distributed under the 8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | // express or implied. See the License for the specific language governing permissions and 10 | // limitations under the License. 11 | 12 | class SampleJava { 13 | 14 | public void sampleMethod(ExperimentInterface exp) { 15 | if (exp.isTreated("SAMPLE_STALE_FLAG")) { 16 | System.out.println("SAMPLE_STALE_FLAG is enabled"); 17 | } else { 18 | System.out.println("SAMPLE_STALE_FLAG is disabled"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo/find_replace/java/TestEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2023 Uber Technologies, Inc. 3 | * 4 | *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *
http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *
Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.uber.piranha; 15 | 16 | public enum Something implements ExperimentName { 17 | 18 | /** Show menu */ 19 | SHOW_MENU, 20 | 21 | /** Foobar */ 22 | STALE_FLAG, 23 | 24 | /** barfoo. */ 25 | BAR_FOO, 26 | } 27 | -------------------------------------------------------------------------------- /demo/find_replace/java/configurations/rules.toml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Uber Technologies, Inc. 2 | # 3 | #
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | # except in compliance with the License. You may obtain a copy of the License at 5 | #
http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | #
Unless required by applicable law or agreed to in writing, software distributed under the 8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | # express or implied. See the License for the specific language governing permissions and 10 | # limitations under the License. 11 | 12 | # 13 | # For @stale_flag_name = STALE_FLAG 14 | # Before : 15 | # enum Flags { 16 | # ABC, STALE_FLAG, OTHER_FLAG 17 | # } 18 | # After : 19 | # enum Flags { 20 | # ABC, OTHER_FLAG 21 | # } 22 | # 23 | [[rules]] 24 | name = "delete_enum_constant" 25 | query = """ 26 | ( 27 | ((enum_constant name : (_) @n) @ec) 28 | (#eq? @n "@stale_flag_name") 29 | ) 30 | """ 31 | replace_node = "ec" 32 | replace = "" 33 | holes = ["stale_flag_name"] 34 | groups = ["delete_enum_entry"] 35 | -------------------------------------------------------------------------------- /demo/find_replace/swift/configurations/rules.toml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Uber Technologies, Inc. 2 | # 3 | #
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | # except in compliance with the License. You may obtain a copy of the License at 5 | #
http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | #
Unless required by applicable law or agreed to in writing, software distributed under the 8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 9 | # express or implied. See the License for the specific language governing permissions and 10 | # limitations under the License. 11 | 12 | # This file contains rules to the specific feature flag API. 13 | 14 | # 15 | # For @stale_flag_name = test_second_experiment and @treated = true 16 | # Before 17 | # case test_second_experiment 18 | # After 19 | # 20 | # 21 | [[rules]] 22 | name = "delete_case_enum_entry" 23 | query = """ 24 | ( 25 | (enum_entry name: (_) @flag_name) @ee 26 | (#eq? @flag_name "@stale_flag_name") 27 | )""" 28 | replace_node = "ee" 29 | replace = "" 30 | holes = ["stale_flag_name"] 31 | -------------------------------------------------------------------------------- /demo/find_replace_custom_cleanup/java/AnotherClass.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2023 Uber Technologies, Inc. 3 | * 4 | *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *
http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *
Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.uber.piranha; 15 | 16 | class TestSubClass extends TestClass { 17 | 18 | @Override 19 | void testMethod() { 20 | System.out.println("Hi World!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demo/find_replace_custom_cleanup/java/SomeClass.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2023 Uber Technologies, Inc. 3 | * 4 | *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *
http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *
Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | import java.util.ArrayList;
17 |
18 | class SomeClass {
19 | ArrayList Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "File"
15 | from = "replace_arrays_as_list_with_collection_singleton"
16 | to = ["add_import_statement"]
17 |
--------------------------------------------------------------------------------
/demo/find_replace_custom_cleanup/python/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "delete_str_literal_in_list"
15 | to = ["delete_empty_list_assignment"]
16 |
--------------------------------------------------------------------------------
/demo/find_replace_custom_cleanup/python/only_lists.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | deps = ['dependency1', 'dependency2', 'dependency3']
13 | nums = [1, 2, 3]
14 | deps2 = ["dependency2", "dependency1"]
15 | deps3 = ['dependency2']
16 | empty_list = []
17 |
--------------------------------------------------------------------------------
/demo/match_only/go/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_go_stmt_for_loop"
14 | query = """
15 | (
16 | (go_statement) @go_stmt
17 | )
18 | """
19 | [[rules.filters]]
20 | enclosing_node = "(for_statement) @fs"
21 |
22 |
23 | [[rules]]
24 | name = "find_for"
25 | query = """
26 | (
27 | (for_statement) @for_stmt
28 | )
29 | """
30 |
--------------------------------------------------------------------------------
/demo/match_only/java/Sample.java:
--------------------------------------------------------------------------------
1 | public class Sample {
2 |
3 | public static void someMethodStatic(Foo foo) {
4 | System.out.println("This is a static method!");
5 | foo.fooBar("baz");
6 | }
7 |
8 | public void someMethodInstance(Foo foo) {
9 | System.out.println("This is a instance method!");
10 | foo.fooBar("baz");
11 | }
12 |
13 | public static void someOtherMethodStatic(Foo foo) {
14 | System.out.println("This is a static method!");
15 | foo.barFoo("baz");
16 | }
17 |
18 | public void someOtherMethodInstance(Foo foo) {
19 | System.out.println("This is a instance method!");
20 | foo.barFoo("baz");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/demo/match_only/ts/sample.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | for (let i = 0; i < 10; ++i) {
13 | console.log(i);
14 | }
15 |
16 | function f1() {
17 | for (let i = 0; i < 10; ++i) {
18 | console.log(i);
19 | }
20 | }
21 |
22 | function f2() {
23 | let i = 0;
24 |
25 | while(i < 10) {
26 | for (let j = 0; j < 10; ++j) {
27 | console.log(10*i + j);
28 | }
29 |
30 | ++i;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/demo/match_only/tsx/sample.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | import React from 'react';
13 |
14 | type Props = {
15 | label: string;
16 | }
17 |
18 | const Component1 = (props: Props) => {
19 | return
26 | {props.label}
27 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
--------------------------------------------------------------------------------
/experimental/piranha_playground/demo/after.java:
--------------------------------------------------------------------------------
1 | class Test {
2 | public static void main(String[] args) {
3 | data = ContextWrappers.wrap(Executors.newFixedThreadPool(1));
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/experimental/piranha_playground/demo/before.java:
--------------------------------------------------------------------------------
1 | class Test {
2 | public static void main(String[] args) {
3 | data = ContextExecutors.newFixedThreadPool(1);
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/experimental/piranha_playground/rule_inference/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
--------------------------------------------------------------------------------
/experimental/piranha_playground/rule_inference/tests/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
--------------------------------------------------------------------------------
/experimental/piranha_playground/rule_inference/utils/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
--------------------------------------------------------------------------------
/experimental/piranha_playground/rule_inference/utils/pretty_toml.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | from toml.encoder import TomlEncoder, _dump_str, unicode
13 |
14 |
15 | def _dump_str_prefer_multiline(v):
16 | multilines = v.split("\n")
17 | if len(multilines) > 1:
18 | return unicode('"""\n' + v.replace('"""', '\\"""').strip() + '\n"""')
19 | else:
20 | return _dump_str(v)
21 |
22 |
23 | class PrettyTOML(TomlEncoder):
24 | def __init__(self, _dict=dict, preserve=False):
25 | super(PrettyTOML, self).__init__(_dict=dict, preserve=preserve)
26 | self.dump_funcs[str] = _dump_str_prefer_multiline
27 |
--------------------------------------------------------------------------------
/experimental/requirements.txt:
--------------------------------------------------------------------------------
1 | tree-sitter==0.20.1
2 | tree-sitter-languages
3 | attrs
4 | openai
5 | polyglot-piranha
6 | toml
7 | pytest
8 | flask
9 | flask-socketio
10 | comby
11 | eventlet
12 |
--------------------------------------------------------------------------------
/license_header.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | Unless required by applicable law or agreed to in writing, software distributed under the
8 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | express or implied. See the License for the specific language governing permissions and
10 | limitations under the License.
11 |
--------------------------------------------------------------------------------
/plugins/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools>=42", "wheel"]
3 | build-backend = "setuptools.build_meta"
4 |
5 | [tool.poetry]
6 | name = "spark_upgrade"
7 | version = "0.0.1"
8 | description = "Rules to migrate 'scaletest'"
9 | # Add any other metadata you need
10 |
11 | [tool.poetry.dependencies]
12 | python = "^3.9"
13 | polyglot_piranha = "*"
14 |
15 | [tool.poetry.dev-dependencies]
16 | pytest = "7.4.x"
17 |
18 | [tool.poetry.scripts."scala_test"]
19 | main = "spark_upgrade.main:main"
20 |
21 | [tool.poetry.scripts."pytest"]
22 | main = "pytest"
23 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/README.md:
--------------------------------------------------------------------------------
1 | # `Spark Upgrade` Plugin (WIP)
2 |
3 | Upgrades your codebase to Spark 3.3
4 |
5 |
6 | Currently, it updates to [v.3.3](https://spark.apache.org/releases/spark-release-3-3-0.html) only.
7 | Supported rewrites:
8 | * `CalendarInterval` -> `DateTimeConstants`
9 | * Updates execution plan access
10 | * `Calculator` signature change
11 | * `GradientBoostTrees` api change
12 | * Update `SQLExecution.withNewExecutionId`
13 | * Update `QueryTest.CheckAnswer`
14 | * Update `SparkConf` (Builder pattern style)
15 |
16 |
17 |
18 | ## Usage:
19 |
20 | Clone the repository - `git clone https://github.com/uber/piranha.git`
21 |
22 | Install the dependencies - `pip3 install -r plugins/spark_upgrade/requirements.txt`
23 |
24 | Run the tool - `python3 plugins/spark_upgrade/main.py -h`
25 |
26 | CLI:
27 | ```
28 | usage: main.py [-h] --path_to_codebase PATH_TO_CODEBASE
29 |
30 | Updates the codebase to use a new version of `Spark 3.3`.
31 |
32 | options:
33 | -h, --help show this help message and exit
34 | --path_to_codebase PATH_TO_CODEBASE
35 | Path to the codebase directory.
36 | ```
37 |
38 | ## Test
39 | ```
40 | pytest plugins/
41 | ```
42 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/requirements.txt:
--------------------------------------------------------------------------------
1 | polyglot-piranha
2 | pytest
3 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/plugins/spark_upgrade/tests/__init__.py
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/accessing_execution_plan/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object AccessingExecutionPlan {
4 | def main(args: Array[String]): Unit = {
5 | var r0 = df.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].initialPlan
6 | var r1 = df.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec].initialPlan.collect
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/accessing_execution_plan/input/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object AccessingExecutionPlan {
4 | def main(args: Array[String]): Unit = {
5 | var r0 = df.queryExecution.executedPlan
6 | var r1 = df.queryExecution.executedPlan.collect
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/calculator_signature_change/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object AccessingExecutionPlan {
4 | def main(args: Array[String]): Unit = {
5 | var e1 = EntropyCalculator(s, s.sum.toLong)
6 | var e2 = GiniCalculator(s, s.sum.toLong)
7 | var e3 = VarianceCalculator(s, s.sum.toLong)
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/calculator_signature_change/input/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object AccessingExecutionPlan {
4 | def main(args: Array[String]): Unit = {
5 | var e1 = EntropyCalculator(s)
6 | var e2 = GiniCalculator(s)
7 | var e3 = VarianceCalculator(s)
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/gradient_boost_trees/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | // this rules removes the comment on line 11
4 | object GradientBoostTressExample {
5 | def main(args: Array[String]): Unit = {
6 | val (a, b) =
7 | GradientBoostedTrees.run(
8 | oldDataset.map(data => new Instance(data.label, 1.0, data.features)),
9 | boostingStrategy,
10 | seed,
11 | "auto")
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/gradient_boost_trees/expected/sample2.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object GradientBoostTressExample {
4 | def main(args: Array[String]): Unit = {
5 | val (c, d) =
6 | GradientBoostedTrees.run(
7 | oldDataset.map(data => new Instance(data.label, 1.0, data.features)),
8 | boostingStrategy,
9 | seed,
10 | "auto"
11 | )
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/gradient_boost_trees/input/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | // this rules removes the comment on line 11
4 | object GradientBoostTressExample {
5 | def main(args: Array[String]): Unit = {
6 | val (a, b) =
7 | GradientBoostedTrees.run(
8 | oldDataset,
9 | boostingStrategy,
10 | seed,
11 | "auto" /* featureSubsetStrategy */)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/gradient_boost_trees/input/sample2.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object GradientBoostTressExample {
4 | def main(args: Array[String]): Unit = {
5 | val (c, d) =
6 | GradientBoostedTrees.run(
7 | oldDataset,
8 | boostingStrategy,
9 | seed,
10 | "auto")
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/idf_model_signature_change/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object IDFModelExample {
4 | def main(args: Array[String]): Unit = {
5 | var r = new feature.IDFModel(
6 | MichelangeloIDFModel.getVectorFromProto(protoTransformer.getIDF.getIdfModel),
7 | new Array[Long](protoTransformer.getTopicSimilarity.getIdfModel.getIdfModel.getSize),
8 | 0L)
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/idf_model_signature_change/input/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | object IDFModelExample {
4 | def main(args: Array[String]): Unit = {
5 | var r = feature.IDFModel(
6 | MichelangeloIDFModel.getVectorFromProto(protoTransformer.getIDF.getIdfModel)
7 | )
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf
4 | import org.apache.spark.sql.SparkSession
5 |
6 | class Sample {
7 | def main(args: Array[String]): Unit = {
8 |
9 | val conf = new SparkConf()
10 | .set("spark.sql.legacy.timeParserPolicy","LEGACY")
11 | .set("spark.sql.legacy.allowUntypedScalaUDF", "true")
12 | .setMaster(master)
13 | .setAppName(appName)
14 | .set("spark.driver.allowMultipleContexts", "true")
15 | val sc = new SparkContext(conf)
16 | val sqlContext = new TestHiveContext(sc).sparkSession
17 |
18 | val conf2 = new SparkConf()
19 | .set("spark.sql.legacy.timeParserPolicy","LEGACY")
20 | .set("spark.sql.legacy.allowUntypedScalaUDF", "true")
21 |
22 | conf2.setSparkHome(sparkHome)
23 |
24 | conf2.setExecutorEnv("spark.executor.extraClassPath", "test")
25 |
26 | val sparkSession = SparkSession.builder()
27 | .master(master)
28 | .appName(appName)
29 | .getOrCreate
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/expected/sample2.java:
--------------------------------------------------------------------------------
1 | import org.apache.spark.SparkConf;
2 | import org.apache.spark.sql.SparkSession;
3 |
4 | public class Sample2 {
5 |
6 | private static JavaSparkContext jsc;
7 |
8 | @BeforeClass
9 | public static void startSpark() {
10 | jsc =
11 | new JavaSparkContext(
12 | SparkSession.builder()
13 | .config("spark.sql.legacy.allowUntypedScalaUDF", "true")
14 | .appName(Sample2.class.getName())
15 | .master("master")
16 | .config("spark.driver.allowMultipleContexts", "true")
17 | .getOrCreate()
18 | .sparkContext());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/expected/sample2.scala:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf
4 | import org.apache.spark.sql.SparkSession
5 |
6 | class Sample {
7 |
8 | def main(argv: Array[String]): Unit = {
9 | val spark = SparkSession.builder
10 | .appName("appName")
11 | .config("conf", "package.conf")
12 | .enableHiveSupport
13 | .getOrCreate
14 |
15 | run(spark, config)
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/expected/sample3.java:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf;
4 | import org.apache.spark.SparkContext;
5 | import org.apache.spark.sql.SparkSession;
6 |
7 | public class Sample {
8 | public static void main(String[] args) {
9 | // Should not touch existent SparkSession.builder()
10 | SparkSession session = SparkSession.builder().config(sc.getConf()).getOrCreate();
11 |
12 | SparkSession session2 =
13 | SparkSession.builder().appName("appName").config("config", "local").getOrCreate();
14 |
15 | SparkSession.builder().appName("appName").config("config", "local").getOrCreate();
16 | }
17 |
18 | @Test
19 | public void test() {
20 | SparkSession session =
21 | SparkSession.builder().appName("appName").config("config", "local").getOrCreate();
22 | SparkContext sc = session.sparkContext();
23 | JavaSparkContext jsc = JavaSparkContext.fromSparkContext(sc());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/expected/sample3.scala:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.sql.SparkSession
4 |
5 | import org.mockito.Mockito.spy
6 |
7 | class Sample {
8 |
9 | @Test
10 | def testMain(): Unit = {
11 | lazy val spark: SparkSession = spy(
12 | SparkSession
13 | .builder()
14 | .master("master")
15 | .appName("AppName")
16 | .config("spark.ui.enabled", "false")
17 | .config("spark.driver.host", "localhost")
18 | .getOrCreate())
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/input/sample.scala:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf
4 | import org.apache.spark.sql.SparkSession
5 |
6 | class Sample {
7 | def main(args: Array[String]): Unit = {
8 |
9 | val conf = new SparkConf()
10 | .setMaster(master)
11 | .setAppName(appName)
12 | .set("spark.driver.allowMultipleContexts", "true")
13 | val sc = new SparkContext(conf)
14 | val sqlContext = new TestHiveContext(sc).sparkSession
15 |
16 | val conf2 = new SparkConf()
17 |
18 | conf2.setSparkHome(sparkHome)
19 |
20 | conf2.setExecutorEnv("spark.executor.extraClassPath", "test")
21 |
22 | val sparkSession = SparkSession.builder()
23 | .master(master)
24 | .appName(appName)
25 | .getOrCreate
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/input/sample2.java:
--------------------------------------------------------------------------------
1 | import org.apache.spark.SparkConf;
2 |
3 | public class Sample2 {
4 |
5 | private static JavaSparkContext jsc;
6 |
7 | @BeforeClass
8 | public static void startSpark() {
9 | jsc =
10 | new JavaSparkContext(
11 | new SparkConf()
12 | .setAppName(Sample2.class.getName())
13 | .setMaster("master")
14 | .set("spark.driver.allowMultipleContexts", "true"));
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/input/sample2.scala:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf
4 | import org.apache.spark.sql.SparkSession
5 |
6 | class Sample {
7 |
8 | def main(argv: Array[String]): Unit = {
9 | val spark = SparkSession.builder
10 | .appName("appName")
11 | .config("conf", "package.conf")
12 | .enableHiveSupport
13 | .getOrCreate
14 |
15 | run(spark, config)
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/input/sample3.java:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf;
4 | import org.apache.spark.SparkContext;
5 | import org.apache.spark.sql.SparkSession;
6 |
7 | public class Sample {
8 | public static void main(String[] args) {
9 | // Should not touch existent SparkSession.builder()
10 | SparkSession session = SparkSession.builder().config(sc.getConf()).getOrCreate();
11 |
12 | SparkSession session2 =
13 | SparkSession.builder().appName("appName").config("config", "local").getOrCreate();
14 |
15 | SparkSession.builder().appName("appName").config("config", "local").getOrCreate();
16 | }
17 |
18 | @Test
19 | public void test() {
20 | SparkSession session =
21 | SparkSession.builder().appName("appName").config("config", "local").getOrCreate();
22 | SparkContext sc = session.sparkContext();
23 | JavaSparkContext jsc = JavaSparkContext.fromSparkContext(sc());
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/spark_conf/input/sample3.scala:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.sql.SparkSession
4 |
5 | import org.mockito.Mockito.spy
6 |
7 | class Sample {
8 |
9 | @Test
10 | def testMain(): Unit = {
11 | lazy val spark: SparkSession = spy(
12 | SparkSession
13 | .builder()
14 | .master("master")
15 | .appName("AppName")
16 | .getOrCreate())
17 | spark.sqlContext.setConf("spark.ui.enabled", "false")
18 | spark.sqlContext.setConf("spark.driver.host", "localhost")
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/sql_new_execution/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | import org.apache.spark.unsafe.types.CalendarInterval
4 |
5 | object SqlNewExecutionExample {
6 | def main(args: Array[String]): Unit = {
7 | val x = SQLExecution.withNewExecutionId(qe)
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/sql_new_execution/input/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | import org.apache.spark.unsafe.types.CalendarInterval
4 |
5 | object SqlNewExecutionExample {
6 | def main(args: Array[String]): Unit = {
7 | val x = SQLExecution.withNewExecutionId(sparkSession, qe)
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/update_calendar_interval/expected/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | import org.apache.spark.sql.catalyst.util.DateTimeConstants
4 | import org.apache.spark.unsafe.types.CalendarInterval
5 |
6 | object CalendarIntervalExample {
7 | def main(args: Array[String]): Unit = {
8 | // Accessing MICROS_PER_SECOND constant
9 | val microsPerSecond = DateTimeConstants.MICROS_PER_SECOND
10 | val microsPerHour = DateTimeConstants.MICROS_PER_HOUR
11 | val fromYearMonthString = DateTimeConstants.fromYearMonthString("1-2")
12 | val fromDayTimeString = DateTimeConstants.fromDayTimeString("1-2")
13 | println(s"Microseconds per Second: $microsPerSecond")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/plugins/spark_upgrade/tests/resources/update_calendar_interval/input/sample.scala:
--------------------------------------------------------------------------------
1 | package org.piranha
2 |
3 | import org.apache.spark.unsafe.types.CalendarInterval
4 |
5 | object CalendarIntervalExample {
6 | def main(args: Array[String]): Unit = {
7 | // Accessing MICROS_PER_SECOND constant
8 | val microsPerSecond = CalendarInterval.MICROS_PER_SECOND
9 | val microsPerHour = CalendarInterval.MICROS_PER_HOUR
10 | val fromYearMonthString = CalendarInterval.fromYearMonthString("1-2")
11 | val fromDayTimeString = CalendarInterval.fromDayTimeString("1-2")
12 | println(s"Microseconds per Second: $microsPerSecond")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/plugins/zap-transformation/resource/sample.go:
--------------------------------------------------------------------------------
1 | func logTestMessage() {
2 |
3 | logger.With(zap.Any("field", complex128(0))).Info("test")
4 | c1 = float64(0)
5 | c = complex128(0)
6 | logger.With(zap.Any("field", &c1)).Info("test")
7 | }
8 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [project]
2 | name = "polyglot_piranha"
3 | requires-python = ">=3.8"
4 | dynamic = ["version"]
5 | description = "Polyglot Piranha is a library for performing structural find and replace with deep cleanup."
6 | authors = [{ name = "Uber Technologies Inc." }]
7 | license = "Apache-2.0"
8 | readme = "README.md"
9 | keywords = [
10 | "refactoring",
11 | "code update",
12 | "structural find-replace",
13 | "structural search and replace",
14 | "structural search",
15 | ]
16 |
17 | [project.urls]
18 | homepage = "https://github.com/uber/piranha"
19 | documentation = "https://github.com/uber/piranha"
20 | repository = "https://github.com/uber/piranha"
21 |
22 | [build-system]
23 | requires = ["maturin>=1.4.0,<2.0"]
24 | build-backend = "maturin"
25 |
26 | [tool.maturin]
27 | bindings = "pyo3"
28 | include = ["LICENSE", "NOTICE", "polyglot_piranha.pyi"]
29 |
--------------------------------------------------------------------------------
/report.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/report.pdf
--------------------------------------------------------------------------------
/rustfmt.toml:
--------------------------------------------------------------------------------
1 | # /*
2 | # Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | # except in compliance with the License. You may obtain a copy of the License at
6 | # http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | # Unless required by applicable law or agreed to in writing, software distributed under the
9 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | # express or implied. See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | # */
13 | max_width = 100
14 | tab_spaces = 2
15 | edition = "2021"
16 | fn_args_layout = "Compressed"
17 | use_field_init_shorthand = true
18 |
--------------------------------------------------------------------------------
/src/cleanup_rules/ruby/edges.toml:
--------------------------------------------------------------------------------
1 | [[edges]]
2 | scope = "Parent"
3 | from = "replace_expression_with_boolean_literal"
4 | to = ["boolean_literal_cleanup"]
5 |
6 |
7 | [[edges]]
8 | scope = "Parent"
9 | from = "boolean_literal_cleanup"
10 | to = ["boolean_expression_simplify", "statement_cleanup", "block_removal"]
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "boolean_expression_simplify"
15 | to = ["boolean_literal_cleanup"]
16 |
17 | [[edges]]
18 | scope = "Parent"
19 | from = "statement_cleanup"
20 | to = ["if_cleanup"]
21 |
22 | [[edges]]
23 | scope = "Parent"
24 | from = "if_cleanup"
25 | to = ["delete_all_statements_after_return"]
26 |
27 | [[edges]]
28 | scope = "Parent"
29 | from = "delete_all_statements_after_return"
30 | to = ["delete_all_statements_after_return"]
31 |
32 | [[edges]]
33 | scope = "Parent"
34 | from = "statement_cleanup"
35 | to = ["delete_variable_declaration"]
36 |
37 | [[edges]]
38 | scope = "Method"
39 | from = "delete_variable_declaration"
40 | to = ["replace_identifier_with_value"]
41 |
42 | [[edges]]
43 | scope = "Parent"
44 | from = "replace_identifier_with_value"
45 | to = ["boolean_literal_cleanup"]
46 |
47 | [[edges]]
48 | scope = "Parent"
49 | from = "delete_variable_declaration"
50 | to = ["identify_empty_methods"]
51 |
--------------------------------------------------------------------------------
/src/cleanup_rules/ruby/scope_config.toml:
--------------------------------------------------------------------------------
1 | [[scopes]]
2 | name = "Method"
3 | [[scopes.rules]]
4 | enclosing_node = """
5 | (
6 | [
7 | (method
8 | name: (identifier) @n
9 | )
10 | (method
11 | name: (identifier) @n
12 | parameters: (method_parameters) @fp
13 | )
14 | ]
15 | @xdn)
16 | """
17 | scope = """
18 | (
19 | [
20 | (
21 | (method
22 | name: (identifier) @z
23 | )
24 | (#eq? @z "@n")
25 | )
26 | (
27 | (method
28 | name: (identifier) @z
29 | parameters: (method_parameters) @tp
30 | )
31 | (#eq? @z "@n")
32 | (#eq? @tp "@fp")
33 | )
34 | ]
35 | )@qdn
36 | """
37 |
--------------------------------------------------------------------------------
/src/cleanup_rules/scala/scope_config.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
13 | [[scopes]]
14 | name = "File"
15 | [[scopes.rules]]
16 | enclosing_node = """
17 | (compilation_unit) @cu
18 | """
19 | scope = "(compilation_unit) @compilation_unit"
20 |
--------------------------------------------------------------------------------
/src/df/README.md:
--------------------------------------------------------------------------------
1 | # Dataflow analysis for Piranha
2 |
3 | This folder implements a small data flow analysis framework `df.rs`.
4 |
5 | There's an implementation to a "Definite Assignment Analysis" under `tag_analysis.rs`.
6 | The idea is to track all the variables defined through the rule graph,
7 | and make sure that all the variables are defined before they are used.
8 | Unlike "Definite Assignment Analysis", it tracks "tags" as they propagate
9 | through rules in the `RuleGraph`.
10 | The goal of the analysis is to find, for each point in the graph,
11 | the set of tags that will always reach that point.
12 | The result can then be used to check if the query contains any variable tag that was not defined.
13 |
--------------------------------------------------------------------------------
/src/df/mod.rs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | pub mod analysis;
15 | pub mod tag_analysis;
16 | pub mod utils;
17 |
--------------------------------------------------------------------------------
/src/models/mod.rs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | pub(crate) mod capture_group_patterns;
15 | pub(crate) mod concrete_syntax;
16 | pub(crate) mod default_configs;
17 | pub mod edit;
18 | pub mod filter;
19 | pub mod language;
20 | pub(crate) mod matches;
21 | pub(crate) mod outgoing_edges;
22 | pub mod piranha_arguments;
23 | pub mod piranha_output;
24 | pub(crate) mod rule;
25 | pub(crate) mod rule_graph;
26 | pub(crate) mod rule_store;
27 | pub(crate) mod scopes;
28 | pub(crate) mod source_code_unit;
29 |
30 | pub(crate) trait Validator {
31 | fn validate(&self) -> Result<(), String>;
32 | }
33 |
--------------------------------------------------------------------------------
/src/models/unit_tests/testdata/custom_builtin/edges.toml:
--------------------------------------------------------------------------------
1 | [[edges]]
2 | scope = "Class"
3 | from = "rule_1"
4 | to = ["rule_2"]
5 |
6 | [[edges]]
7 | scope = "Parent"
8 | from = "rule_2"
9 | to = ["rule_1"]
10 |
--------------------------------------------------------------------------------
/src/models/unit_tests/testdata/custom_builtin/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "rule_1"
3 | query = """
4 | (
5 | (expression_statement (method_invocation
6 | !object
7 | name: (_) @name
8 | arguments: (_) @args)) @call_expr
9 | )"""
10 | replace_node = "call_expr"
11 | replace = ""
12 | is_seed_rule = false
13 | [[rules.filters]]
14 | enclosing_node = "(program) @prgrm"
15 | not_contains = ["""
16 | (method_declaration
17 | name: (_) @ExistingName) @method_decl
18 | (#eq? @ExistingName "@name")
19 | """]
20 |
21 | [[rules]]
22 | name = "rule_2"
23 | query = """
24 | (
25 | (method_declaration
26 | (modifiers) @modifier
27 | name: (_) @name
28 | body: (block) @body
29 | ) @method
30 | (#match? @body "^\\\\{\\\\s*(//.*?\\\\s*)*\\\\}$")
31 | (#match? @modifier "private|protected")
32 | )"""
33 | replace_node = "method"
34 | replace = ""
35 | is_seed_rule = false
36 |
--------------------------------------------------------------------------------
/src/tests/test_piranha_scala.rs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | use super::create_rewrite_tests;
15 | use crate::models::default_configs::SCALA;
16 |
17 | create_rewrite_tests! {
18 | SCALA,
19 | test_simple_match_replace: "simple_match_replace", 1;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/tests/test_piranha_thrift.rs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | use crate::models::default_configs::THRIFT;
15 |
16 | use super::create_rewrite_tests;
17 |
18 | create_rewrite_tests! {
19 | THRIFT,
20 | test_feature_flag_system_1_treated: "match_exception_type", 1;
21 | }
22 |
--------------------------------------------------------------------------------
/src/tests/test_piranha_ts.rs:
--------------------------------------------------------------------------------
1 | use std::collections::HashMap;
2 |
3 | /*
4 | Copyright (c) 2023 Uber Technologies, Inc.
5 |
6 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
7 | except in compliance with the License. You may obtain a copy of the License at
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software distributed under the
11 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | express or implied. See the License for the specific language governing permissions and
13 | limitations under the License.
14 | */
15 | use super::create_match_tests;
16 |
17 | use crate::models::default_configs::TYPESCRIPT;
18 |
19 | create_match_tests! {
20 | TYPESCRIPT,
21 | test_find_fors_within_functions_not_within_whiles: "structural_find/find_fors_within_functions_not_within_whiles", HashMap::from([("find_fors_within_functions_not_within_whiles", 1)]);
22 | test_find_fors_within_functions:"structural_find/find_fors_within_functions", HashMap::from([("find_fors_within_functions", 2)]);
23 | test_find_fors: "structural_find/find_fors", HashMap::from([("find_fors", 3)]);
24 | }
25 |
--------------------------------------------------------------------------------
/src/tests/test_piranha_yaml.rs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | use crate::models::default_configs::YAML;
15 |
16 | use super::{create_rewrite_tests, substitutions};
17 |
18 | create_rewrite_tests! {
19 | YAML,
20 | test_yaml_find_replace_with_holes: "find_replace/",1,
21 | substitutions= substitutions! {
22 | "value_to_replace" => "localhost"
23 | };
24 | }
25 |
--------------------------------------------------------------------------------
/test-resources/go/feature_flag/system_1/const_same_file/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "File"
14 | from = "find_const_str_literal"
15 | to = ["replace_expression_with_boolean_literal"]
16 |
--------------------------------------------------------------------------------
/test-resources/go/structural_find/expression_with_string_literal/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "match_bool_value"
3 | query = "cs :[x].BoolValue(\":[y]\")"
4 |
--------------------------------------------------------------------------------
/test-resources/go/structural_find/expression_with_string_literal/input/sample.go:
--------------------------------------------------------------------------------
1 | package flag
2 |
3 | import "fmt"
4 |
5 |
6 | func a() {
7 | if exp.BoolValue("staleFlagConst") {
8 | fmt.Println("true")
9 | } else {
10 | fmt.Println("false")
11 | }
12 | }
13 |
14 | func a1() {
15 | if exp.BoolValue(staleFlagConst) {
16 | fmt.Println("true")
17 | } else {
18 | fmt.Println("false")
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/go/structural_find/for_loop/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_for"
14 | query = """
15 | (
16 | (for_statement) @for_stmt
17 | )
18 | """
19 |
--------------------------------------------------------------------------------
/test-resources/go/structural_find/go_stmt_for_loop/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_go_stmt_for_loop"
14 | query = """
15 | (
16 | (go_statement) @go_stmt
17 | )
18 | """
19 | [[rules.filters]]
20 | enclosing_node = "(for_statement) @fs"
21 |
--------------------------------------------------------------------------------
/test-resources/go/structural_find/go_stmt_for_loop/input/sample.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | package main
15 |
16 | import "fmt"
17 |
18 | func f(n int) {
19 | for i := 0; i < 10; i++ {
20 | fmt.Println(n, ":", i)
21 | }
22 | }
23 |
24 | func main() {
25 | go f(0) // go_statement does not get matched
26 | go f(1) // go_statement does not get matched
27 | }
28 |
29 | func go_stmt() {
30 | for i := 0; i < 10; i++ {
31 | go f(i) // go_statement gets matched
32 | }
33 | var input string
34 | fmt.Scanln(&input)
35 | }
36 |
--------------------------------------------------------------------------------
/test-resources/java/consecutive_scope_level_rules/expected/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class FooBar {
17 |
18 | int Id;
19 |
20 | FooBar(int id) {
21 | this.Id = id;
22 | }
23 |
24 | public class InnerFooBar {
25 | private String address;
26 | private String name;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test-resources/java/consecutive_scope_level_rules/input/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class FooBar {
17 |
18 | int Id;
19 |
20 | FooBar(int id) {
21 | this.Id = id;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/test-resources/java/custom_rules/custom_rules/edges.toml:
--------------------------------------------------------------------------------
1 | [[edges]]
2 | scope = "Class"
3 | from = "delete_empty_private_method"
4 | to = ["delete_usages"]
5 |
6 | [[edges]]
7 | scope = "Parent"
8 | from = "delete_usages"
9 | to = ["delete_empty_private_method"]
10 |
--------------------------------------------------------------------------------
/test-resources/java/custom_rules/custom_rules/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "delete_usages"
3 | query = """
4 | (
5 | (expression_statement (method_invocation
6 | !object
7 | name: (_) @name
8 | arguments: (_) @args)) @call_expr
9 | )"""
10 | replace_node = "call_expr"
11 | replace = ""
12 | is_seed_rule = false
13 | [[rules.filters]]
14 | enclosing_node = "(program) @prgrm"
15 | not_contains = ["""
16 | (method_declaration
17 | name: (_) @ExistingName) @method_decl
18 | (#eq? @ExistingName "@name")
19 | """]
20 |
21 | [[rules]]
22 | name = "delete_empty_private_method"
23 | query = """
24 | (
25 | (method_declaration
26 | (modifiers) @modifier
27 | name: (_) @name
28 | body: (block) @body
29 | ) @method
30 | (#match? @body "^\\\\{\\\\s*(//.*?\\\\s*)*\\\\}$")
31 | (#match? @modifier "private")
32 | )"""
33 | replace_node = "method"
34 | replace = ""
35 | is_seed_rule = false
36 |
--------------------------------------------------------------------------------
/test-resources/java/custom_rules/expected/Sample.java:
--------------------------------------------------------------------------------
1 | public class PokemonCatcher {
2 | private void shouldNotBeDeleted_4() {
3 | if (sheeps) {
4 | }
5 | else if (check){
6 | blah = 0;
7 | }
8 | else {
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/test-resources/java/custom_rules/input/Sample.java:
--------------------------------------------------------------------------------
1 | public class PokemonCatcher {
2 | private void shouldNotBeDeleted_4() {
3 | if (sheeps) {
4 | shouldBeDeleted_2();
5 | }
6 | else if (check){
7 | blah = 0;
8 | }
9 | else {
10 | shouldBeDeleted_2();
11 | shouldBeDeleted_1();
12 | }
13 | }
14 | private void shouldBeDeleted_1() {
15 | shouldBeDeleted_2();
16 | }
17 | private void empty() {
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/test-resources/java/delete_comments/expected/Test.java:
--------------------------------------------------------------------------------
1 | class Test {
2 | public void foobar() {
3 | // Given;
4 | more_variables.set_value(false);
5 | // When
6 | var result = data.Something();
7 |
8 | // Then
9 | assertTrue("This is a test", result);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/test-resources/java/delete_comments/input/Test.java:
--------------------------------------------------------------------------------
1 | class Test {
2 | public void foobar() {
3 | // Given
4 | // This is an explanatory comment for variable
5 | variable.set_value(true);
6 | more_variables.set_value(false);
7 |
8 | // When
9 | var result = data.Something();
10 |
11 | // Then
12 | assertTrue("This is a test", result);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "delete 3rd argument"
3 | query = """(
4 | (method_invocation name: (_) @name (argument_list) @args) @method_invocation
5 | (#eq? @name "add")
6 | )"""
7 | replace_node = "args"
8 | replace_idx = 1
9 | replace = ""
10 | [[rules.filters]]
11 | sibling_count = 3
12 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument/expected/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | class A {
4 |
5 | void foobar() {
6 | int total = add(1, 3);
7 | System.out.println(total);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument/input/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | class A {
4 |
5 | void foobar() {
6 | int total = add(1,2,3);
7 | System.out.println(total);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument_invalid/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "delete 3rd argument"
3 | query = """(
4 | (method_invocation name: (_) @name (argument_list) @args) @method_invocation
5 | (#eq? @name "add")
6 | )"""
7 | replace_node = "rgs"
8 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument_invalid/expected/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | class A {
4 |
5 | void foobar() {
6 | int total = add(1, 2, 3);
7 | System.out.println(total);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument_invalid/input/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | class A {
4 |
5 | void foobar() {
6 | int total = add(1, 2, 3);
7 | System.out.println(total);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument_no_op/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "delete 3rd argument"
3 | query = """(
4 | (method_invocation name: (_) @name (argument_list) @args) @method_invocation
5 | (#eq? @name "add")
6 | )"""
7 | replace_node = "args"
8 | replace_idx = 4
9 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument_no_op/expected/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | class A {
4 |
5 | void foobar() {
6 | int total = add(1, 2, 3);
7 | System.out.println(total);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/test-resources/java/delete_method_invocation_argument_no_op/input/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | class A {
4 |
5 | void foobar() {
6 | int total = add(1, 2, 3);
7 | System.out.println(total);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/test-resources/java/delete_unused_field/expected/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class Test implements FooBar{
17 |
18 |
19 | private String anotherString;
20 |
21 | public String foo(){
22 | return anotherString;
23 | }
24 |
25 | public void bar() {
26 | // Do something else
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test-resources/java/delete_unused_field/input/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class Test implements FooBar{
17 |
18 | private String testString;
19 | private String anotherString;
20 |
21 | public String foo(){
22 | return anotherString;
23 | }
24 |
25 | public void bar() {
26 | // Do something else
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_1/control/expected/TestEnum.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/java/feature_flag_system_1/control/expected/TestEnum.java
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_1/control/input/TestEnum.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | enum TestEnum {
17 | STALE_FLAG
18 | }
19 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_1/treated/input/TestEnum.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | enum TestEnum {
17 | STALE_FLAG
18 | }
19 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/control/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Global"
15 | from = "delete_flag_method_declaration_fully_annotated"
16 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
17 |
18 | [[edges]]
19 | scope = "Global"
20 | from = "delete_flag_method_declaration_inside_annotated_interface"
21 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
22 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/control/expected/ExperimentInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | interface SomeParameter {
15 |
16 | @BoolParam(key = "other_flag", namespace = "some_long_name")
17 | BoolParameter isOtherFlag();
18 | }
19 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/control/expected/ExperimentInterfaceAnnotatedInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | @ParameterDefinition(namespace = "some_long_name")
15 | interface SomeParameter {
16 |
17 | @BoolParam(key = "other_flag", namespace = "some_long_name")
18 | BoolParameter isOtherFlag();
19 | }
20 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/control/input/ExperimentInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | interface SomeParameter {
15 |
16 | @BoolParam(key = "STALE_FLAG", namespace = "some_long_name")
17 | BoolParameter isStaleFeature();
18 |
19 | @BoolParam(key = "other_flag", namespace = "some_long_name")
20 | BoolParameter isOtherFlag();
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/control/input/ExperimentInterfaceAnnotatedInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | @ParameterDefinition(namespace = "some_long_name")
15 | interface SomeParameter {
16 |
17 | @BoolParam(key = "STALE_FLAG")
18 | BoolParameter isStaleFeature();
19 |
20 | @BoolParam(key = "other_flag", namespace = "some_long_name")
21 | BoolParameter isOtherFlag();
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/treated/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Global"
15 | from = "delete_flag_method_declaration_fully_annotated"
16 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
17 |
18 | [[edges]]
19 | scope = "Global"
20 | from = "delete_flag_method_declaration_inside_annotated_interface"
21 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
22 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/treated/expected/ExperimentInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | interface SomeParameter {
15 |
16 | @BoolParam(key = "other_flag", namespace = "some_long_name")
17 | BoolParameter isOtherFlag();
18 | }
19 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/treated/expected/ExperimentInterfaceAnnotatedInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | @ParameterDefinition(namespace = "some_long_name")
15 | interface SomeParameter {
16 |
17 | @BoolParam(key = "other_flag", namespace = "some_long_name")
18 | BoolParameter isOtherFlag();
19 | }
20 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/treated/input/ExperimentInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | interface SomeParameter {
15 |
16 | @BoolParam(key = "STALE_FLAG", namespace = "some_long_name")
17 | BoolParameter isStaleFeature();
18 |
19 | @BoolParam(key = "other_flag", namespace = "some_long_name")
20 | BoolParameter isOtherFlag();
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/java/feature_flag_system_2/treated/input/ExperimentInterfaceAnnotatedInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | @ParameterDefinition(namespace = "some_long_name")
15 | interface SomeParameter {
16 |
17 | @BoolParam(key = "STALE_FLAG")
18 | BoolParameter isStaleFeature();
19 |
20 | @BoolParam(key = "other_flag", namespace = "some_long_name")
21 | BoolParameter isOtherFlag();
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Global"
15 | from = "find_interface_extension"
16 | to = ["delete_class"]
17 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate/expected/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class TestClass implements SomeInterface {
17 | void testMethod() {
18 | System.out.println("Hello World!");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate/expected/TestSubClass.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/java/find_and_propagate/expected/TestSubClass.java
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate/input/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class TestClass implements SomeInterface {
17 | void testMethod() {
18 | System.out.println("Hello World!");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate/input/TestSubClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class TestSubClass extends TestClass {
17 |
18 | @Override
19 | void testMethod() {
20 | System.out.println("Hi World!");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate_invalid_substitutions/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Global"
15 | from = "find_interface_extension"
16 | to = ["delete_class"]
17 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate_invalid_substitutions/expected/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class TestClass implements SomeInterface {
17 | void testMethod() {
18 | System.out.println("Hello World!");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate_invalid_substitutions/expected/TestSubClass.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/java/find_and_propagate_invalid_substitutions/expected/TestSubClass.java
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate_invalid_substitutions/input/TestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class TestClass implements SomeInterface {
17 | void testMethod() {
18 | System.out.println("Hello World!");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/java/find_and_propagate_invalid_substitutions/input/TestSubClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class TestSubClass extends TestClass {
17 |
18 | @Override
19 | void testMethod() {
20 | System.out.println("Hi World!");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/java/handle_syntactically_incorrect_tree/expected/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | import java.util.List;
4 |
5 | class SomeClass {
6 |
7 | public static void run(List Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # This file contains rules to the specific feature flag API.
13 |
14 | [[rules]]
15 | name = "Match import statement"
16 | # This rules is purposefully syntactically incorrect (for testing)
17 | query = """(
18 | (import_declaration @import
19 | )"""
20 |
--------------------------------------------------------------------------------
/test-resources/java/incorrect_rule/input/Sample.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha ;
2 |
3 | import java.util.List;
4 |
5 | class A {
6 |
7 | List Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "File"
15 | from = "add_field_declaration"
16 | to = ["add_import"]
17 |
--------------------------------------------------------------------------------
/test-resources/java/insert_field_and_initializer/expected/AnotherClass.java:
--------------------------------------------------------------------------------
1 | package com.uber.piranha;
2 |
3 | import java.util.Set;
4 |
5 | public class AnotherClass {
6 |
7 | Set Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
13 | [[rules]]
14 | name = "replace_arrays_as_list_with_collection_singleton"
15 | query = """
16 | (
17 | ((method_invocation object: (identifier) @object
18 | name: (_) @name
19 | arguments : (argument_list (string_literal) @literal)) @mi)
20 | (#eq? @name "equals")
21 | )
22 | """
23 | replace_node = "mi"
24 | replace = "@literal.equals(@object)"
25 |
--------------------------------------------------------------------------------
/test-resources/java/new_line_character_used_in_string_literal/expected/SomeClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class SomeClass {
17 |
18 | void someMethod(String s) {
19 | assert ("Hello \n World".equals(s));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/java/new_line_character_used_in_string_literal/input/SomeClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | class SomeClass {
17 |
18 | void someMethod(String s) {
19 | assert (s.equals("Hello \n World"));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/java/non_seed_user_rule/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "File"
15 | from = "replace_arrays_as_list_with_collection_singleton"
16 | to = ["add_import_statement"]
17 |
--------------------------------------------------------------------------------
/test-resources/java/non_seed_user_rule/expected/AnotherClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | import java.util.ArrayList;
17 |
18 | class TestSubClass extends TestClass {
19 | ArrayList Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 | import java.util.Collections;
16 | import java.util.ArrayList;
17 |
18 |
19 | class SomeClass {
20 | ArrayList Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 | import java.util.ArrayList;
16 |
17 | class TestSubClass extends TestClass {
18 |
19 | ArrayList Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | import java.util.ArrayList;
17 |
18 | class SomeClass {
19 | ArrayList Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
13 | [[edges]]
14 | scope = "Parent"
15 | from = "spark_conf_change_java_scala"
16 | to = ["BuilderPattern"]
17 |
18 | [[edges]]
19 | scope = "Parent"
20 | from = "BuilderPattern"
21 | to = ["BuilderPattern"]
22 |
--------------------------------------------------------------------------------
/test-resources/java/parent_iterative/negative/expected/sample.java:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf;
4 | import org.apache.spark.sql.SparkSession;
5 |
6 | class Sample {
7 | void main() {
8 | // `setApp` and `setMaster` will not get updated
9 | val conf1 = new SparkSession.builder()
10 | .setMaster(master1)
11 | .setAppName(appName1)
12 | .executorEnv("spark.executor.extraClassPath1", "test1");
13 |
14 | // `setApp` and `setMaster` will not get updated
15 | val conf2 = new SparkSession.builder()
16 | .setAppName(appName2)
17 | .setMaster(master2)
18 | .sparkHome(sparkHome2)
19 | .executorEnv("spark.executor.extraClassPath2", "test2");
20 |
21 | // `setMaster` and `setExecutorEnv` will not get updated
22 | val conf3 = new SparkSession.builder()
23 | .setExecutorEnv("spark.executor.extraClassPath3", "test3")
24 | .setMaster(master3)
25 | .sparkHome(sparkHome3)
26 | .appName(appName3);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test-resources/java/parent_iterative/negative/input/sample.java:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf;
4 | import org.apache.spark.sql.SparkSession;
5 |
6 | class Sample {
7 | void main() {
8 |
9 | // `setApp` and `setMaster` will not get updated
10 | val conf1 = new SparkConf()
11 | .setMaster(master1)
12 | .setAppName(appName1)
13 | .setExecutorEnv("spark.executor.extraClassPath1", "test1");
14 |
15 | // `setApp` and `setMaster` will not get updated
16 | val conf2 = new SparkConf()
17 | .setAppName(appName2)
18 | .setMaster(master2)
19 | .setSparkHome(sparkHome2)
20 | .setExecutorEnv("spark.executor.extraClassPath2", "test2");
21 |
22 | // `setMaster` and `setExecutorEnv` will not get updated
23 | val conf3 = new SparkConf()
24 | .setExecutorEnv("spark.executor.extraClassPath3", "test3")
25 | .setMaster(master3)
26 | .setSparkHome(sparkHome3)
27 | .setAppName(appName3);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/test-resources/java/parent_iterative/positive/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 |
13 | [[edges]]
14 | scope = "ParentIterative"
15 | from = "spark_conf_change_java_scala"
16 | to = ["BuilderPattern"]
17 |
18 | [[edges]]
19 | scope = "ParentIterative"
20 | from = "BuilderPattern"
21 | to = ["BuilderPattern"]
22 |
--------------------------------------------------------------------------------
/test-resources/java/parent_iterative/positive/expected/sample.java:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf;
4 | import org.apache.spark.sql.SparkSession;
5 |
6 | class Sample {
7 | void main() {
8 |
9 | val conf1 = new SparkSession.builder()
10 | .master(master1)
11 | .appName(appName1)
12 | .executorEnv("spark.executor.extraClassPath1", "test1");
13 |
14 | val conf2 = new SparkSession.builder()
15 | .appName(appName2)
16 | .master(master2)
17 | .sparkHome(sparkHome2)
18 | .executorEnv("spark.executor.extraClassPath2", "test2");
19 |
20 | val conf3 = new SparkSession.builder()
21 | .executorEnv("spark.executor.extraClassPath3", "test3")
22 | .appName(appName3)
23 | .master(master3)
24 | .sparkHome(sparkHome3);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/test-resources/java/parent_iterative/positive/input/sample.java:
--------------------------------------------------------------------------------
1 | package com.piranha;
2 |
3 | import org.apache.spark.SparkConf;
4 | import org.apache.spark.sql.SparkSession;
5 |
6 | class Sample {
7 | void main() {
8 |
9 | val conf1 = new SparkConf()
10 | .setMaster(master1)
11 | .setAppName(appName1)
12 | .setExecutorEnv("spark.executor.extraClassPath1", "test1");
13 |
14 | val conf2 = new SparkConf()
15 | .setAppName(appName2)
16 | .setMaster(master2)
17 | .setSparkHome(sparkHome2)
18 | .setExecutorEnv("spark.executor.extraClassPath2", "test2");
19 |
20 | val conf3 = new SparkConf()
21 | .setExecutorEnv("spark.executor.extraClassPath3", "test3")
22 | .setAppName(appName3)
23 | .setMaster(master3)
24 | .setSparkHome(sparkHome3);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/test-resources/java/regex_based_matcher/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "File"
14 | from = "update_import"
15 | to = ["update_list_int"]
16 |
17 | [[edges]]
18 | scope = "Method"
19 | from = "update_list_int"
20 | to = ["update_add"]
21 |
22 |
23 | [[edges]]
24 | scope = "File"
25 | from = "delete_import_our_map_of"
26 | to = ["change_type_from_OurHashMap", "add_import_For_hashmap"]
27 |
28 | [[edges]]
29 | scope = "Method"
30 | from = "change_type_from_OurHashMap"
31 | to = ["update_push"]
32 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Class"
15 | from = "find_enum_constant"
16 | to = ["find_method"]
17 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find/input/SampleEnum.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.uber.piranha;
15 |
16 | public enum SampleEnum {
17 | FOO,
18 | BAR;
19 | public String getName() {
20 | switch(this) {
21 | case FOO:
22 | return "foo";
23 | case BAR:
24 | return "bar";
25 | }
26 | }
27 | }
28 |
29 | public class SomeClass {
30 | public void someMethod(){
31 | System.out.println("Hello World!");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find_replace_multiple_code_bases/folder_1/Sample.java:
--------------------------------------------------------------------------------
1 | package org.piranha.examples;
2 |
3 | import java.util.List;
4 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find_replace_multiple_code_bases/folder_2/Sample.java:
--------------------------------------------------------------------------------
1 | package org.piranha.examples;
2 |
3 | import java.util.List;
4 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find_replace_multiple_code_bases/folder_3/Sample.java:
--------------------------------------------------------------------------------
1 | package org.piranha.examples;
2 |
3 | import java.util.List;
4 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find_with_include_exclude/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Class"
15 | from = "find_enum_constant"
16 | to = ["find_method"]
17 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find_with_include_exclude/input/folder_1/SomeEnum.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package folder_1;
15 |
16 | public enum SampleEnum {
17 | FOO,
18 | BAR;
19 | public String getName() {
20 | switch(this) {
21 | case FOO:
22 | return "foo";
23 | case BAR:
24 | return "bar";
25 | }
26 | }
27 | }
28 |
29 | public class SomeClass {
30 | public void someMethod(){
31 | System.out.println("Hello World!");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test-resources/java/structural_find_with_include_exclude/input/folder_2/SampleEnum.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package folder_2;
15 |
16 | public enum SampleEnum {
17 | FOO,
18 | BAR;
19 | public String getName() {
20 | switch(this) {
21 | case FOO:
22 | return "foo";
23 | case BAR:
24 | return "bar";
25 | }
26 | }
27 | }
28 |
29 | public class SomeClass {
30 | public void someMethod(){
31 | System.out.println("Hello World!");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_delete_consecutive_lines/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "Delete File"
14 | query = "(((method_declaration name: (_)@name) @md) (#eq? @name \"foobar\"))"
15 | replace_node = "name"
16 | replace = "barfoo"
17 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_delete_consecutive_lines/expected/Sample.java:
--------------------------------------------------------------------------------
1 | package foo.bar;
2 |
3 | public class Sample {
4 |
5 | public void barfoo() {
6 |
7 | System.out.println("Hello World!");
8 |
9 | System.out.println();
10 | }
11 |
12 | public void foobar1() {
13 |
14 | System.out.println("Hello World!");
15 |
16 | System.out.println();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_delete_consecutive_lines/input/Sample.java:
--------------------------------------------------------------------------------
1 | package foo.bar;
2 |
3 | public class Sample {
4 |
5 | public void foobar() {
6 |
7 | System.out.println("Hello World!");
8 |
9 |
10 | System.out.println();
11 | }
12 |
13 | public void foobar1() {
14 |
15 | System.out.println("Hello World!");
16 |
17 |
18 |
19 |
20 | System.out.println();
21 | }
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_delete_if_empty/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "Delete File"
14 | query = "(program) @program"
15 | replace_node = "program"
16 | replace = ""
17 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_delete_if_empty/expected/.placeholder:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/java/user_option_delete_if_empty/expected/.placeholder
--------------------------------------------------------------------------------
/test-resources/java/user_option_delete_if_empty/input/Sample.java:
--------------------------------------------------------------------------------
1 | package foo.bar;
2 |
3 | public class Sample {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_do_not_delete_consecutive_lines/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "Delete File"
14 | query = "(((method_declaration name: (_)@name) @md) (#eq? @name \"foobar\"))"
15 | replace_node = "name"
16 | replace = "barfoo"
17 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_do_not_delete_consecutive_lines/expected/Sample.java:
--------------------------------------------------------------------------------
1 | package foo.bar;
2 |
3 | public class Sample {
4 |
5 | public void barfoo() {
6 |
7 | System.out.println("Hello World!");
8 |
9 |
10 | System.out.println();
11 | }
12 |
13 | public void foobar1() {
14 |
15 | System.out.println("Hello World!");
16 |
17 |
18 |
19 |
20 | System.out.println();
21 | }
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_do_not_delete_consecutive_lines/input/Sample.java:
--------------------------------------------------------------------------------
1 | package foo.bar;
2 |
3 | public class Sample {
4 |
5 | public void foobar() {
6 |
7 | System.out.println("Hello World!");
8 |
9 |
10 | System.out.println();
11 | }
12 |
13 | public void foobar1() {
14 |
15 | System.out.println("Hello World!");
16 |
17 |
18 |
19 |
20 | System.out.println();
21 | }
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_do_not_delete_if_empty/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "Delete File"
14 | query = "(program) @program"
15 | replace_node = "program"
16 | replace = ""
17 |
--------------------------------------------------------------------------------
/test-resources/java/user_option_do_not_delete_if_empty/expected/Sample.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/java/user_option_do_not_delete_if_empty/expected/Sample.java
--------------------------------------------------------------------------------
/test-resources/java/user_option_do_not_delete_if_empty/input/Sample.java:
--------------------------------------------------------------------------------
1 | package foo.bar;
2 |
3 | public class Sample {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/test-resources/kt/feature_flag_system_1/control/expected/TestEnum.kt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/kt/feature_flag_system_1/control/expected/TestEnum.kt
--------------------------------------------------------------------------------
/test-resources/kt/feature_flag_system_1/control/input/TestEnum.kt:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | package com.uber.input
15 |
16 | enum class TestEnum {
17 | @Autorollout
18 | STALE_FLAG,
19 | }
20 |
--------------------------------------------------------------------------------
/test-resources/kt/feature_flag_system_1/treated/expected/TestEnum.kt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/kt/feature_flag_system_1/treated/expected/TestEnum.kt
--------------------------------------------------------------------------------
/test-resources/kt/feature_flag_system_1/treated/input/TestEnum.kt:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | package com.uber.input
15 |
16 | enum class TestEnum {
17 | @Autorollout
18 | STALE_FLAG,
19 | }
20 |
--------------------------------------------------------------------------------
/test-resources/kt/feature_flag_system_2/control/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Global"
15 | from = "delete_flag_method_declaration_fully_annotated"
16 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
17 |
18 | [[edges]]
19 | scope = "Global"
20 | from = "delete_flag_method_declaration_inside_annotated_interface"
21 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
22 |
--------------------------------------------------------------------------------
/test-resources/kt/feature_flag_system_2/treated/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # The edges in this file specify the flow between the rules
13 | [[edges]]
14 | scope = "Global"
15 | from = "delete_flag_method_declaration_fully_annotated"
16 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
17 |
18 | [[edges]]
19 | scope = "Global"
20 | from = "delete_flag_method_declaration_inside_annotated_interface"
21 | to = ["replace_flag_method_with_boolean_literal", "delete_put"]
22 |
--------------------------------------------------------------------------------
/test-resources/kt/file_scoped_chain_rules/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "File"
14 | from = "transform_api1"
15 | to = ["delete_import_statement"]
16 |
--------------------------------------------------------------------------------
/test-resources/kt/file_scoped_chain_rules/expected/Sample.kt:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | package com.uber.piranha
15 |
16 | interface SceneStateParameters {
17 |
18 | fun create(cachedParameters: CachedParameters): SceneStateParameters {
19 | return SceneStateParametersProvider.create(cachedParameters)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/kt/file_scoped_chain_rules/input/Sample.kt:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | except in compliance with the License. You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the
9 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | express or implied. See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | package com.uber.piranha
15 |
16 | import com.uber.something.piranha.ParameterUtils
17 |
18 | interface SceneStateParameters {
19 | fun create(cachedParameters: CachedParameters): SceneStateParameters {
20 | return ParameterUtils.create(SceneStateParameters::class.java, cachedParameters)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/python/delete_cleanup_str_in_list/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "delete_str_literal_in_list"
15 | to = ["delete_empty_list_assignment"]
16 |
--------------------------------------------------------------------------------
/test-resources/python/delete_cleanup_str_in_list/expected/only_lists.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | deps = ['dependency1_1', 'dependency3']
13 | nums = [1, 2, 3]
14 | deps2 = ["dependency1_1"]
15 | empty_list = []
16 |
--------------------------------------------------------------------------------
/test-resources/python/delete_cleanup_str_in_list/input/only_lists.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | deps = ['dependency1', 'dependency2', 'dependency3']
13 | nums = [1, 2, 3]
14 | deps2 = ["dependency2", "dependency1"]
15 | deps3 = ['dependency2']
16 | empty_list = []
17 |
--------------------------------------------------------------------------------
/test-resources/python/structural_find/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # This file contains rules to the specific feature flag API.
13 |
14 | # For the two lists below, the query will match 1 result (the `a` list).
15 | # a = ['a', 'b']
16 | # b = [1, 2]
17 | # `@ls` will match lists that contain string literals as elements
18 | #
19 | [[rules]]
20 | name = "find_lists_with_str_literals"
21 | query = """
22 | (
23 | (list
24 | (string)+ @s
25 | (_)*
26 | ) @ls
27 | )
28 | """
29 |
--------------------------------------------------------------------------------
/test-resources/python/structural_find/input/list_as_arg.py:
--------------------------------------------------------------------------------
1 | func_call(
2 | name = "call",
3 | deps = [
4 | 'dependency1',
5 | 'dependency2',
6 | 'dependency3',
7 | ],
8 | nums = [
9 | 1,
10 | 2,
11 | 3,
12 | ],
13 | )
14 |
--------------------------------------------------------------------------------
/test-resources/python/structural_find/input/only_lists.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | deps = ['dependency1', 'dependency2', 'dependency3']
13 | nums = [1, 2, 3]
14 | deps2 = ["dependency1"]
15 |
--------------------------------------------------------------------------------
/test-resources/ruby/delete_lines_after_return/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "delete_all_statements_after_return"
3 | query = """
4 | (
5 | (body_statement
6 | ((_)* @pre)
7 | [
8 | (
9 | (return)
10 | ?(comment)
11 | ) @r
12 | (
13 | (return)
14 | ) @r
15 | ]
16 | ((_)+ @post)
17 | ) @body
18 | )
19 | """
20 | replace = ""
21 | replace_node = "post"
22 |
--------------------------------------------------------------------------------
/test-resources/ruby/delete_lines_after_return/expected/delete_lines_after_return.rb:
--------------------------------------------------------------------------------
1 | def remove_multiple_lines_after_return
2 | before_return
3 | return super
4 | end
5 |
--------------------------------------------------------------------------------
/test-resources/ruby/delete_lines_after_return/input/delete_lines_after_return.rb:
--------------------------------------------------------------------------------
1 | def remove_multiple_lines_after_return
2 | before_return
3 | return super
4 | after_return
5 | another_method_call
6 | end
7 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_empty_if_or_unless_statement/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Before :
2 | # if true
3 | # end
4 | # After :
5 | #
6 | [[rules]]
7 | name = "replace_empty_if_or_unless"
8 | groups = ["if_cleanup"]
9 | query = """
10 | [
11 | (if
12 | condition: [(true) (false)]
13 | .
14 | )@conditional
15 | (if
16 | condition: (parenthesized_statements [(true) (false)])
17 | .
18 | )@conditional
19 | (unless
20 | condition: [(true) (false)]
21 | .
22 | )@conditional
23 | (unless
24 | condition: (parenthesized_statements [(true) (false)])
25 | .
26 | )@conditional
27 | ]
28 | """
29 | replace = ""
30 | replace_node = "conditional"
31 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_empty_if_or_unless_statement/expected/test_empty_if_unless_rules.rb:
--------------------------------------------------------------------------------
1 | def test_empty_unless_statement_true
2 | end
3 |
4 | def test_empty_unless_statement_false
5 | end
6 |
7 | def test_empty_unless_statement_parenthesized_true
8 | end
9 |
10 | def test_empty_unless_statement_parenthesized_false
11 | end
12 |
13 | def test_empty_if_statement_true
14 | end
15 |
16 | def test_empty_if_statement_false
17 | end
18 |
19 | def test_empty_if_statement_parenthesized_true
20 | end
21 |
22 | def test_empty_if_statement_parenthesized_false
23 | end
24 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_empty_if_or_unless_statement/input/test_empty_if_unless_rules.rb:
--------------------------------------------------------------------------------
1 | def test_empty_unless_statement_true
2 | unless true
3 | end
4 | end
5 |
6 | def test_empty_unless_statement_false
7 | unless false
8 | end
9 | end
10 |
11 | def test_empty_unless_statement_parenthesized_true
12 | unless(true)
13 | end
14 | end
15 |
16 | def test_empty_unless_statement_parenthesized_false
17 | unless(false)
18 | end
19 | end
20 |
21 | def test_empty_if_statement_true
22 | if true
23 | end
24 | end
25 |
26 | def test_empty_if_statement_false
27 | if false
28 | end
29 | end
30 |
31 | def test_empty_if_statement_parenthesized_true
32 | if(true)
33 | end
34 | end
35 |
36 | def test_empty_if_statement_parenthesized_false
37 | if(false)
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_if_statement/expected/test_if_rules_inline.rb:
--------------------------------------------------------------------------------
1 | def test_if_statement_inline_true
2 | do_something
3 | end
4 |
5 | def test_if_statement_inline_false
6 | end
7 |
8 | def test_if_statement_inline_true_parenthesized
9 | do_something
10 | end
11 |
12 | def test_if_statement_inline_false_parenthesized
13 | end
14 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_if_statement/expected/test_if_rules_with_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_if_statement_true_with_else
2 | do_something
3 | end
4 |
5 | def test_if_statement_true_parenthesized_with_else
6 | do_something
7 | end
8 |
9 | def test_if_statement_false_with_else
10 | do_something_else
11 | end
12 |
13 | def test_if_statement_false_parenthesized_with_else
14 | do_something_else
15 | end
16 |
17 | def test_if_statement_with_elsif
18 | if check_if_true?
19 | do_something
20 | else
21 | do_something_else
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_if_statement/expected/test_if_rules_without_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_if_statement_true_without_else
2 | do_something
3 | end
4 |
5 | def test_if_statement_true_parenthesized_without_else
6 | do_something
7 | end
8 |
9 | def test_if_statement_false_without_else
10 | end
11 |
12 | def test_if_statement_false_parenthesized_without_else
13 | end
14 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_if_statement/input/test_if_rules_inline.rb:
--------------------------------------------------------------------------------
1 | def test_if_statement_inline_true
2 | do_something if true
3 | end
4 |
5 | def test_if_statement_inline_false
6 | do_something if false
7 | end
8 |
9 | def test_if_statement_inline_true_parenthesized
10 | do_something if (true)
11 | end
12 |
13 | def test_if_statement_inline_false_parenthesized
14 | do_something if (false)
15 | end
16 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_if_statement/input/test_if_rules_with_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_if_statement_true_with_else
2 | if true
3 | do_something
4 | else
5 | do_something_else
6 | end
7 | end
8 |
9 | def test_if_statement_true_parenthesized_with_else
10 | if(true)
11 | do_something
12 | else
13 | do_something_else
14 | end
15 | end
16 |
17 | def test_if_statement_false_with_else
18 | if false
19 | do_something
20 | else
21 | do_something_else
22 | end
23 | end
24 |
25 | def test_if_statement_false_parenthesized_with_else
26 | if(false)
27 | do_something
28 | else
29 | do_something_else
30 | end
31 | end
32 |
33 | def test_if_statement_with_elsif
34 | if check_if_true?
35 | do_something
36 | elsif true
37 | do_something_else
38 | else
39 | do_something_else_again
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_if_statement/input/test_if_rules_without_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_if_statement_true_without_else
2 | if true
3 | do_something
4 | end
5 | end
6 |
7 | def test_if_statement_true_parenthesized_without_else
8 | if(true)
9 | do_something
10 | end
11 | end
12 |
13 | def test_if_statement_false_without_else
14 | if false
15 | do_something
16 | end
17 | end
18 |
19 | def test_if_statement_false_parenthesized_without_else
20 | if(false)
21 | do_something_else
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_ternary_operator/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Before :
2 | # true ? flag_flow : non_flag_flow
3 | # After :
4 | # flag_flow
5 | #
6 | [[rules]]
7 | name = "replace_ternary_operator_true"
8 | groups = ["if_cleanup"]
9 | query = """
10 | (
11 | (conditional
12 | [
13 | condition: (true)
14 | condition: (parenthesized_statements (true))
15 | ]
16 | consequence : (_)* @consequence
17 | alternative: (_)* @alternative
18 | )
19 | @conditional)
20 | """
21 | replace = "@consequence"
22 | replace_node = "conditional"
23 |
24 | # Before :
25 | # false ? flag_flow : non_flag_flow
26 | # After :
27 | # non_flag_flow
28 | #
29 | [[rules]]
30 | name = "replace_ternary_operator_false"
31 | groups = ["if_cleanup"]
32 | query = """
33 | (
34 | (conditional
35 | [
36 | condition: (false)
37 | condition: (parenthesized_statements (false))
38 | ]
39 | consequence : (_)* @consequence
40 | alternative: (_)* @alternative
41 | )
42 | @conditional)
43 | """
44 | replace = "@alternative"
45 | replace_node = "conditional"
46 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_ternary_operator/expected/test_if_rules_ternary.rb:
--------------------------------------------------------------------------------
1 | def test_if_ternary
2 | do_something
3 | end
4 |
5 | def test_if_ternary_negeated
6 | do_something_else
7 | end
8 |
9 | def test_if_ternary_parenthesized
10 | do_something
11 | end
12 |
13 | def test_if_ternary_negeated_parenthesized
14 | do_something_else
15 | end
16 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_ternary_operator/input/test_if_rules_ternary.rb:
--------------------------------------------------------------------------------
1 | def test_if_ternary
2 | true ? do_something : do_something_else
3 | end
4 |
5 | def test_if_ternary_negeated
6 | false ? do_something : do_something_else
7 | end
8 |
9 | def test_if_ternary_parenthesized
10 | (true) ? do_something : do_something_else
11 | end
12 |
13 | def test_if_ternary_negeated_parenthesized
14 | (false) ? do_something : do_something_else
15 | end
16 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_unless_statement/expected/test_unless_rules_inline.rb:
--------------------------------------------------------------------------------
1 | def test_unless_statement_inline_true
2 | end
3 |
4 | def test_unless_statement_inline_false
5 | do_something
6 | end
7 |
8 | def test_unless_statement_inline_true_parenthesized
9 | end
10 |
11 | def test_unless_statement_inline_false_parenthesized
12 | do_something
13 | end
14 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_unless_statement/expected/test_unless_rules_with_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_unless_statement_true_with_else
2 | do_something_else
3 | end
4 |
5 | def test_unless_statement_true_parenthesized_with_else
6 | do_something_else
7 | end
8 |
9 | def test_unless_statement_false_with_else
10 | do_something
11 | end
12 |
13 | def test_unless_statement_false_parenthesized_with_else
14 | do_something
15 | end
16 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_unless_statement/expected/test_unless_rules_without_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_unless_statement_true_without_else
2 | end
3 |
4 | def test_unless_statement_true_parenthesized_without_else
5 | end
6 |
7 | def test_unless_statement_false_without_else
8 | do_something
9 | end
10 |
11 | def test_unless_statement_false_parenthesized_without_else
12 | do_something_else
13 | end
14 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_unless_statement/input/test_unless_rules_inline.rb:
--------------------------------------------------------------------------------
1 | def test_unless_statement_inline_true
2 | do_something unless true
3 | end
4 |
5 | def test_unless_statement_inline_false
6 | do_something unless false
7 | end
8 |
9 | def test_unless_statement_inline_true_parenthesized
10 | do_something unless (true)
11 | end
12 |
13 | def test_unless_statement_inline_false_parenthesized
14 | do_something unless (false)
15 | end
16 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_unless_statement/input/test_unless_rules_with_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_unless_statement_true_with_else
2 | unless true
3 | do_something
4 | else
5 | do_something_else
6 | end
7 | end
8 |
9 | def test_unless_statement_true_parenthesized_with_else
10 | unless(true)
11 | do_something
12 | else
13 | do_something_else
14 | end
15 | end
16 |
17 | def test_unless_statement_false_with_else
18 | unless false
19 | do_something
20 | else
21 | do_something_else
22 | end
23 | end
24 |
25 | def test_unless_statement_false_parenthesized_with_else
26 | unless(false)
27 | do_something
28 | else
29 | do_something_else
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/test-resources/ruby/replace_unless_statement/input/test_unless_rules_without_else_block.rb:
--------------------------------------------------------------------------------
1 | def test_unless_statement_true_without_else
2 | unless true
3 | do_something
4 | end
5 | end
6 |
7 | def test_unless_statement_true_parenthesized_without_else
8 | unless(true)
9 | do_something
10 | end
11 | end
12 |
13 | def test_unless_statement_false_without_else
14 | unless false
15 | do_something
16 | end
17 | end
18 |
19 | def test_unless_statement_false_parenthesized_without_else
20 | unless(false)
21 | do_something_else
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_if_lambda_conditional_statements/expected/simplify_if_lambda_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | class CleanedUpController < ApplicationController
2 | before_action :keep_if_action, only: [:create, :update]
3 | before_action :set_variable
4 | before_action :authenticate_user!
5 | before_action :authenticate_user_with_params!
6 |
7 | before_action :do_not_change, only: [:create, :update], if: -> { check_something? }
8 | end
9 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_if_lambda_conditional_statements/input/simplify_if_lambda_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | class CleanedUpController < ApplicationController
2 | before_action :keep_if_action, only: [:create, :update], if: -> { true }
3 | before_action :set_variable, if: ->(c) { true }
4 | before_action :authenticate_user!, if: lambda { true }
5 | before_action :authenticate_user_with_params!, if: lambda { |c| true }
6 |
7 | before_action :keep_if_action, only: [:create, :update], if: -> { false }
8 | before_action :set_variable, if: ->(c) { false }
9 | before_action :authenticate_user!, if: lambda { false }
10 | before_action :authenticate_user_with_params!, if: lambda { |c| false }
11 |
12 | before_action :do_not_change, only: [:create, :update], if: -> { check_something? }
13 | end
14 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_if_proc_conditional_statements/expected/simplify_if_proc_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | after_commit :do_something, on: :create
2 |
3 | attribute :created_date do |object|
4 | object.actions
5 | end
6 |
7 | after_commit :do_something, on: :create
8 |
9 | attribute :planned_date do |object|
10 | object.actions
11 | end
12 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_if_proc_conditional_statements/input/simplify_if_proc_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | after_commit :do_something, on: :create, if: Proc.new { true }
2 | after_commit :do_lots_of_things, on: :create, if: Proc.new { false }
3 |
4 | attribute :created_date, if: Proc.new { |object| true } do |object|
5 | object.actions
6 | end
7 |
8 | attribute :release_date, if: Proc.new { |object| false} do |object|
9 | object.actions
10 | end
11 |
12 | after_commit :do_something, on: :create, if: proc { true }
13 | after_commit :do_lots_of_things, on: :create, if: proc { false }
14 |
15 | attribute :planned_date, if: proc { |object| true } do |object|
16 | object.actions
17 | end
18 |
19 | attribute :future_date, if: proc { |object| false } do |object|
20 | object.actions
21 | end
22 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_rspec_block_expressions/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Before :
2 | # before(:all) { }
3 | # After :
4 | #
5 | #
6 | [[rules]]
7 | name = "remove_empty_rspec_blocks"
8 | groups = ["block_removal"]
9 | query = """
10 | (
11 | (call
12 | method: (identifier) @method
13 | (argument_list (simple_symbol) @args)
14 | [
15 | (block
16 | !body
17 | )
18 | (do_block
19 | !body
20 | )
21 | ]
22 | )@call
23 | (#match? @method "(before|after)")
24 | (#match? @args "(:suite|:all|:context|:each|:example)")
25 | )
26 | """
27 | replace = ""
28 | replace_node = "call"
29 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_rspec_block_expressions/expected/simplify_rspec_block_expressions.rb:
--------------------------------------------------------------------------------
1 | after(:all) do
2 | do_something
3 | end
4 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_rspec_block_expressions/input/simplify_rspec_block_expressions.rb:
--------------------------------------------------------------------------------
1 | before(:all) do
2 | end
3 |
4 | after(:all) { }
5 |
6 | before(:each) do
7 | end
8 |
9 | after(:each) { }
10 |
11 | before(:suite) do
12 | end
13 |
14 | after(:suite) { }
15 |
16 | before(:context) do
17 | end
18 |
19 | after(:context) { }
20 |
21 | before(:example) do
22 | end
23 |
24 | after(:example) { }
25 |
26 |
27 | after(:all) do
28 | do_something
29 | end
30 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_unless_lambda_conditional_statements/expected/simplify_unless_lambda_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | class CleanedUpController < ApplicationController
2 | before_action :unless_staby_syntax_keep_unless_action, only: [:create, :update]
3 | before_action :unless_staby_syntax_set_variable
4 | before_action :unless_staby_syntax_authenticate_user!
5 | before_action :unless_staby_syntax_authenticate_user_with_params!
6 |
7 | before_action :do_not_change, only: [:create, :update], unless: -> { check_something? }
8 | end
9 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_unless_lambda_conditional_statements/input/simplify_unless_lambda_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | class CleanedUpController < ApplicationController
2 | before_action :unless_lambda_syntax_keep_unless_action, only: [:create, :update], unless: -> { true }
3 | before_action :unless_lambda_syntax_set_variable, unless: ->(c) { true }
4 | before_action :unless_lambda_syntax_authenticate_user!, unless: lambda { true }
5 | before_action :unless_lambda_syntax_authenticate_user_with_params!, unless: lambda { |c| true }
6 |
7 | before_action :unless_staby_syntax_keep_unless_action, only: [:create, :update], unless: -> { false }
8 | before_action :unless_staby_syntax_set_variable, unless: ->(c) { false }
9 | before_action :unless_staby_syntax_authenticate_user!, unless: lambda { false }
10 | before_action :unless_staby_syntax_authenticate_user_with_params!, unless: lambda { |c| false }
11 |
12 | before_action :do_not_change, only: [:create, :update], unless: -> { check_something? }
13 | end
14 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_unless_proc_conditional_statements/expected/simplify_unless_proc_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | after_commit :do_lots_of_things, on: :create
2 |
3 | attribute :release_date do |object|
4 | object.actions
5 | end
6 |
7 | after_commit :do_lots_of_other_things, on: :create
8 |
9 | attribute :future_date do |object|
10 | object.actions
11 | end
12 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_unless_proc_conditional_statements/input/simplify_unless_proc_conditional_statements.rb:
--------------------------------------------------------------------------------
1 | after_commit :do_something, on: :create, unless: Proc.new { true }
2 | after_commit :do_lots_of_things, on: :create, unless: Proc.new { false }
3 |
4 | attribute :created_date, unless: Proc.new { |object| true } do |object|
5 | object.actions
6 | end
7 |
8 | attribute :release_date, unless: Proc.new { |object| false} do |object|
9 | object.actions
10 | end
11 |
12 | after_commit :do_flag_enabled_stuff, on: :create, unless: proc { true }
13 | after_commit :do_lots_of_other_things, on: :create, unless: proc { false }
14 |
15 | attribute :planned_date, unless: proc { |object| true } do |object|
16 | object.actions
17 | end
18 |
19 | attribute :future_date, unless: proc { |object| false } do |object|
20 | object.actions
21 | end
22 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_variable_assigned_flag_check/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | [[edges]]
2 | scope = "Method"
3 | from = "delete_variable_declaration"
4 | to = ["replace_identifier_with_value"]
5 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_variable_assigned_flag_check/expected/simplify_variable_assigned_flag_check.rb:
--------------------------------------------------------------------------------
1 | def test_cleanup_when_assigned_to_local_variable
2 |
3 | do_flag_enabled_stuff
4 | end
5 |
6 | def test_cleanup_when_assigned_to_local_variable_and_redeclared
7 | is_flag_enabled = true
8 | is_flag_enabled = check_another_condition?
9 | if(is_flag_enabled)
10 | do_flag_enabled_stuff
11 | else
12 | do_non_flag_stuff
13 | end
14 | end
15 |
16 | def test_cleanup_when_assigned_to_instance_variable
17 |
18 | do_flag_enabled_stuff
19 | end
20 |
21 | def test_cleanup_when_assigned_to_instance_variable_and_redeclared
22 | @is_flag_enabled = true
23 | @is_flag_enabled = check_another_condition?
24 | if(@is_flag_enabled)
25 | do_flag_enabled_stuff
26 | else
27 | do_non_flag_stuff
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/test-resources/ruby/simplify_variable_assigned_flag_check/input/simplify_variable_assigned_flag_check.rb:
--------------------------------------------------------------------------------
1 | def test_cleanup_when_assigned_to_local_variable
2 | is_flag_enabled = true
3 | if(is_flag_enabled)
4 | do_flag_enabled_stuff
5 | else
6 | do_non_flag_stuff
7 | end
8 | end
9 |
10 | def test_cleanup_when_assigned_to_local_variable_and_redeclared
11 | is_flag_enabled = true
12 | is_flag_enabled = check_another_condition?
13 | if(is_flag_enabled)
14 | do_flag_enabled_stuff
15 | else
16 | do_non_flag_stuff
17 | end
18 | end
19 |
20 | def test_cleanup_when_assigned_to_instance_variable
21 | @is_flag_enabled = true
22 | if(@is_flag_enabled)
23 | do_flag_enabled_stuff
24 | else
25 | do_non_flag_stuff
26 | end
27 | end
28 |
29 | def test_cleanup_when_assigned_to_instance_variable_and_redeclared
30 | @is_flag_enabled = true
31 | @is_flag_enabled = check_another_condition?
32 | if(@is_flag_enabled)
33 | do_flag_enabled_stuff
34 | else
35 | do_non_flag_stuff
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/test-resources/scala/simple_match_replace/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "Replace + operator"
3 | query = "cs :[x] + :[y]"
4 | replace_node = "*"
5 | replace = "add(@x,@y)"
6 |
--------------------------------------------------------------------------------
/test-resources/scala/simple_match_replace/expected/Sample.scala:
--------------------------------------------------------------------------------
1 | object AddTwoNumbers {
2 | def main(args: Array[String]): Unit = {
3 | // Read input from the user
4 | print("Enter first number: ")
5 | val num1 = scala.io.StdIn.readDouble()
6 |
7 | print("Enter second number: ")
8 | val num2 = scala.io.StdIn.readDouble()
9 |
10 | // Calculate the sum
11 | val sum = add(num1, num2)
12 |
13 | // Display the result
14 | println(s"The sum of $num1 and $num2 is: $sum")
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test-resources/scala/simple_match_replace/input/Sample.scala:
--------------------------------------------------------------------------------
1 | object AddTwoNumbers {
2 | def main(args: Array[String]): Unit = {
3 | // Read input from the user
4 | print("Enter first number: ")
5 | val num1 = scala.io.StdIn.readDouble()
6 |
7 | print("Enter second number: ")
8 | val num2 = scala.io.StdIn.readDouble()
9 |
10 | // Calculate the sum
11 | val sum = num1 + num2
12 |
13 | // Display the result
14 | println(s"The sum of $num1 and $num2 is: $sum")
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test-resources/scm/simple_rename/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # Renames tree-sitter query tag from `name` to `method_name`
13 | [[rules]]
14 | name = "rename_tag"
15 | query = """
16 | (
17 | (named_node name: (_)@named_node (field_definition (named_node (capture name: (_)@i) ))) @n
18 | (#eq? @named_node "method_declaration")
19 | (#eq? @i "name")
20 | )
21 | """
22 | replace_node = "i"
23 | replace = "method_name"
24 | is_seed_rule = true
25 |
--------------------------------------------------------------------------------
/test-resources/scm/simple_rename/expected/sample.scm:
--------------------------------------------------------------------------------
1 | (method_declaration name: (_) @method_name) @md
2 |
--------------------------------------------------------------------------------
/test-resources/scm/simple_rename/input/sample.scm:
--------------------------------------------------------------------------------
1 | (method_declaration name: (_) @name) @md
2 |
--------------------------------------------------------------------------------
/test-resources/strings/sample_strings/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | # This file contains rules to the specific feature flag API.
13 |
14 | #
15 | # For @stale_flag_name = test_second_experiment and @treated = true
16 | # Before
17 | # case test_second_experiment
18 | # After
19 | #
20 | #
21 | [[rules]]
22 | name = "delete_entry_by_key"
23 | query = """
24 | (
25 | (statement (assignment_statement left :(string_literal) @lhs)) @statement
26 | (#eq? @lhs "\\\"@stale_key\\\"")
27 | )"""
28 | replace_node = "statement"
29 | replace = ""
30 | holes = ["stale_key"]
31 |
--------------------------------------------------------------------------------
/test-resources/strings/sample_strings/expected/sample_en.strings:
--------------------------------------------------------------------------------
1 | /* Menu item to make the current document plain text */
2 | "Make Plain Text" = "Make Plain Text";
3 |
4 | /* Menu item to make the current document italic text */
5 | "Make Italic Text" = "Make Italic Text";
6 |
--------------------------------------------------------------------------------
/test-resources/strings/sample_strings/input/sample_en.strings:
--------------------------------------------------------------------------------
1 | /* Menu item to make the current document plain text */
2 | "Make Plain Text" = "Make Plain Text";
3 |
4 | // Menu item to make the current document rich text
5 | "Make Rich Text" = "Make Rich Text";
6 |
7 | /* Menu item to make the current document italic text */
8 | "Make Italic Text" = "Make Italic Text";
9 |
10 | /* Menu item to make the current document rich text */
11 | "Make Rich Text" = "Make Rich Text";
12 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | from = "delete_switch_entry"
14 | scope = "Class"
15 | to = ["delete_enum_entry"]
16 |
17 | [[edges]]
18 | from = "delete_enum_entry"
19 | scope = "Global"
20 | to = ["read_only_detect_type_alias"]
21 |
22 |
23 | [[edges]]
24 | from = "read_only_detect_type_alias"
25 | scope = "Global"
26 | to = ["delete_factory_class_inherits_relevant_type_alias"]
27 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete/expected/Experiment.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | import Experiment
15 |
16 | public enum SomePluginSwitch: PluginSwitch {
17 | case defaultIcon
18 |
19 | case defaultTitle
20 | case premiumTitle
21 |
22 |
23 |
24 | public var generatedExperimentKey: String {
25 | switch self {
26 | case .defaultIcon: return "Default-Icon"
27 |
28 | case .defaultTitle: return "Default-Title"
29 | case .premiumTitle: return "Premium-Title"
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete/expected/Factory.swift:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/swift/cascade_file_delete/expected/Factory.swift
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete/expected/SomeProtocols.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | public typealias SomePluginFactory = PluginFactory Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | import Experiment
16 |
17 | public enum SomePluginSwitch: PluginSwitch {
18 | case defaultIcon
19 | case premiumIcon // premium icon
20 | case defaultTitle
21 | case premiumTitle
22 |
23 |
24 |
25 | public var generatedExperimentKey: String {
26 | switch self {
27 | case .defaultIcon: return "Default-Icon"
28 | case .premiumIcon: return "Premium-Icon"
29 | case .defaultTitle: return "Default-Title"
30 | case .premiumTitle: return "Premium-Title"
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete/input/Factory.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | public final class SomeFactory: SomePluginFactory {
16 | // MARK: - Initializer
17 | public init(cachedExperiments: CachedExperimenting) {
18 | super.init(pluginSwitch: .premiumIcon) { context in
19 | handler(cachedExperiments: cachedExperiments, context: context)
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete/input/SomeProtocols.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | public typealias SomePluginFactory = PluginFactory Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | from = "delete_switch_entry"
14 | scope = "Class"
15 | to = ["delete_enum_entry"]
16 |
17 | [[edges]]
18 | from = "delete_enum_entry"
19 | scope = "Global"
20 | to = ["read_only_detect_type_alias"]
21 |
22 |
23 | [[edges]]
24 | from = "read_only_detect_type_alias"
25 | scope = "Global"
26 | to = ["delete_factory_class_inherits_relevant_type_alias"]
27 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete_custom_global_tag/expected/Experiment.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | import Experiment
15 |
16 | public enum SomePluginSwitch: PluginSwitch {
17 | case defaultIcon
18 |
19 | case defaultTitle
20 | case premiumTitle
21 |
22 |
23 |
24 | public var generatedExperimentKey: String {
25 | switch self {
26 | case .defaultIcon: return "Default-Icon"
27 |
28 | case .defaultTitle: return "Default-Title"
29 | case .premiumTitle: return "Premium-Title"
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete_custom_global_tag/expected/Factory.swift:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uber/piranha/7320e13eb91be9af799ea6bbf88c5413a840762a/test-resources/swift/cascade_file_delete_custom_global_tag/expected/Factory.swift
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete_custom_global_tag/expected/SomeProtocols.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | public typealias SomePluginFactory = PluginFactory Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | public final class SomeFactory: SomePluginFactory {
16 | // MARK: - Initializer
17 | public init(cachedExperiments: CachedExperimenting) {
18 | super.init(pluginSwitch: .premiumIcon) { context in
19 | handler(cachedExperiments: cachedExperiments, context: context)
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-resources/swift/cascade_file_delete_custom_global_tag/input/SomeProtocols.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2023 Uber Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 | * except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the
10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 | * express or implied. See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | public typealias SomePluginFactory = PluginFactory Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | func f1(_ someParameter: SomeParameterType) {
13 | switch someParameter.actionName {
14 | case .a:
15 | someFunctionCall()
16 | case .b:
17 | anotherFunctionCall()
18 |
19 |
20 | }
21 | }
22 |
23 | func f2(_ anotherParameter: SomeParameterType){
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/adhoc_variable_inline/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "replace_expression_with_boolean_literal"
15 | to = ["variable_inline_cleanup"]
16 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "replace_expression_with_boolean_literal"
15 | to = ["variable_inline_cleanup"]
16 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/expected/test1.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | super.init(someParameter: someOtherVar)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/expected/test2.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | super.init(someParameter: someVar)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/expected/test3.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | super.init(someParameter: someOtherVar)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/expected/test4.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | super.init(someParameter: someFunctionCall(a: true))
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/expected/test5.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | super.init(someParameter: someFunctionCall(a: true))
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/input/test1.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | let a = !placeholder_true
19 | super.init(someParameter: a ? someVar : someOtherVar)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/input/test2.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | let a = placeholder_false
19 | super.init(someParameter: !a ? someVar : someOtherVar)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/input/test3.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | let a = placeholder_true
19 | super.init(someParameter: !a ? someVar : someOtherVar)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/input/test4.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | let a = !placeholder_false
19 | super.init(someParameter: someFunctionCall(a: a))
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/constructor_variable_inline/input/test5.swift:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 Uber Technologies, Inc.
2 |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | // except in compliance with the License. You may obtain a copy of the License at
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | // Unless required by applicable law or agreed to in writing, software distributed under the
8 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | // express or implied. See the License for the specific language governing permissions and
10 | // limitations under the License.
11 |
12 | // rule to test:
13 | // 1. edge from boolean_literal_cleanup to variable_inline_cleanup
14 | // 2. variable cleanup local to the init
15 |
16 | class C1 {
17 | init() {
18 | let a = !placeholder_false
19 | super.init(someParameter: someFunctionCall(a: a))
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/field_variable_inline/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "replace_expression_with_boolean_literal"
15 | to = ["variable_inline_cleanup"]
16 |
--------------------------------------------------------------------------------
/test-resources/swift/variable_inline/local_variable_inline/configurations/edges.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[edges]]
13 | scope = "Parent"
14 | from = "replace_expression_with_boolean_literal"
15 | to = ["variable_inline_cleanup"]
16 |
--------------------------------------------------------------------------------
/test-resources/thrift/match_exception_type/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | [[rules]]
2 | name = "Match Exception Definition"
3 | query = """(
4 | (exception_definition (identifier) @exception_name) @exception_definition
5 | (#match? @exception_name "Internal")
6 | )"""
7 | replace_node = "exception_definition"
8 | replace = """@exception_definition (
9 | rpc.code = "INTERNAL"
10 | )
11 | """
12 | [[rules.filters]]
13 | enclosing_node = "(exception_definition) @c_e"
14 | not_contains = ["(annotation_definition) @ad"]
15 |
--------------------------------------------------------------------------------
/test-resources/thrift/match_exception_type/expected/sample.thrift:
--------------------------------------------------------------------------------
1 | exception InternalServerError {
2 | 1: optional string message
3 | } (
4 | rpc.code = "INTERNAL"
5 | )
6 |
--------------------------------------------------------------------------------
/test-resources/thrift/match_exception_type/input/sample.thrift:
--------------------------------------------------------------------------------
1 | exception InternalServerError {
2 | 1: optional string message
3 | }
4 |
--------------------------------------------------------------------------------
/test-resources/tsx/structural_find/find_jsx_elements/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_jsx_elements"
14 | query = """
15 | (
16 | (jsx_element) @jsx_element
17 | )
18 | """
19 |
--------------------------------------------------------------------------------
/test-resources/tsx/structural_find/find_jsx_elements/input/sample.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | import React from 'react';
13 |
14 | type Props = {
15 | label: string;
16 | }
17 |
18 | const Component1 = (props: Props) => {
19 | return
26 | {props.label}
27 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_props_identifiers_within_b_jsx_elements"
14 | query = """
15 | (
16 | ((identifier) @identifier)
17 | (#eq? @identifier "props")
18 | )
19 | """
20 | [[rules.filters]]
21 | enclosing_node = """
22 | (
23 | (jsx_element
24 | open_tag: (jsx_opening_element
25 | name: (identifier) @name
26 | (#eq? @name "b")
27 | )
28 | ) @j
29 | )
30 | """
31 |
--------------------------------------------------------------------------------
/test-resources/tsx/structural_find/find_props_identifiers_within_b_jsx_elements/input/sample.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | import React from 'react';
13 |
14 | type Props = {
15 | label: string;
16 | }
17 |
18 | const Component1 = (props: Props) => {
19 | return
26 | {props.label}
27 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_props_identifiers_within_variable_declarators_not_within_divs"
14 | query = """
15 | (
16 | ((identifier) @identifier)
17 | (#eq? @identifier "props")
18 | )
19 | """
20 | [[rules.filters]]
21 | enclosing_node = """
22 | (
23 | (variable_declarator) @vd
24 | )
25 | """
26 | not_contains = ["""
27 | (
28 | (jsx_element
29 | open_tag: (jsx_opening_element
30 | name: (identifier) @name
31 | (#eq? @name "div")
32 | )
33 | ) @j
34 | )
35 | """]
36 |
--------------------------------------------------------------------------------
/test-resources/tsx/structural_find/find_props_identifiers_within_variable_declarators_not_within_divs/input/sample.tsx:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | import React from 'react';
13 |
14 | type Props = {
15 | label: string;
16 | }
17 |
18 | const Component1 = (props: Props) => {
19 | return
26 | {props.label}
27 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_fors"
14 | query = """
15 | (
16 | (for_statement) @for_stmt
17 | )
18 | """
19 |
--------------------------------------------------------------------------------
/test-resources/typescript/structural_find/find_fors/input/sample.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | for (let i = 0; i < 10; ++i) {
13 | console.log(i);
14 | }
15 |
16 | function f1() {
17 | for (let i = 0; i < 10; ++i) {
18 | console.log(i);
19 | }
20 | }
21 |
22 | function f2() {
23 | let i = 0;
24 |
25 | while(i < 10) {
26 | for (let j = 0; j < 10; ++j) {
27 | console.log(10*i + j);
28 | }
29 |
30 | ++i;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/test-resources/typescript/structural_find/find_fors_within_functions/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_fors_within_functions"
14 | query = """
15 | (
16 | (for_statement) @for_stmt
17 | )
18 | """
19 | [[rules.filters]]
20 | enclosing_node = "(function_declaration) @fs"
21 |
--------------------------------------------------------------------------------
/test-resources/typescript/structural_find/find_fors_within_functions/input/sample.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | for (let i = 0; i < 10; ++i) {
13 | console.log(i);
14 | }
15 |
16 | function f1() {
17 | for (let i = 0; i < 10; ++i) {
18 | console.log(i);
19 | }
20 | }
21 |
22 | function f2() {
23 | let i = 0;
24 |
25 | while(i < 10) {
26 | for (let j = 0; j < 10; ++j) {
27 | console.log(10*i + j);
28 | }
29 |
30 | ++i;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/test-resources/typescript/structural_find/find_fors_within_functions_not_within_whiles/configurations/rules.toml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2023 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | [[rules]]
13 | name = "find_fors_within_functions_not_within_whiles"
14 | query = """
15 | (
16 | (for_statement) @for_stmt
17 | )
18 | """
19 | [[rules.filters]]
20 | enclosing_node = "(function_declaration) @fs"
21 | not_contains = ["""
22 | (
23 | (while_statement) @while_stmt
24 | )
25 | """]
26 |
--------------------------------------------------------------------------------
/test-resources/typescript/structural_find/find_fors_within_functions_not_within_whiles/input/sample.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023 Uber Technologies, Inc.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | except in compliance with the License. You may obtain a copy of the License at
5 | http://www.apache.org/licenses/LICENSE-2.0
6 | Unless required by applicable law or agreed to in writing, software distributed under the
7 | License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 | express or implied. See the License for the specific language governing permissions and
9 | limitations under the License.
10 | */
11 |
12 | for (let i = 0; i < 10; ++i) {
13 | console.log(i);
14 | }
15 |
16 | function f1() {
17 | for (let i = 0; i < 10; ++i) {
18 | console.log(i);
19 | }
20 | }
21 |
22 | function f2() {
23 | let i = 0;
24 |
25 | while(i < 10) {
26 | for (let j = 0; j < 10; ++j) {
27 | console.log(10*i + j);
28 | }
29 |
30 | ++i;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/test-resources/utility_tests/sample.toml:
--------------------------------------------------------------------------------
1 | name = 'Piranha'
2 |
--------------------------------------------------------------------------------
/test-resources/yaml/find_replace/expected/sample.yaml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2024 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | config:
13 | hostname: "127.0.0.1"
14 | port: 8080
15 | username: "admin"
16 | password: "admin"
17 |
--------------------------------------------------------------------------------
/test-resources/yaml/find_replace/input/sample.yaml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2024 Uber Technologies, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4 | # except in compliance with the License. You may obtain a copy of the License at
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software distributed under the
8 | # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9 | # express or implied. See the License for the specific language governing permissions and
10 | # limitations under the License.
11 |
12 | config:
13 | hostname: "localhost"
14 | port: 8080
15 | username: "admin"
16 | password: "admin"
17 |
--------------------------------------------------------------------------------