99
1010from itertools import islice
1111
12-
1312from commoncode .datautils import Boolean
1413from commoncode .text import toascii
1514from plugincode .scan import ScanPlugin
1918import 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' ,
@@ -157,25 +156,39 @@ def generated_scanner(location, **kwargs):
157156 'function: static codebooks autogenerated by' ,
158157
159158 # yarn lock
160- 'THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY .' ,
161- 'This file has been automatically created by' ,
162- 'Please do not edit this file, all changes will be lost' ,
159+ 'this is an autogenerated file. do not edit this file directly .' ,
160+ 'this file has been automatically created by' ,
161+ 'please do not edit this file, all changes will be lost' ,
163162
164- # protoc
165- 'Generated by the protocol buffer compiler. DO NOT EDIT!' ,
163+ # thrift
164+ 'this is an automatically-generated file.' ,
165+ 'it could get re-generated if the allow_idl_generation flag is on' ,
166166
167- ))
167+ # aws sdk ruby
168+ 'warning about generated code' ,
169+ 'this file is generated. see the contributing guide for more information' ,
170+ 'this file is generated' ,
168171
172+ # seen in Go files:
173+ 'code generated file. do not edit' ,
174+ 'code generated by running "go generate". do not edit.'
169175
170- max_lines = 150
176+ # protoc
177+ 'generated by the protocol buffer compiler. do not edit!' ,
178+ 'generated by the protocol buffer compiler.' ,
179+ ))
171180
172181
173- 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+ ):
174187 """
175188 Return a line of extracted text from a file if that file is likely
176189 generated source code.
177190
178- 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
179192 if generated keywords are found in the line as lowercase
180193 yield the line text as a 'potentially_ generated' annotation
181194 """
@@ -184,9 +197,8 @@ def get_generated_code_hint(location, generated_keywords=GENERATED_KEYWORDS):
184197 return
185198 with open (location , 'rb' ) as filein :
186199 for line in islice (filein , max_lines ):
187- text = toascii (line .strip ())
188- textl = text .lower ()
189- 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 ):
190202 # yield only the first 100 chars..
191203 yield text [:100 ]
192204
0 commit comments