<s> import os <EOL> import re <EOL> import sublime <EOL> import sublime_plugin <EOL> try : <EOL> from edit_buffer import * <EOL> from statusprocess import * <EOL> from asyncprocess import * <EOL> except ImportError : <EOL> from . edit_buffer import * <EOL> from . statusprocess import * <EOL> from . asyncprocess import * <EOL> RESULT_VIEW_NAME = '<STR_LIT>' <EOL> SETTINGS_FILE = "<STR_LIT>" <EOL> class ShowJslintResultCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" + RESULT_VIEW_NAME } ) <EOL> class JslintCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> s = sublime . load_settings ( SETTINGS_FILE ) <EOL> file_path = self . window . active_view ( ) . file_name ( ) <EOL> file_name = os . path . basename ( file_path ) <EOL> self . debug = s . get ( '<STR_LIT>' , False ) <EOL> self . buffered_data = '<STR_LIT>' <EOL> self . file_path = file_path <EOL> self . file_name = file_name <EOL> self . is_running = True <EOL> self . tests_panel_showed = False <EOL> self . ignored_error_count = <NUM_LIT:0> <EOL> self . ignore_errors = s . get ( '<STR_LIT>' , [ ] ) <EOL> self . use_node_jslint = s . get ( '<STR_LIT>' , False ) <EOL> self . init_tests_panel ( ) <EOL> if ( self . use_node_jslint ) : <EOL> cmd = '<STR_LIT>' + s . get ( '<STR_LIT>' , '<STR_LIT>' ) + '<STR_LIT>' + file_path + '<STR_LIT:">' <EOL> else : <EOL> if len ( s . get ( '<STR_LIT>' , '<STR_LIT>' ) ) > <NUM_LIT:0> : <EOL> jslint_jar = s . get ( '<STR_LIT>' ) <EOL> else : <EOL> jslint_jar = sublime . packages_path ( ) + '<STR_LIT>' <EOL> cmd = '<STR_LIT>' + jslint_jar + '<STR_LIT>' + s . get ( '<STR_LIT>' , '<STR_LIT>' ) + '<STR_LIT>' + file_path + '<STR_LIT:">' <EOL> AsyncProcess ( cmd , self ) <EOL> StatusProcess ( '<STR_LIT>' + file_name , self ) <EOL> JsLintEventListener . disabled = True <EOL> def init_tests_panel ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . output_view = self . window . get_output_panel ( RESULT_VIEW_NAME ) <EOL> self . output_view . set_name ( RESULT_VIEW_NAME ) <EOL> self . clear_test_view ( ) <EOL> self . output_view . settings ( ) . set ( "<STR_LIT>" , self . file_path ) <EOL> def show_tests_panel ( self ) : <EOL> if self . tests_panel_showed : <EOL> return <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" + RESULT_VIEW_NAME } ) <EOL> self . tests_panel_showed = True <EOL> def clear_test_view ( self ) : <EOL> with Edit ( self . output_view , True ) as edit : <EOL> edit . erase ( sublime . Region ( <NUM_LIT:0> , self . output_view . size ( ) ) ) <EOL> def append_data ( self , proc , bData , end = False ) : <EOL> if self . debug : <EOL> print ( "<STR_LIT>" ) <EOL> data = bData . decode ( '<STR_LIT:utf-8>' ) <EOL> if self . debug : <EOL> print ( "<STR_LIT>" + data ) <EOL> self . buffered_data = self . buffered_data + data <EOL> data = self . buffered_data . replace ( self . file_path , self . file_name ) . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) . replace ( '<STR_LIT:\r>' , '<STR_LIT:\n>' ) <EOL> if end is False : <EOL> rsep_pos = data . rfind ( '<STR_LIT:\n>' ) <EOL> if rsep_pos == - <NUM_LIT:1> : <EOL> return <EOL> self . buffered_data = data [ rsep_pos + <NUM_LIT:1> : ] <EOL> data = data [ : rsep_pos + <NUM_LIT:1> ] <EOL> text = data <EOL> if ( len ( self . ignore_errors ) > <NUM_LIT:0> ) and ( not self . use_node_jslint ) : <EOL> text = '<STR_LIT>' <EOL> for line in data . split ( '<STR_LIT:\n>' ) : <EOL> if len ( line ) == <NUM_LIT:0> : <EOL> continue <EOL> ignored = False <EOL> for rule in self . ignore_errors : <EOL> if re . search ( rule , line ) : <EOL> ignored = True <EOL> self . ignored_error_count += <NUM_LIT:1> <EOL> if self . debug : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" + rule ) <EOL> print ( "<STR_LIT>" + line ) <EOL> print ( "<STR_LIT>" ) <EOL> break <EOL> if ignored is False : <EOL> text += line + '<STR_LIT:\n>' <EOL> self . show_tests_panel ( ) <EOL> selection_was_at_end = ( len ( self . output_view . sel ( ) ) == <NUM_LIT:1> and self . output_view . sel ( ) [ <NUM_LIT:0> ] == sublime . Region ( self . output_view . size ( ) ) ) <EOL> with Edit ( self . output_view , True ) as edit : <EOL> edit . insert ( self . output_view . size ( ) , text ) <EOL> if end and not self . use_node_jslint : <EOL> text = '<STR_LIT>' + str ( self . ignored_error_count ) + '<STR_LIT>' <EOL> with Edit ( self . output_view , True ) as edit : <EOL> edit . insert ( <NUM_LIT:0> , text ) <EOL> def update_status ( self , msg , progress ) : <EOL> sublime . status_message ( msg + "<STR_LIT:U+0020>" + progress ) <EOL> def proc_terminated ( self , proc ) : <EOL> if proc . returncode == <NUM_LIT:0> : <EOL> msg = self . file_name + '<STR_LIT>' <EOL> else : <EOL> msg = '<STR_LIT>' <EOL> self . append_data ( proc , msg . encode ( '<STR_LIT:utf-8>' ) , True ) <EOL> JsLintEventListener . disabled = False <EOL> class JsLintEventListener ( sublime_plugin . EventListener ) : <EOL> """<STR_LIT>""" <EOL> disabled = False <EOL> def __init__ ( self ) : <EOL> self . previous_resion = None <EOL> self . file_view = None <EOL> def on_post_save ( self , view ) : <EOL> s = sublime . load_settings ( SETTINGS_FILE ) <EOL> if s . get ( '<STR_LIT>' , False ) is False : <EOL> return <EOL> if view . file_name ( ) . endswith ( '<STR_LIT>' ) is False : <EOL> return <EOL> sublime . active_window ( ) . run_command ( "<STR_LIT>" ) <EOL> def on_deactivated ( self , view ) : <EOL> if view . name ( ) != RESULT_VIEW_NAME : <EOL> return <EOL> self . previous_resion = None <EOL> if self . file_view : <EOL> self . file_view . erase_regions ( RESULT_VIEW_NAME ) <EOL> def on_selection_modified ( self , view ) : <EOL> if JsLintEventListener . disabled : <EOL> return <EOL> if view . name ( ) != RESULT_VIEW_NAME : <EOL> return <EOL> region = view . line ( view . sel ( ) [ <NUM_LIT:0> ] ) <EOL> s = sublime . load_settings ( SETTINGS_FILE ) <EOL> if self . previous_resion == region : <EOL> return <EOL> self . previous_resion = region <EOL> if ( s . get ( '<STR_LIT>' , False ) ) : <EOL> pattern_position = "<STR_LIT>" <EOL> text = view . substr ( region ) <EOL> text = re . findall ( pattern_position , text ) <EOL> if len ( text ) > <NUM_LIT:0> : <EOL> line = int ( text [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> col = int ( text [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> else : <EOL> text = view . substr ( region ) . split ( '<STR_LIT::>' ) <EOL> if len ( text ) < <NUM_LIT:4> or text [ <NUM_LIT:0> ] != '<STR_LIT>' or re . match ( '<STR_LIT>' , text [ <NUM_LIT:2> ] ) is None or re . match ( '<STR_LIT>' , text [ <NUM_LIT:3> ] ) is None : <EOL> return <EOL> line = int ( text [ <NUM_LIT:2> ] ) <EOL> col = int ( text [ <NUM_LIT:3> ] ) <EOL> view . add_regions ( RESULT_VIEW_NAME , [ region ] , "<STR_LIT>" ) <EOL> file_path = view . settings ( ) . get ( '<STR_LIT>' ) <EOL> window = sublime . active_window ( ) <EOL> file_view = None <EOL> for v in window . views ( ) : <EOL> if v . file_name ( ) == file_path : <EOL> file_view = v <EOL> break <EOL> if file_view is None : <EOL> return <EOL> self . file_view = file_view <EOL> window . focus_view ( file_view ) <EOL> file_view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : line } ) <EOL> file_region = file_view . line ( file_view . sel ( ) [ <NUM_LIT:0> ] ) <EOL> file_view . add_regions ( RESULT_VIEW_NAME , [ file_region ] , "<STR_LIT:string>" ) </s>
