-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go Cleanup Built-in Rules #265
Merged
+1,848
−75
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
872687c
Pointing to modified Go grammar for now
dvmarcilio fb8e013
Go: Initial boolean_expression_simplify rules
dvmarcilio bf726c1
Unary_expression has "hidden" field `operator`
dvmarcilio 3833c4e
Go: simplify {true|false}_and_something...
dvmarcilio 769ba90
Go: simplify {true|false} or something...
dvmarcilio fee496d
Go: converging to a standard rule formatting
dvmarcilio 8acc48d
Go: if_cleanup && remove_unneccessary_nested_block
dvmarcilio 215f11d
Go: TODO comment to address if w/ short stmt
dvmarcilio 3e4e10f
Go: temp start for delete_short_v_decl
dvmarcilio b2b0674
'delete_immediate_if_err' working. clean rules/edges/scope later
dvmarcilio f4d9bac
replace_double_short_var_decl working!
dvmarcilio 51500e1
delete_variable_declaration
dvmarcilio eb85d56
One intra cleanup scenario working!
dvmarcilio 6cb92ed
Merging two rules into one
dvmarcilio a9530c5
Fix hole; Scope Function -> Function-Method
dvmarcilio 8e85e59
Adding graph for current built-in rules
dvmarcilio e086048
Go: constant same file
dvmarcilio 6875fbb
delete_bool_blank_identifier_short_var_declaration
dvmarcilio dbc86f7
Go: Removing unused param used in call
dvmarcilio 93d0bf2
Go: delete_all_statements_after_return
dvmarcilio 02200fa
Simplifying identity equality and inequality for {true|false|nil}
dvmarcilio 9c89491
Go: Cleanup rules work for single short var decl
dvmarcilio a0435b5
delete_variable_declaration needs a constraint!
dvmarcilio c5de253
replace_identifier_with_value needs a constraint
dvmarcilio d4249aa
More meaningful names for identity rules
dvmarcilio e7276bc
Moving Go tests
dvmarcilio fcf2633
Go `delete_statement_after_return` self-edge
dvmarcilio de9ad4c
Removing outdated image
dvmarcilio 0cefd06
--ignore-parser-error option. (rebased so this commit is very weird)
dvmarcilio ec97026
Reverting ignore_parse_error arg (rebased; commit is weird)
dvmarcilio 5ccc4b1
Initial cleanup of go rules
dvmarcilio a6255e2
Go simplify_identity: wildcard for lhs and rhs
dvmarcilio d049ed8
Go: test for simplify if false with no alternative
dvmarcilio 8a24525
Removing `.`s from delete_parent_assignment
dvmarcilio fcb1c48
`*` and `+` rules with `\n` terminator
dvmarcilio 9439bca
Go grammar: branch on Uber tree-sitter-go repo
dvmarcilio 533a1be
`return_cleanup` <-> `delete_stmt_after_return`
dvmarcilio 8dba1a2
Go: removing `*` from `lhs|rhs` captures
dvmarcilio e2c14ec
constraint for `replace_identifier_with_value`
dvmarcilio 7dbde04
`simplify_something_or_true` excluding calls
dvmarcilio 2fbd662
`simplify_something_and_false` excluding calls
dvmarcilio 5224867
Removing 'delete_parent_assignment' !
dvmarcilio 189990c
Adding Go in PiranhaLanguage
dvmarcilio 171d4dc
dummy 'return_cleanup' -> 'return_statement_cleanup
dvmarcilio 7759e90
Simplifying rules for test "const_same_file"
dvmarcilio fb72b1f
`const_same_file` tests following conventions
dvmarcilio 9e8faf3
Removing empty edges.toml
dvmarcilio 67b509a
test_piranha_go: Adding needed import
dvmarcilio 1f93f33
Using treated/treated_complement as arguments in test
dvmarcilio 8cbbe3c
Fix .toml formatting
dvmarcilio 0a1d8da
cleaning `remove_unnecessary_nested_block`
dvmarcilio bea7f6f
Cleaning `delete_statement_after_return`
dvmarcilio 4ce2547
add missing license
dvmarcilio 2b584aa
README: checkmarks for Go
dvmarcilio c8f9942
TODO on Cargo.toml to change tree-sitter-go dependency
dvmarcilio f0b1f55
Merge branch 'master' into go_develop
dvmarcilio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on our discussion, we don't need this grammar change right? Maybe we can point to main tree-sitter-go then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the change to match all the contents of a block—without braces
{
}
—in a single pass.In principle, we could use
(_)*
; but then we run into the problem of multiple single-line matches (similar to #284).For a rule such as
remove_unnecessary_nested_block
,replace
would consider only the first match.