-
Notifications
You must be signed in to change notification settings - Fork 424
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
Fix for legacy named arguments #692
Changes from 3 commits
b09bb31
b011aa3
1f84bcc
5f7867a
1eb4626
fe14be0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,7 +581,7 @@ java_test() | |
} | ||
|
||
func TestNativePyWarning(t *testing.T) { | ||
checkFindingsAndFix(t, "native-py", ` | ||
checkFindingsAndFix(t, "native-py", ` | ||
"""My file""" | ||
|
||
def macro(): | ||
|
@@ -604,14 +604,14 @@ def macro(): | |
|
||
py_test() | ||
`, tables.PyLoadPath), | ||
[]string{ | ||
fmt.Sprintf(`:4: Function "py_library" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:5: Function "py_binary" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:6: Function "py_test" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:7: Function "py_runtime" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:9: Function "py_test" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
}, | ||
scopeBzl|scopeBuild) | ||
[]string{ | ||
fmt.Sprintf(`:4: Function "py_library" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:5: Function "py_binary" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:6: Function "py_test" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:7: Function "py_runtime" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
fmt.Sprintf(`:9: Function "py_test" is not global anymore and needs to be loaded from "%s".`, tables.PyLoadPath), | ||
}, | ||
scopeBzl|scopeBuild) | ||
} | ||
|
||
func TestNativeProtoWarning(t *testing.T) { | ||
|
@@ -650,3 +650,67 @@ def macro(): | |
}, | ||
scopeBzl|scopeBuild) | ||
} | ||
|
||
func TestKeywordParameters(t *testing.T) { | ||
checkFindingsAndFix(t, "keyword-parameters", ` | ||
foo(key = value) | ||
all(elements = [True, False]) | ||
any(elements = [True, False]) | ||
tuple(x = [1, 2, 3]) | ||
list(x = [1, 2, 3]) | ||
len(x = [1, 2, 3]) | ||
str(x = foo) | ||
repr(x = foo) | ||
bool(x = 3) | ||
int(x = "3") | ||
int(x = "13", base = 8) | ||
dir(x = foo) | ||
type(x = foo) | ||
hasattr(x = foo, name = "bar") | ||
getattr(x = foo, name = "bar", default = "baz") | ||
select(x = {}) | ||
glob(["*.cc"], ["test*"]) | ||
native.glob(["*.cc"], ["test*"]) | ||
glob(["*.cc"]) | ||
native.glob(["*.cc"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
`, ` | ||
foo(key = value) | ||
all([True, False]) | ||
any([True, False]) | ||
tuple([1, 2, 3]) | ||
list([1, 2, 3]) | ||
len([1, 2, 3]) | ||
str(foo) | ||
repr(foo) | ||
bool(3) | ||
int("3") | ||
int("13", base = 8) | ||
dir(foo) | ||
type(foo) | ||
hasattr(foo, name = "bar") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
getattr(foo, name = "bar", default = "baz") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
select({}) | ||
glob(["*.cc"], exclude = ["test*"]) | ||
native.glob(["*.cc"], exclude = ["test*"]) | ||
glob(["*.cc"]) | ||
native.glob(["*.cc"]) | ||
`, []string{ | ||
`:2: Keyword parameter "elements" for "all" should be positional.`, | ||
`:3: Keyword parameter "elements" for "any" should be positional.`, | ||
`:4: Keyword parameter "x" for "tuple" should be positional.`, | ||
`:5: Keyword parameter "x" for "list" should be positional.`, | ||
`:6: Keyword parameter "x" for "len" should be positional.`, | ||
`:7: Keyword parameter "x" for "str" should be positional.`, | ||
`:8: Keyword parameter "x" for "repr" should be positional.`, | ||
`:9: Keyword parameter "x" for "bool" should be positional.`, | ||
`:10: Keyword parameter "x" for "int" should be positional.`, | ||
`:11: Keyword parameter "x" for "int" should be positional.`, | ||
`:12: Keyword parameter "x" for "dir" should be positional.`, | ||
`:13: Keyword parameter "x" for "type" should be positional.`, | ||
`:14: Keyword parameter "x" for "hasattr" should be positional.`, | ||
`:15: Keyword parameter "x" for "getattr" should be positional.`, | ||
`:16: Keyword parameter "x" for "select" should be positional.`, | ||
`:17: Parameter at the position 2 for "glob" should be keyword (exclude = ...).`, | ||
`:18: Parameter at the position 2 for "glob" should be keyword (exclude = ...).`, | ||
}, scopeEverywhere) | ||
} |
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.
How are you going to fix functions with more than 1 argument?
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.
I was going to implement it in portions, but perhaps I should support flexible amount of arguments now and just add functions/methods 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.
You'll have to change the data structure. The current code handles a specific case that never happens in real file (naming the
x
argument).You might as well remove the legacyNamed code and submit only legacyPositional, if you want to split in portions.
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.
Refactored to handle both legacy keyword and legacy positional parameters, even for the same function