Skip to content

Commit

Permalink
Go Cleanup Built-in Rules (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvmarcilio authored Dec 19, 2022
1 parent 1feef9e commit e2c9338
Show file tree
Hide file tree
Showing 21 changed files with 1,848 additions and 75 deletions.
4 changes: 2 additions & 2 deletions polyglot/piranha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ tree-sitter-java = { git = "https://github.com/tree-sitter/tree-sitter-java.git"
tree-sitter-swift = { git = "https://github.com/ketkarameya/tree-sitter-swift.git", branch = "add_parser" }
tree-sitter-strings = { git = "https://github.com/ketkarameya/tree-sitter-strings.git" }
tree-sitter-python = { git = "https://github.com/tree-sitter/tree-sitter-python.git" }
tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go.git" }
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript.git" }
# TODO: tree-sitter-go should be changed either to upstream or Uber main branch
tree-sitter-go = { git = "https://github.com/uber/tree-sitter-go.git", branch = "expose_statement_list" }
derive_builder = "0.11.2"
getset = "0.1.2"
pyo3 = "0.17.1"
Expand All @@ -54,4 +55,3 @@ pyo3-log = "0.7.0"
[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

128 changes: 64 additions & 64 deletions polyglot/piranha/README.md

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions polyglot/piranha/images/go_builtin_rules.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions polyglot/piranha/src/cleanup_rules/go/edges.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2022 Uber Technologies, Inc.
#
# <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the License at
# <p>http://www.apache.org/licenses/LICENSE-2.0
#
# <p>Unless required by applicable law or agreed to in writing, software distributed under the
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing permissions and
# limitations under the License.

# The language specific rules in this file are applied after the API specific change has been performed.

# The edges in this file specify the flow between the rules.

[[edges]]
scope = "Parent"
from = "replace_expression_with_boolean_literal"
to = [
"boolean_literal_cleanup",
"statement_cleanup",
]

### boolean_literal_cleanup
[[edges]]
scope = "Parent"
from = "boolean_literal_cleanup"
to = [
"boolean_expression_simplify",
"statement_cleanup",
]

[[edges]]
scope = "Parent"
from = "boolean_expression_simplify"
to = ["boolean_literal_cleanup"]

[[edges]]
scope = "Parent"
from = "statement_cleanup"
to = ["if_cleanup"]

### statement_cleanup
[[edges]]
scope = "Function-Method"
from = "statement_cleanup"
to = ["delete_variable_declaration"]

[[edges]]
scope = "Function-Method"
from = "delete_variable_declaration"
to = ["replace_identifier_with_value"]

[[edges]]
scope = "Parent"
from = "replace_identifier_with_value"
to = ["boolean_literal_cleanup"]


### if_cleanup
[[edges]]
scope = "Parent"
from = "if_cleanup"
to = ["remove_unnecessary_nested_block"]

[[edges]]
scope = "Parent"
from = "remove_unnecessary_nested_block"
to = ["return_statement_cleanup"]

# Cycle to circumvent `delete_statement_after_return` only removing one match at a time
[[edges]]
scope = "Parent"
from = "return_statement_cleanup"
to = ["delete_statement_after_return"]

[[edges]]
scope = "Parent"
from = "delete_statement_after_return"
to = ["return_statement_cleanup"]
Loading

0 comments on commit e2c9338

Please sign in to comment.