Skip to content

Commit

Permalink
Added two flags to check or not useless value assignments and unmappe…
Browse files Browse the repository at this point in the history
…d sustitution mapping requirements
  • Loading branch information
philippemerle committed Mar 4, 2022
1 parent c1f82b7 commit 9b63c52
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions bin/cloudnet/tosca/type_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
"deploy": {},
"undeploy": {},
},

"check-useless-value-assigments": True,
"check-unmapped-substitution-mappings-requirements": True,
"warning-on-definitions-allowing-negative-values": True,
}

Expand Down Expand Up @@ -4675,16 +4678,22 @@ def check_value_assignment(self, name, value, definition, context_error_message)
return

self.check_value(value, definition, {}, context_error_message)
if 'default' in definition:
default = definition.get(syntax.DEFAULT)
if value == default:
self.warning(
context_error_message
+ ': '
+ str(value)
+ ' - useless assignment as the value equals to the defined default value',
name,
)

# Check useless assignents
if self.configuration.get(
TYPE_SYSTEM,
"check-useless-value-assigments"
):
if 'default' in definition:
default = definition.get(syntax.DEFAULT)
if value == default:
self.warning(
context_error_message
+ ': '
+ str(value)
+ ' - useless assignment as the value equals to the defined default value',
name,
)

def check_property_assignment(
self,
Expand Down Expand Up @@ -6412,12 +6421,17 @@ def check_ummapped_requirement_definition(
# produce an error for each other unmapped requirement
return self.error, "occurrences: " + str(occurrences)

check_unmapped_definitions(
node_type,
syntax.REQUIREMENTS,
"requirement",
check_ummapped_requirement_definition,
)
if self.configuration.get(
TYPE_SYSTEM,
"check-unmapped-substitution-mappings-requirements"
):
check_unmapped_definitions(
node_type,
syntax.REQUIREMENTS,
"requirement",
check_ummapped_requirement_definition,
)

# check interfaces - TODO
self.iterate_over_map_of_assignments(
None,
Expand Down

0 comments on commit 9b63c52

Please sign in to comment.