Page MenuHomec4science

arclint.py
No OneTemporary

File Metadata

Created
Mon, Nov 18, 18:29

arclint.py

import json
from .results import Results
from . import export
@export
class ARCLintJson:
STATUS = {'passed': Results.PASS,
'failed': Results.FAIL}
def __init__(self, filename):
self._file = open(filename, "r")
self._json = json.load(self._file)
def __iter__(self):
self._last_path_lints = []
self._lints = iter(self._json)
return self
def __next__(self):
class Lint:
def __init__(self, path, json):
self.json = json
self.json['path'] = path
if 'name' in json and 'code' in json and \
json['name'] == json['code']:
self.json['name'] = json['description']
del self.json['description']
def __getattr__(self, name):
if name == 'json':
return self.json
elif name in self.json:
return self.json[name]
else:
return None
def __str__(self):
return f'{self.path} => {self.name}'
lint = None
while not lint:
if len(self._last_path_lints) > 0:
lint = Lint(self._last_path,
self._last_path_lints.pop(0))
break
json = next(self._lints)
if type(json) != dict:
raise RuntimeError("Wrong input type for the linter processor")
self._last_path = list(json.keys())[0]
self._last_path_lints = json[self._last_path]
return lint
def __exit__(self, exc_type, exc_value, traceback):
self._file.close()
def __enter__(self):
return self

Event Timeline