def code_analysis_jshint(options): log('title', 'JSHint') jenkins = _normalize_boolean(options['jenkins']) # cmd is a sequence of program arguments # first argument is child program paths = options['directory'].split('\n') cmd = [ options['jshint-bin'], '--verbose', '--exclude={0}'.format(options['jshint-exclude'] or ' ')] + paths try: if jenkins: cmd.append('--reporter=jslint') output_file_name = os.path.join(options['location'], 'jshint.xml') output_file = open(output_file_name, 'w+') else: output_file = TemporaryFile('w+') # Wrapper to subprocess.Popen try: # Return code is not used for jshint. output = _read_subprocess_output(cmd, output_file)[0] except OSError: log('skip') return False finally: output_file.close() # HACK: workaround for JSHint limitations if jshint_errors(output, jenkins): if jenkins: log('failure', 'Output file written to %s.' % output_file_name) else: # Name the pattern to use it in the substitution. old, new = '\((?P<name>E\d\d\d)\)', u'(\033[00;31m\g<name>\033[0m)' log('failure', _process_output(output, old, new)) return False else: log('ok') if output != '' and not jenkins: print(output) # XXX: there should be warnings on the output return True
def code_analysis_flake8(options): log('title', 'Flake8') jenkins = _normalize_boolean(options['jenkins']) # cmd is a sequence of program arguments # first argument is child program cmd = [ os.path.join(options['bin-directory']) + '/flake8', '--ignore={0}'.format(options['flake8-ignore']), '--exclude={0}'.format(options['flake8-exclude']), '--max-complexity={0}'.format(options['flake8-max-complexity']), '--max-line-length={0}'.format(options['flake8-max-line-length']) ] paths_to_check = options['directory'].split('\n') cmd.extend(paths_to_check) try: if jenkins: output_file_name = os.path.join(options['location'], 'flake8.log') output_file = open(output_file_name, 'w+') else: output_file = TemporaryFile('w+') # Wrapper to subprocess.Popen try: output, return_code = _read_subprocess_output(cmd, output_file) except OSError: log('skip') return False finally: output_file.close() if return_code: log('failure', output) return False else: log('ok') return True
def code_analysis_csslint(options): log('title', 'CSS Lint') jenkins = _normalize_boolean(options['jenkins']) # cmd is a sequence of program arguments # first argument is child program paths = options['directory'].split('\n') cmd = [options['csslint-bin']] + paths try: if jenkins: cmd.insert(1, '--format=lint-xml') # Get only errors, no warnings. output_file_name = os.path.join(options['location'], 'csslint.xml') output_file = open(output_file_name, 'w+') else: output_file = TemporaryFile('w+') # Wrapper to subprocess.Popen try: # Return code is not used for csslint. output = _read_subprocess_output(cmd, output_file)[0] except OSError: log('skip') return False finally: output_file.close() if csslint_errors(output, jenkins): if jenkins: log('failure', 'Output file written to %s.' % output_file_name) else: # TODO: pass color to _process_output # Name the pattern to use it in the substitution. old, new = '(?P<name>Error[^ -]*)', '\033[00;31m\g<name>\033[0m' log('failure', _process_output(output, old, new)) return False else: log('ok') return True