-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swift: Fix local variable declaration inside constructor (#620)
- Loading branch information
Showing
20 changed files
with
325 additions
and
88 deletions.
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
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
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
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
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
15 changes: 15 additions & 0 deletions
15
test-resources/swift/variable_inline/constructor_variable_inline/configurations/edges.toml
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,15 @@ | ||
# Copyright (c) 2023 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. | ||
|
||
[[edges]] | ||
scope = "Parent" | ||
from = "replace_expression_with_boolean_literal" | ||
to = ["variable_inline_cleanup"] |
40 changes: 40 additions & 0 deletions
40
test-resources/swift/variable_inline/constructor_variable_inline/configurations/rules.toml
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,40 @@ | ||
# Copyright (c) 2023 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. | ||
|
||
# Before | ||
# placeholder_false | ||
# After | ||
# false | ||
# | ||
[[rules]] | ||
name = "test_rule_replace_false_placeholder" | ||
query = """( | ||
(simple_identifier) @variable | ||
(#eq? @variable "placeholder_false") | ||
)""" | ||
replace_node = "variable" | ||
replace = "false" | ||
groups = ["replace_expression_with_boolean_literal"] | ||
|
||
# Before | ||
# placeholder_false | ||
# After | ||
# false | ||
# | ||
[[rules]] | ||
name = "test_rule_replace_true_placeholder" | ||
query = """( | ||
(simple_identifier) @variable | ||
(#eq? @variable "placeholder_true") | ||
)""" | ||
replace_node = "variable" | ||
replace = "true" | ||
groups = ["replace_expression_with_boolean_literal"] |
20 changes: 20 additions & 0 deletions
20
test-resources/swift/variable_inline/constructor_variable_inline/expected/test1.swift
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,20 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
super.init(someParameter: someOtherVar) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test-resources/swift/variable_inline/constructor_variable_inline/expected/test2.swift
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,20 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
super.init(someParameter: someVar) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test-resources/swift/variable_inline/constructor_variable_inline/expected/test3.swift
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,20 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
super.init(someParameter: someOtherVar) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test-resources/swift/variable_inline/constructor_variable_inline/expected/test4.swift
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,20 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
super.init(someParameter: someFunctionCall(a: true)) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test-resources/swift/variable_inline/constructor_variable_inline/expected/test5.swift
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,20 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
super.init(someParameter: someFunctionCall(a: true)) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test-resources/swift/variable_inline/constructor_variable_inline/input/test1.swift
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,21 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
let a = !placeholder_true | ||
super.init(someParameter: a ? someVar : someOtherVar) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test-resources/swift/variable_inline/constructor_variable_inline/input/test2.swift
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,21 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
let a = placeholder_false | ||
super.init(someParameter: !a ? someVar : someOtherVar) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test-resources/swift/variable_inline/constructor_variable_inline/input/test3.swift
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,21 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
let a = placeholder_true | ||
super.init(someParameter: !a ? someVar : someOtherVar) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test-resources/swift/variable_inline/constructor_variable_inline/input/test4.swift
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,21 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
// rule to test: | ||
// 1. edge from boolean_literal_cleanup to variable_inline_cleanup | ||
// 2. variable cleanup local to the init | ||
|
||
class C1 { | ||
init() { | ||
let a = !placeholder_false | ||
super.init(someParameter: someFunctionCall(a: a)) | ||
} | ||
} |
Oops, something went wrong.