-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.py
executable file
·140 lines (129 loc) · 3.61 KB
/
check.py
1
2
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python3
import fileinput
import re
SAME_IN_LODASH_AND_UNDERSCORE = [
'_.bind',
'_.clone',
'_.compact',
'_.constant',
'_.defaults',
'_.difference',
'_.escape',
'_.has',
'_.includes',
'_.intersection',
'_.isArray',
'_.isBoolean',
'_.isDate',
'_.isElement',
'_.isEmpty',
'_.isEqual',
'_.isFunction',
'_.isNaN',
'_.isNull',
'_.isNumber',
'_.isObject',
'_.isString',
'_.isUndefined',
'_.keys',
'_.memoize',
'_.mixin',
'_.negate',
'_.noop',
'_.now',
'_.partial',
'_.property',
'_.range',
'_.result',
'_.size',
'_.toArray',
'_.unescape',
'_.union',
'_.uniqueId',
'_.values',
'_.without',
]
CONVERTED_FROM_UNDERSCORE = {
'_.all': ['_.every', '_.every(_.bind)'],
'_.any': ['_.some', '_.some(_.bind)'],
'_.contains': ['_.includes'],
'_.debounce': ['_.debounce'],
'_.detect': ['_.find', '_.find(_.bind)'],
'_.each': ['_.forEach', '_.forEach(_.bind)'],
'_.every': ['_.every(_.bind)'],
'_.extend': ['_.assignIn'],
'_.filter': ['_.filter', '_.filter(_.bind)'],
'_.find': ['_.find', '_.find(_.bind)'],
'_.findWhere': ['_.find'],
'_.first': ['_.head', '_.take'],
'_.flatten': ['_.flatten', '_.flattenDeep'],
'_.forEach': ['_.forEach(_.bind)'],
'_.get': ['_.get'],
'_.groupBy': ['_.groupBy(_.bind)'],
'_.include': ['_.includes'],
'_.indexBy': ['_.keyBy', '_.keyBy(_.bind)'],
'_.indexOf': ['_.indexOf', '_.sortedIndexOf'],
'_.initial': ['_.dropRight', '_.initial'],
'_.invoke': ['_.invokeMap'],
'_.last': ['_.last', '_.takeRight'],
'_.map': ['_.map', '_.map(_.bind)'],
'_.mapObject': ['_.mapValues', '_.mapValues(_.bind)'],
'_.max': ['_.maxBy', '_.maxBy(_.bind)'],
'_.min': ['_.minBy', '_.minBy(_.bind)'],
'_.object': ['_.zipObject'],
'_.omit': ['_.omit', '_.omitBy'],
'_.pairs': ['_.toPairs'],
'_.pick': ['_.pick', '_.pickBy'],
'_.pluck': ['_.map'],
'_.reduce': ['_.reduce', '_.reduce(_.bind)'],
'_.reject': ['_.reject', '_.reject(_.bind)'],
'_.require': ['_.require'],
'_.rest': ['_.drop'],
'_.some': ['_.some', '_.some(_.bind)'],
'_.sortBy': ['_.sortBy(_.bind)'],
'_.times': ['_.times', '_.times(_.bind)'],
'_.uniq': ['_.sortedUniq', '_.sortedUniqBy', '_.uniqBy'],
'_.unique': ['_.sortedUniq', '_.sortedUniqBy', '_.uniqBy'],
'_.where': ['_.filter'],
}
UNDERSCORE = CONVERTED_FROM_UNDERSCORE.keys()
CONVERTED_FROM_SIERRA = {
'_.deep': ['_.get', '_.set'],
}
# Lodash functions used
LODASH = sum(CONVERTED_FROM_UNDERSCORE.values(), [])
LODASH += sum(CONVERTED_FROM_SIERRA.values(), [])
LODASH = sorted(LODASH)
#
# Process standard input
#
functions = {}
ansi_escape = re.compile(r'\x1b[^m]*m\n*')
processed_term = []
for term in fileinput.input():
# Pass when work is already done
if term in processed_term:
continue
else:
processed_term += term
# Trim standard input from color codes
plain_term = ansi_escape.sub('', term)
# Check function's conversion status
conversions = CONVERTED_FROM_UNDERSCORE.get(plain_term)
availableInUnderscore = plain_term in UNDERSCORE
checks = {
'conversions': conversions,
'loash': plain_term in LODASH,
'needs conversion': availableInUnderscore and conversions is None,
'sierra': CONVERTED_FROM_SIERRA.get(plain_term),
'transparent': plain_term in SAME_IN_LODASH_AND_UNDERSCORE,
'underscore': availableInUnderscore
}
# Trim the useless
checks = {k: v for k, v in checks.items() if v not in [None, False]}
functions[plain_term] = checks
for functionName in sorted(functions.keys()):
print(functionName)
function = functions.get(functionName)
for prop in sorted(function.keys()):
print('\t{}: {}'.format(prop, function.get(prop)))