├── .flake8 ├── .python-version ├── .travis.yml ├── LICENSE ├── README.md ├── linter.py ├── messages.json └── messages └── install.txt /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | 4 | # D100 Missing docstring in public module 5 | # D101 Missing docstring in public class 6 | # D102 Missing docstring in public method 7 | # D103 Missing docstring in public function 8 | # D104 Missing docstring in public package 9 | # D105 Missing docstring in magic method 10 | # D107 Missing docstring in __init__ 11 | ignore = D100,D101,D102,D103,D105,D107 12 | 13 | -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.6" 4 | install: 5 | - pip install flake8 6 | script: 7 | - flake8 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-phpmd 2 | ========================= 3 | 4 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [phpmd](http://phpmd.org/documentation/index.html). 5 | It will be used with files that have the "PHP", "HTML" and "HTML5" syntax. 6 | 7 | 8 | ## Installation 9 | 10 | ### Install `SublimeLinter` and `SublimeLinter-phpmd` 11 | 12 | Make sure [Package Control](https://packagecontrol.io) is installed. 13 | 14 | 1. Open the command palette (Ctrl + Shift + P) 15 | 2. Type **Package Control: Install Package** and select it. 16 | 3. Type **SublimeLinter** and select it. 17 | 4. Repeat steps 1-3 typing **SublimeLinter-phpmd** in step 3. 18 | 19 | ### Install `phpmd` 20 | 21 | Choose one of the installation methods below. 22 | 23 | A local install allows you to fine-tune `phpmd` on a per-project basis. A global install is available system-wide. 24 | 25 | #### Local install with [Composer](https://getcomposer.org/) 26 | 27 | On a command line inside your project: 28 | ```bash 29 | composer require phpmd/phpmd 30 | ``` 31 | 32 | #### Global install with [Composer](https://getcomposer.org/) 33 | 34 | ```bash 35 | composer global require phpmd/phpmd 36 | ``` 37 | 38 | Make sure the composer global bin directory is available in $PATH: 39 | 40 | ```bash 41 | export PATH=~/.composer/vendor/bin:$PATH 42 | ``` 43 | 44 | #### Global install with [PEAR](https://pear.php.net) 45 | 46 | ```bash 47 | pear channel-discover pear.phpmd.org 48 | pear channel-discover pear.pdepend.org 49 | pear install --alldeps phpmd/PHP_PMD 50 | ``` 51 | 52 | ## Settings 53 | 54 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 55 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 56 | 57 | ### Additional settings 58 | 59 | If you want to use a baseline file, the linter needs to run on the actual files instead of the temporary files we need for real-time "background" linting. 60 | Therefore, set the "real_file_mode" setting to true. 61 | 62 | ```json 63 | "linters": { 64 | "phpmd": { 65 | "real_file_mode": true 66 | } 67 | } 68 | ``` 69 | 70 | ### Rulesets 71 | 72 | You can configure rules via the `rulesets` setting. This can be a list of rules, or a path to a custom ruleset file. 73 | 74 | ```json 75 | "linters": { 76 | "phpmd": { 77 | "rulesets": "codesize,unusedcode,naming" 78 | } 79 | } 80 | ``` 81 | 82 | ```json 83 | "linters": { 84 | "phpmd": { 85 | "rulesets": "${folder}/phpmd.xml" 86 | } 87 | } 88 | ``` 89 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | from SublimeLinter.lint import PhpLinter, WARNING 2 | 3 | 4 | class Phpmd(PhpLinter): 5 | regex = ( 6 | r'(.+):(?P\d+)\s*(?P.+)$' 7 | ) 8 | on_stderr = None # handle stderr via regex 9 | default_type = WARNING 10 | tempfile_suffix = 'php' 11 | defaults = { 12 | 'real_file_mode': False, 13 | 'selector': 'embedding.php, source.php', 14 | '@rulesets:,': 'cleancode,codesize,controversial,design,naming,unusedcode' 15 | } 16 | 17 | @classmethod 18 | def should_lint(cls, view, settings, reason): 19 | # type: (sublime.View, LinterSettings, Reason) -> bool 20 | """Decide whether the linter can run at this point in time.""" 21 | if settings['real_file_mode'] and ( 22 | view.is_dirty() or not view.file_name() 23 | ): 24 | return False 25 | 26 | return super().should_lint(view, settings, reason) 27 | 28 | def cmd(self): 29 | target = '$file_on_disk' if self.settings['real_file_mode'] else '$temp_file' 30 | self.tempfile_suffix = '-' if self.settings['real_file_mode'] else 'php' 31 | return ('phpmd', target, 'text') 32 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt" 3 | } 4 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-phpmd 2 | ------------------------------- 3 | 4 | This linter plugin for SublimeLinter provides an interface to phpmd. 5 | 6 | For more information, please see 7 | https://github.com/SublimeLinter/SublimeLinter-phpmd. 8 | --------------------------------------------------------------------------------