from imhotep.tools import Tool
from collections import defaultdict
import json
import os


class JSHintDiff(Tool):
	def invoke(self, dirname, filenames=set(), linter_configs=set()):
		retval = defaultdict(lambda: defaultdict(list))
		config = ''
		for config_file in linter_configs:
			config = '--config=%s ' % config_file
		if len(filenames) == 0:
			print 'No files to lint'
			return retval
		else:
			files = []
			for filename in filenames:
				if '.js' in filename:
					files.append('%s/%s' % (dirname, filename))

			cmd = 'jshint %s %s' % (config, ' '.join(files))
		try:
			output = self.executor(cmd)
			for line in output.split('\n'):
				path, line, column, message = line.split(':')
				file_name = os.path.abspath(path)
				file_name = file_name.replace(dirname, '')[1:]
				retval[str(file_name)][line].append(message.lstrip(' '))
		except:
			pass
		return retval

@@ -1,92 +1,45 @@
-from imhotep.tools 
 import 
-Tool
+os%0A
 %0Afrom 
-collections import defaultdict%0Aimport json%0A
+imhotep.tools 
 import 
-os
+Tool
 %0A%0A%0Ac
@@ -65,545 +65,373 @@
 l):%0A
-%09def invoke(self, dirname, filenames=set(), linter_configs=set()):%0A%09%09retval = defaultdict(lambda: defaultdict(list))%0A%09%09config = ''%0A%09%09for config_file in linter_configs:%0A%09%09%09config = '--config=%25s ' %25 config_file%0A%09%09if len(filenames) == 0:%0A%09%09%09print 'No files to lint'%0A%09%09%09return retval%0A%09%09else:%0A%09%09%09files = %5B%5D%0A%09%09%09for filename in filenames:%0A%09%09%09%09if '.js' in filename:%0A%09%09%09%09%09files.append('%25s/%25s' %25 (dirname, filename))%0A%0A%09%09%09cmd = 'jshint %25s %25s' %25 (config, ' '.join(files))%0A%09%09try:%0A%09%09%09output = self.executor(cmd)%0A%09%09%09for line in output.split('%5Cn'):%0A%09%09%09%09
+%0A    def __init__(self, *args, **kwargs):%0A        super(JSHintDiff, self).__init__(*args, **kwargs)%0A        self.linter = 'jshint'%0A        self.config = '.jscsrc'%0A        self.extension = 'js'%0A%0A    def format_linter_output(self, repo_dir, linter_output, linter_errors):%0A        %22%22%22 Returns a dict of linter errors %22%22%22%0A        for line in linter_output:%0A            
 path
@@ -472,20 +472,28 @@
 it(':')%0A
-%09%09%09%09
+            
 file_nam
@@ -518,20 +518,28 @@
 h(path)%0A
-%09%09%09%09
+            
 file_nam
@@ -564,15 +564,16 @@
 ace(
-dirname
+repo_dir
 , ''
@@ -582,18 +582,33 @@
 1:%5D%0A
-%09%09%09%09retval
+            linter_errors
 %5Bstr
@@ -658,38 +658,33 @@
 '))%0A
-%09%09except:%0A%09%09%09pass%0A%09%09return retval
+        return linter_errors
 %0A

Implement refactored tool