def merge_rc_settings(self, settings): """ Merge .sublimelinterrc settings with settings. Searches for .sublimelinterrc in, starting at the directory of the linter's view. The search is limited to rc_search_limit directories. If found, the meta settings and settings for this linter in the rc file are merged with settings. """ limit = persist.settings.get('rc_search_limit', None) rc_settings = util.get_view_rc_settings(self.view, limit=limit) if rc_settings: meta = self.meta_settings(rc_settings) rc_settings = rc_settings.get('linters', {}).get(self.name, {}) rc_settings.update(meta) rcfile = rc_settings.get('rcfile') if rcfile: start_dir = os.path.dirname(self.view.file_name()) linterrc_path = util.find_file(start_dir, '.sublimelinterrc', limit=limit) linterrc_dir = os.path.dirname(linterrc_path) rc_settings['rcfile'] = os.path.abspath(os.path.join(linterrc_dir, rc_settings['rcfile'])) settings.update(rc_settings)
def run(self, cmd, code): """ Return a list with the command to execute. The command chosen is resolved as follows: If the `use-cargo` option is set, lint using a `cargo build`. If cargo is not used, and the `use-crate-root` option is set, lint the crate root. Finally, if the crate root cannot be determined, or the `use-crate-root` option is not set, lint the current file. Linting the crate (either through cargo or rustc) means that if errors are caught in other files, errors on the current file might not show up until these other errors are resolved. Linting a single file means that any imports from higher in the module hierarchy will probably cause an error and prevent proper linting in the rest of the file. """ self.use_cargo = self.get_view_settings().get('use-cargo', False) self.use_cargo_check = self.get_view_settings().get('use-cargo-check', False) self.use_crate_root = self.get_view_settings().get('use-crate-root', False) if self.use_cargo or self.use_cargo_check: cargo_cmd = ['check'] if self.use_cargo_check else self.cmd current_dir = os.path.dirname(self.filename) self.cargo_config = util.find_file(current_dir, 'Cargo.toml') if self.cargo_config: self.tempfile_suffix = '-' old_cwd = os.getcwd() os.chdir(os.path.dirname(self.cargo_config)) try: return util.communicate( ['cargo'] + cargo_cmd + ['--manifest-path', self.cargo_config], code=None, output_stream=self.error_stream, env=self.env) finally: os.chdir(old_cwd) if self.use_crate_root: self.crate_root = self.locate_crate_root() if self.crate_root: cmd.append(self.crate_root) self.tempfile_suffix = '-' return util.communicate(cmd, code=None, output_stream=self.error_stream, env=self.env) self.tempfile_suffix = 'rs' return self.tmpfile(cmd, code)
def run(self, cmd, code): """ Return a list with the command to execute. The command chosen is resolved as follows: If the `use-cargo` option is set, lint using a `cargo build`. If cargo is not used, and the `use-crate-root` option is set, lint the crate root. Finally, if the crate root cannot be determined, or the `use-crate-root` option is not set, lint the current file. Linting the crate (either through cargo or rustc) means that if errors are caught in other files, errors on the current file might not show up until these other errors are resolved. Linting a single file means that any imports from higher in the module hierarchy will probably cause an error and prevent proper linting in the rest of the file. """ self.use_cargo = self.get_view_settings().get('use-cargo', False) self.use_cargo_check = self.get_view_settings().get( 'use-cargo-check', False) self.use_crate_root = self.get_view_settings().get( 'use-crate-root', False) if self.use_cargo or self.use_cargo_check: cargo_cmd = ['check'] if self.use_cargo_check else self.cmd current_dir = os.path.dirname(self.filename) self.cargo_config = util.find_file(current_dir, 'Cargo.toml') if self.cargo_config: self.tempfile_suffix = '-' old_cwd = os.getcwd() os.chdir(os.path.dirname(self.cargo_config)) try: return util.communicate( ['cargo'] + cargo_cmd + ['--manifest-path', self.cargo_config], code=None, output_stream=self.error_stream, env=self.env) finally: os.chdir(old_cwd) if self.use_crate_root: self.crate_root = self.locate_crate_root() if self.crate_root: cmd.append(self.crate_root) self.tempfile_suffix = '-' return util.communicate(cmd, code=None, output_stream=self.error_stream, env=self.env) self.tempfile_suffix = 'rs' return self.tmpfile(cmd, code)
def get_chdir(self, settings): """Find the chdir to use with the linter.""" current_dir = os.path.dirname(self.filename) cargo_config = util.find_file(current_dir, 'Cargo.toml') if not cargo_config: raise Exception('No Cargo.toml found') return os.path.dirname(cargo_config)
def locate_crate_root(self): """ Return the filename of the crate root. The filename may be manually set in a configuration file (highest priority), or it is located by convention. When no configuration is set, main.rs will take preference over lib.rs. If neither main.rs or lib.rs are found, give up. """ crate_root = self.get_view_settings().get('crate-root', None) if not crate_root: crate_root = util.find_file(os.path.dirname(self.filename), 'main.rs') if not crate_root: crate_root = util.find_file(os.path.dirname(self.filename), 'lib.rs') return crate_root
def cmd(self): """Return a tuple with the command line to execute.""" command = [self.executable_path, '--verbose', '8'] config = util.find_file(os.path.dirname(self.filename), '.perlcriticrc') if config: command += ['-p', config] return command
def run(self, cmd, code): current_dir = os.path.dirname(self.filename) self.cargo_config = util.find_file(current_dir, 'Cargo.toml') try: os.chdir(os.path.dirname(self.cargo_config)) return util.communicate(cmd, code=code, output_stream=self.error_stream, env=self.env) finally: os.chdir(current_dir)
def cmd(self): """Return a tuple with the command line to execute.""" command = [self.executable_path, '--verbose', '8'] config = util.find_file( os.path.dirname(self.filename), '.perlcriticrc') if config: command += ['-p', config] return command
def get_classpath(self, classpath_filename): """Read classpath from file and return as str.""" def strip_ws(cp_data): entries = cp_data.split(':') return ':'.join(x.strip() for x in entries) cp_path = util.find_file(path.dirname(self.filename), classpath_filename) if cp_path: with open(cp_path, 'r') as cp_file: cp_data = cp_file.read() return strip_ws(cp_data)
def cmd(self): """ Return the command line to be run. We define this to find a .rubocop.yml file. """ command = [self.executable_path[1]] + ['--format', 'emacs'] config = util.find_file(os.path.dirname(self.filename), '.rubocop.yml') if config: command += ['--config', config] return command
def cmd(self): """ Return a string with the command line to execute. We define this method because we want to use the .scsslintrc files, and we can't rely on scss-lint to find them, because we are using stdin. """ command = [self.executable_path] scsslintrc = util.find_file(os.path.dirname(self.filename), '.scss-lint.yml') if scsslintrc: command += ['--config', scsslintrc] return command + ['@']
def get_classpath(self, classpath_filename): """Read classpath from file and return as str.""" def strip_ws(cp_data): entries = cp_data.split(':') return ':'.join(x.strip() for x in entries) cp_path = util.find_file( path.dirname(self.filename), classpath_filename ) if cp_path: with open(cp_path, 'r') as cp_file: cp_data = cp_file.read() return strip_ws(cp_data)
def build_args(self, settings): """ Return a list of args to add to cls.cmd. We hook into this method to find the rubocop config and set it as an environment variable for the rubocop linter to pick up. """ rubocop_file = settings.get('rubocop-config', '.rubocop.yml') if self.filename: rubocop_config = util.find_file(os.path.dirname(self.filename), rubocop_file, aux_dirs='~') print(rubocop_config) if rubocop_config: self.env['HAML_LINT_RUBOCOP_CONF'] = rubocop_config else: self.env.pop('HAML_LINT_RUBOCOP_CONF', None) return super().build_args(settings)
def cmd(self): """ Return a string with the command line to execute. We define this method because we want to use the .jshintrc files, and we can't rely on jshint to find them, because we are using stdin. """ command = [self.executable_path, '--verbose', '*'] # Allow the user to specify a config file in args args = self.get_user_args() if '--config' not in args: jshintrc = util.find_file(os.path.dirname(self.filename), '.jshintrc') if jshintrc: command += ['--config', jshintrc] return command + ['-']
def build_args(self, settings): """ Return a list of args to add to cls.cmd. We hook into this method to find the rubocop config and set it as an environment variable for the rubocop linter to pick up. """ rubocop_file = settings.get('rubocop-config', '.rubocop.yml') if self.filename: rubocop_config = util.find_file( os.path.dirname(self.filename), rubocop_file, aux_dirs='~' ) print(rubocop_config) if rubocop_config: self.env['HAML_LINT_RUBOCOP_CONF'] = rubocop_config else: self.env.pop('HAML_LINT_RUBOCOP_CONF', None) return super().build_args(settings)
def __findTSConfigPath(self): return util.find_file(os.path.dirname(self.filename), 'tsconfig.json')