Update naming convention to new json format

pull/106/head
Josselin 6 years ago
parent fd60773027
commit b906965dcc
  1. 116
      slither/detectors/naming_convention/naming_convention.py
  2. 2
      tests/expected_json/naming_convention.naming-convention.json

@ -52,11 +52,12 @@ class NamingConvention(AbstractDetector):
contract.source_mapping_str) contract.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'contract', json['type'] = 'contract'
'convention':'CapWords', json['convention'] = 'CapWords'
'name':{'name': contract.name, json['name'] = {'name': contract.name,
'source_mapping': contract.source_mapping}}) 'source_mapping': contract.source_mapping}
results.append(json)
for struct in contract.structures: for struct in contract.structures:
if struct.contract != contract: if struct.contract != contract:
@ -67,13 +68,12 @@ class NamingConvention(AbstractDetector):
info = info.format(struct.contract.name, struct.name, struct.source_mapping_str) info = info.format(struct.contract.name, struct.name, struct.source_mapping_str)
all_info += info all_info += info
json = self.generate_json_result(info)
results.append({'check': self.ARGUMENT, json['type'] = 'structure'
'type': 'structure', json['convention'] = 'CapWords'
'convention':'CapWords', json['name'] = {'name': struct.name,
'name':{'name': struct.name, 'source_mapping': struct.source_mapping}
'source_mapping': struct.source_mapping}}) results.append(json)
for event in contract.events: for event in contract.events:
if event.contract != contract: if event.contract != contract:
continue continue
@ -83,12 +83,12 @@ class NamingConvention(AbstractDetector):
info = info.format(event.contract.name, event.name, event.source_mapping_str) info = info.format(event.contract.name, event.name, event.source_mapping_str)
all_info += info all_info += info
json = self.generate_json_result(info)
results.append({'check': self.ARGUMENT, json['type'] = 'event'
'type': 'event', json['convention'] = 'CapWords'
'convention':'CapWords', json['name'] = {'name': event.name,
'name':{'name': event.name, 'source_mapping': event.source_mapping}
'source_mapping': event.source_mapping}}) results.append(json)
for func in contract.functions: for func in contract.functions:
if func.contract != contract: if func.contract != contract:
@ -99,11 +99,12 @@ class NamingConvention(AbstractDetector):
info = info.format(func.contract.name, func.name, func.source_mapping_str) info = info.format(func.contract.name, func.name, func.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'function', json['type'] = 'function'
'convention':'mixedCase', json['convention'] = 'mixedCase'
'name':{'name': func.name, json['name'] = {'name': func.name,
'source_mapping': func.source_mapping}}) 'source_mapping': func.source_mapping}
results.append(json)
for argument in func.parameters: for argument in func.parameters:
if argument in func.variables_read_or_written: if argument in func.variables_read_or_written:
@ -118,11 +119,12 @@ class NamingConvention(AbstractDetector):
argument.source_mapping_str) argument.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'parameter', json['type'] = 'parameter'
'convention':'mixedCase', json['convention'] = 'mixedCase'
'name':{'name': argument.name, json['name'] = {'name': argument.name,
'source_mapping': argument.source_mapping}}) 'source_mapping': argument.source_mapping}
results.append(json)
for var in contract.state_variables: for var in contract.state_variables:
if var.contract != contract: if var.contract != contract:
@ -134,11 +136,12 @@ class NamingConvention(AbstractDetector):
info = info.format(var.contract.name, var.name, var.source_mapping_str) info = info.format(var.contract.name, var.name, var.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'variable', json['type'] = 'variable'
'convention':'l_O_I_should_not_be_used', json['convention'] = 'l_O_I_should_not_be_used'
'name':{'name': var.name, json['name'] = {'name': var.name,
'source_mapping': var.source_mapping}}) 'source_mapping': var.source_mapping}
results.append(json)
if var.is_constant is True: if var.is_constant is True:
# For ERC20 compatibility # For ERC20 compatibility
@ -150,11 +153,13 @@ class NamingConvention(AbstractDetector):
info = info.format(var.contract.name, var.name, var.source_mapping_str) info = info.format(var.contract.name, var.name, var.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'variable_constant', json['type'] = 'variable_constant'
'convention':'UPPER_CASE_WITH_UNDERSCORES', json['convention'] = 'UPPER_CASE_WITH_UNDERSCORES'
'name':{'name': var.name, json['name'] = {'name': var.name,
'source_mapping': var.source_mapping}}) 'source_mapping': var.source_mapping}
results.append(json)
else: else:
if var.visibility == 'private': if var.visibility == 'private':
correct_naming = self.is_mixed_case_with_underscore(var.name) correct_naming = self.is_mixed_case_with_underscore(var.name)
@ -165,11 +170,12 @@ class NamingConvention(AbstractDetector):
info = info.format(var.contract.name, var.name, var.source_mapping_str) info = info.format(var.contract.name, var.name, var.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'variable', json['type'] = 'variable'
'convention':'mixedCase', json['convention'] = 'mixedCase'
'name':{'name': var.name, json['name'] = {'name': var.name,
'source_mapping': var.source_mapping}}) 'source_mapping': var.source_mapping}
results.append(json)
for enum in contract.enums: for enum in contract.enums:
if enum.contract != contract: if enum.contract != contract:
@ -180,11 +186,13 @@ class NamingConvention(AbstractDetector):
info = info.format(enum.contract.name, enum.name, enum.source_mapping_str) info = info.format(enum.contract.name, enum.name, enum.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'enum', json['type'] = 'enum'
'convention':'CapWords', json['convention'] = 'CapWords'
'name':{'name': enum.name, json['name'] = {'name': enum.name,
'source_mapping': enum.source_mapping}}) 'source_mapping': enum.source_mapping}
results.append(json)
for modifier in contract.modifiers: for modifier in contract.modifiers:
if modifier.contract != contract: if modifier.contract != contract:
@ -197,11 +205,13 @@ class NamingConvention(AbstractDetector):
modifier.source_mapping_str) modifier.source_mapping_str)
all_info += info all_info += info
results.append({'check': self.ARGUMENT, json = self.generate_json_result(info)
'type': 'modifier', json['type'] = 'modifier'
'convention':'mixedCase', json['convention'] = 'mixedCase'
'name':{'name': modifier.name, json['name'] = {'name': modifier.name,
'source_mapping': modifier.source_mapping}}) 'source_mapping': modifier.source_mapping}
results.append(json)
if all_info != '': if all_info != '':
self.log(all_info) self.log(all_info)

@ -1 +1 @@
[{"check": "naming-convention", "type": "contract", "convention": "CapWords", "name": {"name": "naming", "source_mapping": {"start": 26, "length": 598, "filename": "tests/naming_convention.sol", "lines": [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]}}}, {"check": "naming-convention", "type": "structure", "convention": "CapWords", "name": {"name": "test", "source_mapping": {"start": 227, "length": 20, "filename": "tests/naming_convention.sol", "lines": [14, 15, 16]}}}, {"check": "naming-convention", "type": "event", "convention": "CapWords", "name": {"name": "event_", "source_mapping": {"start": 303, "length": 19, "filename": "tests/naming_convention.sol", "lines": [23]}}}, {"check": "naming-convention", "type": "function", "convention": "mixedCase", "name": {"name": "GetOne", "source_mapping": {"start": 405, "length": 71, "filename": "tests/naming_convention.sol", "lines": [30, 31, 32, 33]}}}, {"check": "naming-convention", "type": "parameter", "convention": "mixedCase", "name": {"name": "Number2", "source_mapping": {"start": 512, "length": 12, "filename": "tests/naming_convention.sol", "lines": [35]}}}, {"check": "naming-convention", "type": "variable_constant", "convention": "UPPER_CASE_WITH_UNDERSCORES", "name": {"name": "MY_other_CONSTANT", "source_mapping": {"start": 141, "length": 35, "filename": "tests/naming_convention.sol", "lines": [9]}}}, {"check": "naming-convention", "type": "variable", "convention": "mixedCase", "name": {"name": "Var_One", "source_mapping": {"start": 183, "length": 16, "filename": "tests/naming_convention.sol", "lines": [11]}}}, {"check": "naming-convention", "type": "enum", "convention": "CapWords", "name": {"name": "numbers", "source_mapping": {"start": 77, "length": 23, "filename": "tests/naming_convention.sol", "lines": [6]}}}, {"check": "naming-convention", "type": "modifier", "convention": "mixedCase", "name": {"name": "CantDo", "source_mapping": {"start": 545, "length": 36, "filename": "tests/naming_convention.sol", "lines": [41, 42, 43]}}}, {"check": "naming-convention", "type": "parameter", "convention": "mixedCase", "name": {"name": "_used", "source_mapping": {"start": 748, "length": 10, "filename": "tests/naming_convention.sol", "lines": [59]}}}, {"check": "naming-convention", "type": "variable", "convention": "mixedCase", "name": {"name": "_myPublicVar", "source_mapping": {"start": 695, "length": 17, "filename": "tests/naming_convention.sol", "lines": [56]}}}, {"check": "naming-convention", "type": "variable", "convention": "l_O_I_should_not_be_used", "name": {"name": "l", "source_mapping": {"start": 847, "length": 10, "filename": "tests/naming_convention.sol", "lines": [67]}}}] [{"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Contract 'naming' (tests/naming_convention.sol#3-48) is not in CapWords\n", "type": "contract", "convention": "CapWords", "name": {"name": "naming", "source_mapping": {"start": 26, "length": 598, "filename": "tests/naming_convention.sol", "lines": [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Struct 'naming.test' (tests/naming_convention.sol#14-16) is not in CapWords\n", "type": "structure", "convention": "CapWords", "name": {"name": "test", "source_mapping": {"start": 227, "length": 20, "filename": "tests/naming_convention.sol", "lines": [14, 15, 16]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Event 'naming.event_' (tests/naming_convention.sol#23) is not in CapWords\n", "type": "event", "convention": "CapWords", "name": {"name": "event_", "source_mapping": {"start": 303, "length": 19, "filename": "tests/naming_convention.sol", "lines": [23]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Function 'naming.GetOne' (tests/naming_convention.sol#30-33) is not in mixedCase\n", "type": "function", "convention": "mixedCase", "name": {"name": "GetOne", "source_mapping": {"start": 405, "length": 71, "filename": "tests/naming_convention.sol", "lines": [30, 31, 32, 33]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Parameter 'Number2' of naming.setInt (tests/naming_convention.sol#35) is not in mixedCase\n", "type": "parameter", "convention": "mixedCase", "name": {"name": "Number2", "source_mapping": {"start": 512, "length": 12, "filename": "tests/naming_convention.sol", "lines": [35]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Constant 'naming.MY_other_CONSTANT' (tests/naming_convention.sol#9) is not in UPPER_CASE_WITH_UNDERSCORES\n", "type": "variable_constant", "convention": "UPPER_CASE_WITH_UNDERSCORES", "name": {"name": "MY_other_CONSTANT", "source_mapping": {"start": 141, "length": 35, "filename": "tests/naming_convention.sol", "lines": [9]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Variable 'naming.Var_One' (tests/naming_convention.sol#11) is not in mixedCase\n", "type": "variable", "convention": "mixedCase", "name": {"name": "Var_One", "source_mapping": {"start": 183, "length": 16, "filename": "tests/naming_convention.sol", "lines": [11]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Enum 'naming.numbers' (tests/naming_convention.sol#6) is not in CapWords\n", "type": "enum", "convention": "CapWords", "name": {"name": "numbers", "source_mapping": {"start": 77, "length": 23, "filename": "tests/naming_convention.sol", "lines": [6]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Modifier 'naming.CantDo' (tests/naming_convention.sol#41-43) is not in mixedCase\n", "type": "modifier", "convention": "mixedCase", "name": {"name": "CantDo", "source_mapping": {"start": 545, "length": 36, "filename": "tests/naming_convention.sol", "lines": [41, 42, 43]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Parameter '_used' of T.test (tests/naming_convention.sol#59) is not in mixedCase\n", "type": "parameter", "convention": "mixedCase", "name": {"name": "_used", "source_mapping": {"start": 748, "length": 10, "filename": "tests/naming_convention.sol", "lines": [59]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Variable 'T._myPublicVar' (tests/naming_convention.sol#56) is not in mixedCase\n", "type": "variable", "convention": "mixedCase", "name": {"name": "_myPublicVar", "source_mapping": {"start": 695, "length": 17, "filename": "tests/naming_convention.sol", "lines": [56]}}}, {"check": "naming-convention", "impact": "Informational", "confidence": "High", "description": "Variable 'T.l' (tests/naming_convention.sol#67) used l, O, I, which should not be used\n", "type": "variable", "convention": "l_O_I_should_not_be_used", "name": {"name": "l", "source_mapping": {"start": 847, "length": 10, "filename": "tests/naming_convention.sol", "lines": [67]}}}]
Loading…
Cancel
Save