|
52 | 52 | "string", |
53 | 53 | } |
54 | 54 | PROMISE_BLOCK_ATTRIBUTES = ("path", "interpreter") |
| 55 | + |
55 | 56 | IMPLIES_BUNDLE = {"usebundle", "servicebundle", "service_bundle"} |
| 57 | +IMPLIES_BODY = {"copy_from", "action"} |
| 58 | +# Generally, IMPLIES_BUNDLE and IMPLIES_BODY might not be necessary |
| 59 | +# in the future, when we're using syntax-description.json we will |
| 60 | +# know if we expect a bundle or body (based on both promise type and attribute name) |
| 61 | +# so "guessing" based on only attribute name can be dropped. |
| 62 | + |
56 | 63 | KNOWN_FAULTY_FUNCTION_DEFS = {"regex_replace", "peers"} |
57 | 64 | # Generally, we don't want to allow creating bodies / bundles with the same |
58 | 65 | # name as a built in function, as it can make things more confusing |
@@ -652,19 +659,18 @@ def _lint_node( |
652 | 659 | f"Error: Call to bundle '{name}' inside custom promise: '{state.promise_type}' {location}" |
653 | 660 | ) |
654 | 661 | return 1 |
655 | | - if state.strict and ( |
656 | | - qualified_name not in state.bundles |
657 | | - and ( |
658 | | - state.attribute_name in IMPLIES_BUNDLE |
659 | | - or qualified_name not in state.bodies |
660 | | - ) |
661 | | - and name not in syntax_data.BUILTIN_FUNCTIONS |
662 | | - ): |
663 | | - _highlight_range(node, lines) |
664 | | - print( |
665 | | - f"Error: Call to unknown function / bundle / body '{name}' {location}" |
| 662 | + if state.strict and name not in syntax_data.BUILTIN_FUNCTIONS: |
| 663 | + allowed_in_bundles = state.attribute_name not in IMPLIES_BODY |
| 664 | + allowed_in_bodies = state.attribute_name not in IMPLIES_BUNDLE |
| 665 | + found = (allowed_in_bundles and qualified_name in state.bundles) or ( |
| 666 | + allowed_in_bodies and qualified_name in state.bodies |
666 | 667 | ) |
667 | | - return 1 |
| 668 | + if not found: |
| 669 | + _highlight_range(node, lines) |
| 670 | + print( |
| 671 | + f"Error: Call to unknown function / bundle / body '{name}' {location}" |
| 672 | + ) |
| 673 | + return 1 |
668 | 674 | if ( |
669 | 675 | name not in syntax_data.BUILTIN_FUNCTIONS |
670 | 676 | and state.promise_type == "vars" |
@@ -757,7 +763,7 @@ def _lint_node( |
757 | 763 | return 1 |
758 | 764 |
|
759 | 765 | qualified_name = _qualify(call, state.namespace) |
760 | | - if qualified_name in state.bundles: |
| 766 | + if qualified_name in state.bundles and state.attribute_name not in IMPLIES_BODY: |
761 | 767 | definitions = state.bundles[qualified_name] |
762 | 768 | valid_counts = {len(d.get("parameters", [])) for d in definitions} |
763 | 769 | if len(args) not in valid_counts: |
|
0 commit comments