From 33d2c30a6ef0d2e5be0477ca8fff9c023c7d1bfe Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 16 Jun 2020 01:27:51 +0200 Subject: [PATCH 01/19] Updated cmd --- linter.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/linter.py b/linter.py index 7276298..8cabe9c 100644 --- a/linter.py +++ b/linter.py @@ -1,16 +1,18 @@ # # linter.py -# Linter for SublimeLinter3, a code checking framework for Sublime Text 3 +# Linter for SublimeLinter4, a code checking framework for Sublime Text 3 # # Written by Noah Davis # Copyright (c) 2016 Noah Davis # +# Updated by Schuyler Jager & Andreas for SublimeLinter 4 +# Copyright (c) 2020 Schuyler Jager & Andreas # License: MIT # """This module exports the Codeclimate plugin class.""" -from SublimeLinter.lint import Linter, util, persist +from SublimeLinter.lint import Linter, util class Codeclimate(Linter): @@ -42,14 +44,7 @@ class Codeclimate(Linter): word_re = None def cmd(self): - """Construct a cmd to provide a relative path to 'codeclimate analyze'.""" - result = ['codeclimate', 'analyze', '-e', 'structure', '-e', 'duplication'] - relative_file_name = None - for folder in self.view.window().folders(): - if self.filename.find(folder) == 0: - relative_file_name = self.filename.replace(folder + '/', '') - if relative_file_name == None: - return result - result.append(relative_file_name) - persist.debug(result) - return result + """Set working directory and run 'codeclimate analyze'.""" + if self.context.get('project_root') is None: + self.defaults['chdir'] = '${folder}' + return ['codeclimate', 'analyze', '${file_on_disk}'] From a17fd42d9a589e3c1b2d42b6c147f6e1c749c8fb Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 16 Jun 2020 02:23:34 +0200 Subject: [PATCH 02/19] Set folder or file_path as working dir --- linter.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linter.py b/linter.py index 8cabe9c..ae7a14c 100644 --- a/linter.py +++ b/linter.py @@ -46,5 +46,7 @@ class Codeclimate(Linter): def cmd(self): """Set working directory and run 'codeclimate analyze'.""" if self.context.get('project_root') is None: - self.defaults['chdir'] = '${folder}' + self.defaults['chdir'] = '${folder}' \ + if self.context.get('folder') is not None \ + else '${file_path}' return ['codeclimate', 'analyze', '${file_on_disk}'] From 41fcee0bde5f8204f929d2c5a639f8b224ff7328 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 16 Jun 2020 02:29:05 +0200 Subject: [PATCH 03/19] Updated docs --- README.md | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fa9b447..5bd5444 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ SublimeLinter-contrib-codeclimate -================================ +================================= + +> Please note: This was originally a fork of [codeclimate/SublimeLinter-contrib-codeclimate][codeclimate-origin] to make it compatible for SublimeLinter 4. [![Build Status](https://travis-ci.org/codeclimate/SublimeLinter-contrib-codeclimate.svg?branch=master)](https://travis-ci.org/codeclimate/SublimeLinter-contrib-codeclimate) This linter plugin for [SublimeLinter][docs] provides an interface to [codeclimate](https://github.com/codeclimate/codeclimate). Code Climate supports a variety of languages through standardized Docker images known as static analysis engines. ## Installation -SublimeLinter 3 must be installed in order to use this plugin. If SublimeLinter 3 is not installed, please follow the instructions [here][installation]. +SublimeLinter 4 must be installed in order to use this plugin. If SublimeLinter 4 is not installed, please follow the instructions [here][installation]. ### Linter installation Before using this plugin, you must ensure that `codeclimate` is installed on your system. Please see the `codeclimate` documentation, specifically [Prerequisites](https://github.com/codeclimate/codeclimate#prerequisites) and [Installation](https://github.com/codeclimate/codeclimate#installation) ### Linter configuration -In order for `codeclimate` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. Before going any further, please read and follow the steps in [“Finding a linter executable”](http://sublimelinter.readthedocs.org/en/latest/troubleshooting.html#finding-a-linter-executable) through “Validating your PATH” in the documentation. - -__This plugin requires usage within a Sublime project at this time.__ +In order for `codeclimate` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. Before going any further, please read and follow the steps in ["Finding a linter executable"](http://sublimelinter.readthedocs.org/en/latest/troubleshooting.html#finding-a-linter-executable) through "Validating your PATH" in the documentation. Once you have installed and configured `codeclimate`, you can proceed to install the SublimeLinter-contrib-codeclimate plugin if it is not yet installed. @@ -23,21 +23,48 @@ Please use [Package Control][pc] to install the linter plugin. This will ensure To install via Package Control, do the following: -1. Within Sublime Text, bring up the [Command Palette][cmd] and type `install`. Among the commands you should see `Package Control: Install Package`. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins. +Within Sublime Text, bring up the [Command Palette][cmd] and type `install`. Among the commands you should see `Package Control: Install Package`. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins. -1. When the plugin list appears, type `codeclimate`. Among the entries you should see `SublimeLinter-contrib-codeclimate`. If that entry is not highlighted, use the keyboard or mouse to select it. +When the plugin list appears, type `codeclimate`. Among the entries you should see `SublimeLinter-contrib-codeclimate`. If that entry is not highlighted, use the keyboard or mouse to select it. ## Settings For general information on how SublimeLinter works with settings, please see [Settings][settings]. For information on generic linter settings, please see [Linter Settings][linter-settings]. +## How it works + +The linter is first looking for a SublimeText Project. If a `*.sublime-project` is given, it executes `codeclimate` in the project root directory. If no project is given, it tries to execute `codeclimate` in the first opened folder of the folder pane. + +If the SublimeText project folder or the first opened folder in the folder pane contains a `.codeclimate.yml` configuration file, `codeclimate` will recognise its settings. If no configuration file can be evaluated, `codeclimate` will automatically run the defaults of `structure` and `duplication` at this time. + +## Linter Configuration + +To specify the path to executable, please use the SublimeLinter settings: + +```json +{ + "linters": { + "executable": "/usr/local/bin/codeclimate" + } +} +``` + + +If your `.codeclimate.yml` does not live in the project root folder, you can set also the `working_dir` of SublimeLinter: + +```json +{ + "working_dir": "${folder:$file_path}" +} +``` + ## Contributing If you would like to contribute enhancements or fixes, please do the following: 1. Fork the plugin repository. -1. Hack on a separate topic branch created from the latest `master`. -1. Commit and push the topic branch. -1. Make a pull request. -1. Be patient. ;-) +2. Hack on a separate topic branch created from the latest `master`. +3. Commit and push the topic branch. +4. Make a pull request. +5. Be patient. Please note that modifications should follow these coding guidelines: @@ -48,6 +75,7 @@ Please note that modifications should follow these coding guidelines: Thank you for helping out! +[codeclimate-origin]: https://github.com/codeclimate/SublimeLinter-contrib-codeclimate [docs]: http://sublimelinter.readthedocs.org [installation]: http://sublimelinter.readthedocs.org/en/latest/installation.html [locating-executables]: http://sublimelinter.readthedocs.org/en/latest/usage.html#how-linter-executables-are-located From 42c2145a98a08759f64785568488a1ab824c9189 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 16 Jun 2020 13:52:33 +0200 Subject: [PATCH 04/19] Fixed file path, must be relative to working dir --- linter.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/linter.py b/linter.py index ae7a14c..1711e16 100644 --- a/linter.py +++ b/linter.py @@ -12,6 +12,7 @@ """This module exports the Codeclimate plugin class.""" +import re from SublimeLinter.lint import Linter, util @@ -43,10 +44,16 @@ class Codeclimate(Linter): error_stream = util.STREAM_BOTH word_re = None + root = None + path = None + def cmd(self): """Set working directory and run 'codeclimate analyze'.""" if self.context.get('project_root') is None: self.defaults['chdir'] = '${folder}' \ if self.context.get('folder') is not None \ else '${file_path}' - return ['codeclimate', 'analyze', '${file_on_disk}'] + + root = re.search(r"\{(\w+)\}", self.defaults['chdir']).group(1) + path = self.filename.replace(self.context.get(root) + '/', '') + return ['codeclimate', 'analyze', path] From 4cb246c70526e3090a208d112a60f960d6f36780 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 18 Jun 2020 09:53:28 +0200 Subject: [PATCH 05/19] Added example for global args --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 5bd5444..cfc8c81 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,23 @@ If your `.codeclimate.yml` does not live in the project root folder, you can set } ``` +If you want to ignore the configuration in a `.codeclimate.yml`, for instance, to run a subset of codeclimate engines, you can configure this by setting the linter arguments either in the global SublimeLinter settings or in your project settings. In the global settings, this could look like this: + +```json +{ + "linters": { + "codeclimate": { + "args": [ + "-e", + "structure", + "-e", + "duplication" + ] + } + } +} +``` + ## Contributing If you would like to contribute enhancements or fixes, please do the following: From 7314e2d49b0df88d3fc0a5a00763065037817d5f Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 19 Jun 2020 22:34:19 +0200 Subject: [PATCH 06/19] Updated settings and examples --- README.md | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index cfc8c81..2a5394c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ SublimeLinter-contrib-codeclimate ================================= -> Please note: This was originally a fork of [codeclimate/SublimeLinter-contrib-codeclimate][codeclimate-origin] to make it compatible for SublimeLinter 4. - [![Build Status](https://travis-ci.org/codeclimate/SublimeLinter-contrib-codeclimate.svg?branch=master)](https://travis-ci.org/codeclimate/SublimeLinter-contrib-codeclimate) This linter plugin for [SublimeLinter][docs] provides an interface to [codeclimate](https://github.com/codeclimate/codeclimate). Code Climate supports a variety of languages through standardized Docker images known as static analysis engines. @@ -27,37 +25,28 @@ Within Sublime Text, bring up the [Command Palette][cmd] and type `install`. Amo When the plugin list appears, type `codeclimate`. Among the entries you should see `SublimeLinter-contrib-codeclimate`. If that entry is not highlighted, use the keyboard or mouse to select it. -## Settings -For general information on how SublimeLinter works with settings, please see [Settings][settings]. For information on generic linter settings, please see [Linter Settings][linter-settings]. - ## How it works - -The linter is first looking for a SublimeText Project. If a `*.sublime-project` is given, it executes `codeclimate` in the project root directory. If no project is given, it tries to execute `codeclimate` in the first opened folder of the folder pane. +The linter is first looking for a SublimeText Project. If a `*.sublime-project` is given, it executes `codeclimate` in the directory of the project root. If no project is given, it tries to execute `codeclimate` in the first opened folder of the folder pane. If just a file is open, it tries to execute `codeclimate` in the file directory. If the SublimeText project folder or the first opened folder in the folder pane contains a `.codeclimate.yml` configuration file, `codeclimate` will recognise its settings. If no configuration file can be evaluated, `codeclimate` will automatically run the defaults of `structure` and `duplication` at this time. -## Linter Configuration +## Settings +For general information on how SublimeLinter works with settings, please see [Settings][settings]. For information on generic linter settings, please see [Linter Settings][linter-settings]. -To specify the path to executable, please use the SublimeLinter settings: +### Examples +You can set the path to the `codeclimate` executable in the global SublimeLinter settings or your project settings: ```json { "linters": { - "executable": "/usr/local/bin/codeclimate" + "codeclimate": { + "executable": "/usr/local/bin/codeclimate" + } } } ``` - -If your `.codeclimate.yml` does not live in the project root folder, you can set also the `working_dir` of SublimeLinter: - -```json -{ - "working_dir": "${folder:$file_path}" -} -``` - -If you want to ignore the configuration in a `.codeclimate.yml`, for instance, to run a subset of codeclimate engines, you can configure this by setting the linter arguments either in the global SublimeLinter settings or in your project settings. In the global settings, this could look like this: +If you want to ignore the configuration of a `.codeclimate.yml`, for instance, to run a subset of codeclimate engines, you can set linter arguments in the global SublimeLinter settings or your project settings: ```json { @@ -74,6 +63,14 @@ If you want to ignore the configuration in a `.codeclimate.yml`, for instance, t } ``` +It is also possible to set a working directory for execution. But be careful with this! To make this work with the `codeclimate` CLI, the working directory ***must*** be in the path of the file you want to lint! + +```json +{ + "working_dir": "/path/to/working/dir" +} +``` + ## Contributing If you would like to contribute enhancements or fixes, please do the following: @@ -92,7 +89,6 @@ Please note that modifications should follow these coding guidelines: Thank you for helping out! -[codeclimate-origin]: https://github.com/codeclimate/SublimeLinter-contrib-codeclimate [docs]: http://sublimelinter.readthedocs.org [installation]: http://sublimelinter.readthedocs.org/en/latest/installation.html [locating-executables]: http://sublimelinter.readthedocs.org/en/latest/usage.html#how-linter-executables-are-located From 84d573293043ac9fcb410bf67ab059f5f4177bbe Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 23 Dec 2020 21:49:59 +0100 Subject: [PATCH 07/19] Fixed typo in source.haskell --- linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter.py b/linter.py index 1711e16..fe6b2f0 100644 --- a/linter.py +++ b/linter.py @@ -25,7 +25,7 @@ class Codeclimate(Linter): 'selector': ( 'source.css, ' 'source.go, ' - 'source.haskall, ' + 'source.haskell, ' 'source.java, ' 'source.javascript, ' 'source.js, ' From fabc1f8fce6d09f9d4db96e8a6d05c9e6c34462d Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 23 Dec 2020 22:13:49 +0100 Subject: [PATCH 08/19] Removed initialization of root and path --- linter.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/linter.py b/linter.py index fe6b2f0..f01fa6c 100644 --- a/linter.py +++ b/linter.py @@ -44,9 +44,6 @@ class Codeclimate(Linter): error_stream = util.STREAM_BOTH word_re = None - root = None - path = None - def cmd(self): """Set working directory and run 'codeclimate analyze'.""" if self.context.get('project_root') is None: From 79619052405b33236e167afb343ae0e369b1f92b Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 23 Dec 2020 23:12:59 +0100 Subject: [PATCH 09/19] Cleaned up of linter command and working directory --- linter.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/linter.py b/linter.py index f01fa6c..445d833 100644 --- a/linter.py +++ b/linter.py @@ -11,17 +11,12 @@ # """This module exports the Codeclimate plugin class.""" - -import re from SublimeLinter.lint import Linter, util class Codeclimate(Linter): """Provides an interface to codeclimate.""" - defaults = { - 'chdir': "${project}", - 'executable': 'codeclimate', 'selector': ( 'source.css, ' 'source.go, ' @@ -45,12 +40,10 @@ class Codeclimate(Linter): word_re = None def cmd(self): - """Set working directory and run 'codeclimate analyze'.""" - if self.context.get('project_root') is None: - self.defaults['chdir'] = '${folder}' \ - if self.context.get('folder') is not None \ - else '${file_path}' + """Set command and run 'codeclimate analyze'.""" + if 'executable' in self.settings: + command = self.settings.get('executable') + else: + command = 'codeclimate' - root = re.search(r"\{(\w+)\}", self.defaults['chdir']).group(1) - path = self.filename.replace(self.context.get(root) + '/', '') - return ['codeclimate', 'analyze', path] + return [command, 'analyze', '${args}', '${file}'] From 354aea650b4d32d251ceaab723565cc1d4278992 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 23 Dec 2020 23:47:14 +0100 Subject: [PATCH 10/19] Updated docs --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2a5394c..e16a516 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ Within Sublime Text, bring up the [Command Palette][cmd] and type `install`. Amo When the plugin list appears, type `codeclimate`. Among the entries you should see `SublimeLinter-contrib-codeclimate`. If that entry is not highlighted, use the keyboard or mouse to select it. ## How it works -The linter is first looking for a SublimeText Project. If a `*.sublime-project` is given, it executes `codeclimate` in the directory of the project root. If no project is given, it tries to execute `codeclimate` in the first opened folder of the folder pane. If just a file is open, it tries to execute `codeclimate` in the file directory. +If the first opened folder in SublimeText contains a `.codeclimate.yml` configuration file in its root, `codeclimate` will recognize this file's settings. -If the SublimeText project folder or the first opened folder in the folder pane contains a `.codeclimate.yml` configuration file, `codeclimate` will recognise its settings. If no configuration file can be evaluated, `codeclimate` will automatically run the defaults of `structure` and `duplication` at this time. +Suppose the `codeclimate` CLI finds no configuration file in the folder root: In that case, it will automatically run the default inspections of `structure` and `duplication`. If you have a `.codeclimate.yml` configuration file in a different folder, you can set SublimeLinter's `working_dir` setting (please see examples). ## Settings For general information on how SublimeLinter works with settings, please see [Settings][settings]. For information on generic linter settings, please see [Linter Settings][linter-settings]. @@ -46,7 +46,7 @@ You can set the path to the `codeclimate` executable in the global SublimeLinter } ``` -If you want to ignore the configuration of a `.codeclimate.yml`, for instance, to run a subset of codeclimate engines, you can set linter arguments in the global SublimeLinter settings or your project settings: +If you want to ignore the configuration of a `.codeclimate.yml`, for instance, to run a subset of codeclimate engines, you can set linter arguments in the global SublimeLinter settings or your project settings: ```json { @@ -63,14 +63,22 @@ If you want to ignore the configuration of a `.codeclimate.yml`, for instance, } ``` -It is also possible to set a working directory for execution. But be careful with this! To make this work with the `codeclimate` CLI, the working directory ***must*** be in the path of the file you want to lint! +Suppose you use a `.codeclimate.yml`-configuration file. In that case, the `codeclimate` CLI needs to be executed in your configuration file's directory. Otherwise, it can't detect your configuration and runs only the default analyzes. + +SublimeLinter takes the (first) open folder (or the folder of a single opened file) as the working directory for executing its linter commands. You can change this behavior by setting the working directory of execution: ```json { - "working_dir": "/path/to/working/dir" + "linters": { + "codeclimate": { + "working_dir": "/path/to/working/dir" + } + } } ``` +*Hint: Make sure the working directory is in the path of the file you want to lint!* + ## Contributing If you would like to contribute enhancements or fixes, please do the following: From b000bc820883dcc8c6ba8a8179838fab28e4ba2f Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 27 Dec 2020 22:27:24 +0100 Subject: [PATCH 11/19] Updated command & error handling --- linter.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/linter.py b/linter.py index 445d833..5aaca4f 100644 --- a/linter.py +++ b/linter.py @@ -11,9 +11,14 @@ # """This module exports the Codeclimate plugin class.""" +import logging +import os from SublimeLinter.lint import Linter, util +logger = logging.getLogger('SublimeLinter.plugin.eslint') + + class Codeclimate(Linter): """Provides an interface to codeclimate.""" defaults = { @@ -41,9 +46,31 @@ class Codeclimate(Linter): def cmd(self): """Set command and run 'codeclimate analyze'.""" - if 'executable' in self.settings: - command = self.settings.get('executable') - else: - command = 'codeclimate' + abs_path = self.filename + working_dir = self.get_working_dir() + + msg = 'You try to lint the file %s from outside of SublimeText\'s ' \ + 'working directory (%s), which is not supported by this ' \ + 'SublimeLinter plugin at this time. You can do either:\n' \ + '* You open the directory containing the current file in' \ + 'a new window. You may have to add a customized ' \ + '`.codeclimate.yml` configuration to that directory ' \ + 'as well;\n' \ + '* You change the working directory of the linter plugin in ' \ + ' the global or the Project\'s settings;\n' \ + '* You disable the linter plugin in the global or the ' \ + 'Project\'s settings.\n\n' \ + 'Please visit https://github.com/codeclimate/' \ + 'SublimeLinter-contrib-codeclimate for examples.' \ + '\n' % (abs_path, working_dir) + + command = ['codeclimate', 'analyze', '${args}'] + + if not (abs_path.startswith(os.path.abspath(working_dir) + os.sep)): + logger.info(msg) + return None - return [command, 'analyze', '${args}', '${file}'] + file = os.path.relpath(self.filename, self.get_working_dir()) + command.append(file) + command.append('${xoo}') + return command From b781a488172b1569270fdae597f742bc40d0f060 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 27 Dec 2020 22:42:30 +0100 Subject: [PATCH 12/19] Cleaned up command handling --- linter.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/linter.py b/linter.py index 5aaca4f..81bbdb2 100644 --- a/linter.py +++ b/linter.py @@ -64,13 +64,9 @@ def cmd(self): 'SublimeLinter-contrib-codeclimate for examples.' \ '\n' % (abs_path, working_dir) - command = ['codeclimate', 'analyze', '${args}'] - if not (abs_path.startswith(os.path.abspath(working_dir) + os.sep)): logger.info(msg) return None - file = os.path.relpath(self.filename, self.get_working_dir()) - command.append(file) - command.append('${xoo}') - return command + file = os.path.relpath(abs_path, working_dir) + return ['codeclimate', 'analyze', '${args}', file, '${xoo}'] From 159dd24e909757b678c0b0fc8baea0831308fb8c Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 28 Dec 2020 00:03:58 +0100 Subject: [PATCH 13/19] Updated exception handling --- linter.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/linter.py b/linter.py index 81bbdb2..da40114 100644 --- a/linter.py +++ b/linter.py @@ -11,12 +11,8 @@ # """This module exports the Codeclimate plugin class.""" -import logging import os -from SublimeLinter.lint import Linter, util - - -logger = logging.getLogger('SublimeLinter.plugin.eslint') +from SublimeLinter.lint import Linter, PermanentError, util class Codeclimate(Linter): @@ -49,24 +45,13 @@ def cmd(self): abs_path = self.filename working_dir = self.get_working_dir() - msg = 'You try to lint the file %s from outside of SublimeText\'s ' \ - 'working directory (%s), which is not supported by this ' \ - 'SublimeLinter plugin at this time. You can do either:\n' \ - '* You open the directory containing the current file in' \ - 'a new window. You may have to add a customized ' \ - '`.codeclimate.yml` configuration to that directory ' \ - 'as well;\n' \ - '* You change the working directory of the linter plugin in ' \ - ' the global or the Project\'s settings;\n' \ - '* You disable the linter plugin in the global or the ' \ - 'Project\'s settings.\n\n' \ - 'Please visit https://github.com/codeclimate/' \ - 'SublimeLinter-contrib-codeclimate for examples.' \ - '\n' % (abs_path, working_dir) + msg = 'The file \'%s\' is not part of the working dir (%s). ' \ + 'Please see the Linter\'s README.md to get further ' \ + 'instructions.' % (abs_path, working_dir) if not (abs_path.startswith(os.path.abspath(working_dir) + os.sep)): - logger.info(msg) - return None + self.notify_unassign() + raise PermanentError(msg) file = os.path.relpath(abs_path, working_dir) return ['codeclimate', 'analyze', '${args}', file, '${xoo}'] From e19c4581acb5be016c519e07022d6a8522074987 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 28 Dec 2020 00:10:05 +0100 Subject: [PATCH 14/19] Updated linter regex (now multiline) --- linter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linter.py b/linter.py index da40114..5f290e5 100644 --- a/linter.py +++ b/linter.py @@ -33,8 +33,8 @@ class Codeclimate(Linter): 'text.html' ) } - regex = r'^(?P\d+)(?:-\d+)?:\s(?P.+)$' - multiline = False + regex = r'^== ((?P.*)(?= \(\d+ issue\) ==))( \(\d+ issue\) ==\n(?P\d+))(?:-\d+)?:\s(?P.+)$' + multiline = True line_col_base = (1, 1) tempfile_suffix = '-' error_stream = util.STREAM_BOTH From 987473f358f737907b0895610fa7fcf5ff467dcb Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 28 Dec 2020 00:13:06 +0100 Subject: [PATCH 15/19] Added exclusion if file is not in working dir --- linter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linter.py b/linter.py index 5f290e5..f7c2941 100644 --- a/linter.py +++ b/linter.py @@ -18,6 +18,7 @@ class Codeclimate(Linter): """Provides an interface to codeclimate.""" defaults = { + 'excludes': ['!${folder::}*'], 'selector': ( 'source.css, ' 'source.go, ' @@ -33,6 +34,7 @@ class Codeclimate(Linter): 'text.html' ) } + regex = r'^== ((?P.*)(?= \(\d+ issue\) ==))( \(\d+ issue\) ==\n(?P\d+))(?:-\d+)?:\s(?P.+)$' multiline = True line_col_base = (1, 1) From 8ec7aa6b6a59bd8662efe363f2f66dc602dcee0d Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 28 Dec 2020 00:17:45 +0100 Subject: [PATCH 16/19] Updated docs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e16a516..b10fa21 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Within Sublime Text, bring up the [Command Palette][cmd] and type `install`. Amo When the plugin list appears, type `codeclimate`. Among the entries you should see `SublimeLinter-contrib-codeclimate`. If that entry is not highlighted, use the keyboard or mouse to select it. ## How it works -If the first opened folder in SublimeText contains a `.codeclimate.yml` configuration file in its root, `codeclimate` will recognize this file's settings. +If the opened folder in SublimeText contains a `.codeclimate.yml` configuration file in its root, `codeclimate` will recognize this file's settings. Suppose the `codeclimate` CLI finds no configuration file in the folder root: In that case, it will automatically run the default inspections of `structure` and `duplication`. If you have a `.codeclimate.yml` configuration file in a different folder, you can set SublimeLinter's `working_dir` setting (please see examples). @@ -65,7 +65,7 @@ If you want to ignore the configuration of a `.codeclimate.yml`, for instance, Suppose you use a `.codeclimate.yml`-configuration file. In that case, the `codeclimate` CLI needs to be executed in your configuration file's directory. Otherwise, it can't detect your configuration and runs only the default analyzes. -SublimeLinter takes the (first) open folder (or the folder of a single opened file) as the working directory for executing its linter commands. You can change this behavior by setting the working directory of execution: +SublimeLinter takes the current file's root folder in SublimeText's sidebar as the working directory for executing its linter commands. You can change this behavior by setting the working directory of execution: ```json { From c44c78ad3c903e15273aa7ae45bb9c15488c2929 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 29 Dec 2020 21:16:44 +0100 Subject: [PATCH 17/19] Removed/Reverted folder exclusion --- linter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/linter.py b/linter.py index f7c2941..bba639c 100644 --- a/linter.py +++ b/linter.py @@ -18,7 +18,6 @@ class Codeclimate(Linter): """Provides an interface to codeclimate.""" defaults = { - 'excludes': ['!${folder::}*'], 'selector': ( 'source.css, ' 'source.go, ' From b7fa65184f8aa1de1087d5d6c6667efe1686b3cd Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 29 Dec 2020 21:17:38 +0100 Subject: [PATCH 18/19] Reverted regex pattern --- linter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linter.py b/linter.py index bba639c..15b004b 100644 --- a/linter.py +++ b/linter.py @@ -34,8 +34,8 @@ class Codeclimate(Linter): ) } - regex = r'^== ((?P.*)(?= \(\d+ issue\) ==))( \(\d+ issue\) ==\n(?P\d+))(?:-\d+)?:\s(?P.+)$' - multiline = True + regex = r'^(?P\d+)(?:-\d+)?:\s(?P.+)$' + multiline = False line_col_base = (1, 1) tempfile_suffix = '-' error_stream = util.STREAM_BOTH From 281e165fbf5bc070b78b5f184b4509694ebd2018 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 29 Dec 2020 21:49:37 +0100 Subject: [PATCH 19/19] Updated logging and error messages --- linter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/linter.py b/linter.py index 15b004b..ab8a160 100644 --- a/linter.py +++ b/linter.py @@ -11,10 +11,14 @@ # """This module exports the Codeclimate plugin class.""" +import logging import os from SublimeLinter.lint import Linter, PermanentError, util +logger = logging.getLogger('SublimeLinter.plugin.codeclimate') + + class Codeclimate(Linter): """Provides an interface to codeclimate.""" defaults = { @@ -46,13 +50,14 @@ def cmd(self): abs_path = self.filename working_dir = self.get_working_dir() - msg = 'The file \'%s\' is not part of the working dir (%s). ' \ - 'Please see the Linter\'s README.md to get further ' \ - 'instructions.' % (abs_path, working_dir) + msg = 'The file \'%s\' is not part of any open folder in ' \ + 'SublimeText. Please see the Linter\'s README.md to ' \ + 'get further instructions.' % (abs_path) if not (abs_path.startswith(os.path.abspath(working_dir) + os.sep)): + logger.warning(msg) self.notify_unassign() - raise PermanentError(msg) + raise PermanentError('File not part of an open folder in SublimeText.') file = os.path.relpath(abs_path, working_dir) return ['codeclimate', 'analyze', '${args}', file, '${xoo}']