MCPcopy Index your code
hub / github.com/nodejs/node / is_valid

Function is_valid

tools/checkimports.py:18–39  ·  view source on GitHub ↗
(file_name)

Source from the content-addressed store, hash-verified

16
17
18def is_valid(file_name):
19 with io.open(file_name, encoding='utf-8') as source_file:
20 lines = [line.strip() for line in source_file]
21
22 usings, importeds, line_numbers, valid = [], [], [], True
23 for idx, line in enumerate(lines, 1):
24 matches = re.search(r'^using (\w+::(\w+));$', line)
25 if matches:
26 line_numbers.append(idx)
27 usings.append(matches.group(1))
28 importeds.append(matches.group(2))
29
30 valid = all(do_exist(file_name, lines, imported) for imported in importeds)
31
32 sorted_usings = sorted(usings, key=lambda x: x.lower())
33 if sorted_usings != usings:
34 print(f"using statements aren't sorted in '{file_name}'.")
35 for num, actual, expected in zip(line_numbers, usings, sorted_usings):
36 if actual != expected:
37 print(f'\tLine {num}: Actual: {actual}, Expected: {expected}')
38 return False
39 return valid
40
41if __name__ == '__main__':
42 if len(sys.argv) > 1:

Callers 5

test_unused_complexMethod · 0.90
test_unused_simpleMethod · 0.90
test_unsortedMethod · 0.90
test_validMethod · 0.90

Calls 8

do_existFunction · 0.85
sortedFunction · 0.85
zipFunction · 0.85
openMethod · 0.65
enumerateFunction · 0.50
printFunction · 0.50
searchMethod · 0.45
appendMethod · 0.45

Tested by 5

test_unused_complexMethod · 0.72
test_unused_simpleMethod · 0.72
test_unsortedMethod · 0.72
test_validMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…