Skip to content

Commit f43ca31

Browse files
committed
Add new misc. generated code clues
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 97f872e commit f43ca31

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/summarycode/generated.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from itertools import islice
1111

12-
1312
from commoncode.datautils import Boolean
1413
from commoncode.text import toascii
1514
from plugincode.scan import ScanPlugin
@@ -19,7 +18,7 @@
1918
import typecode.contenttype
2019

2120
"""
22-
Tag files as generated.
21+
Tag files as generated code based on conspicuous strings.
2322
"""
2423

2524
# Tracing flag
@@ -77,7 +76,7 @@ def generated_scanner(location, **kwargs):
7776
return dict(is_generated=is_generated)
7877

7978

80-
GENERATED_KEYWORDS = tuple(g.lower() for g in (
79+
GENERATED_KEYWORDS_LOWERED = tuple(g.lower() for g in (
8180
'generated by',
8281
'auto-generated',
8382
'automatically generated',
@@ -160,7 +159,7 @@ def generated_scanner(location, **kwargs):
160159
'this is an autogenerated file. do not edit this file directly.',
161160
'this file has been automatically created by',
162161
'please do not edit this file, all changes will be lost',
163-
162+
164163
# thrift
165164
'this is an automatically-generated file.',
166165
'it could get re-generated if the allow_idl_generation flag is on',
@@ -172,22 +171,24 @@ def generated_scanner(location, **kwargs):
172171

173172
# seen in Go files:
174173
'code generated file. do not edit',
174+
'code generated by running "go generate". do not edit.'
175175

176176
# protoc
177-
'generated by the protocol buffer compiler. do not edit!',
178-
177+
'generated by the protocol buffer compiler. do not edit!',
178+
'generated by the protocol buffer compiler.',
179179
))
180180

181181

182-
max_lines = 150
183-
184-
185-
def get_generated_code_hint(location, generated_keywords=GENERATED_KEYWORDS):
182+
def get_generated_code_hint(
183+
location,
184+
max_lines=150,
185+
generated_keywords=GENERATED_KEYWORDS_LOWERED
186+
):
186187
"""
187188
Return a line of extracted text from a file if that file is likely
188189
generated source code.
189190
190-
for each of the the first few lines of a source code file
191+
for each of the first few lines of a source code file
191192
if generated keywords are found in the line as lowercase
192193
yield the line text as a 'potentially_ generated' annotation
193194
"""
@@ -196,9 +197,8 @@ def get_generated_code_hint(location, generated_keywords=GENERATED_KEYWORDS):
196197
return
197198
with open(location, 'rb') as filein:
198199
for line in islice(filein, max_lines):
199-
text = toascii(line.strip())
200-
textl = text.lower()
201-
if any(kw in textl for kw in generated_keywords):
200+
text = toascii(line.strip()).lower()
201+
if any(kw in text.lower() for kw in generated_keywords):
202202
# yield only the first 100 chars..
203203
yield text[:100]
204204

0 commit comments

Comments
 (0)