mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	The find-add-class tool, when in lint mode, verifies that we can understand all calls to addClass from our JS code. When in non-lint mode, i.e. verbose mode, the tool prints out a list of tuples of (fn, class) that we can use as we wish in other tools.
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env python
 | 
						|
from __future__ import absolute_import
 | 
						|
from __future__ import print_function
 | 
						|
 | 
						|
from lib.find_add_class import display, find
 | 
						|
import glob
 | 
						|
import optparse
 | 
						|
import sys
 | 
						|
 | 
						|
from six.moves import filter
 | 
						|
try:
 | 
						|
    import lister
 | 
						|
    from typing import cast, Callable, Dict, Iterable, List
 | 
						|
except ImportError as e:
 | 
						|
    print("ImportError: {}".format(e))
 | 
						|
    print("You need to run the Zulip linters inside a Zulip dev environment.")
 | 
						|
    print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
 | 
						|
    sys.exit(1)
 | 
						|
 | 
						|
def process_files():
 | 
						|
    # type: () -> None
 | 
						|
 | 
						|
    usage = '''
 | 
						|
        Use this tool to find HTML classes that we use in our JS code.
 | 
						|
        This looks for calls to addClass, and if you use the -v option,
 | 
						|
        you will get a display of (fn, html_class) tuples that
 | 
						|
        represent addClass calls.
 | 
						|
 | 
						|
        If you call it with no options, the tool acts as a linter, and
 | 
						|
        it will complain if it can't resolve the class for an addClass()
 | 
						|
        call.
 | 
						|
        '''
 | 
						|
 | 
						|
    parser = optparse.OptionParser(usage=usage)
 | 
						|
    parser.add_option('--verbose', '-v',
 | 
						|
        action='store_true', default=False,
 | 
						|
        help='Show where calls are.')
 | 
						|
    (options, _) = parser.parse_args()
 | 
						|
 | 
						|
    fns = glob.glob('static/js/*.js')
 | 
						|
    if options.verbose:
 | 
						|
        display(fns)
 | 
						|
    else:
 | 
						|
        find(fns)
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    process_files()
 |