Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Add option to configure the format of linter messages #47

Merged
merged 4 commits into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This package will lint your opened Python-files in Atom, using [pylint](http://w
## Configuration
* **Executable** Path to your pylint executable. This is useful if you have different versions of pylint for Python 2 and 3 or if you are using a virtualenv
* **RC File** Path to a custom pylintrc
* **Message Format** The format of the linter messages. It may include `%s`
and `%i` for the Pylint human-readable and numeric message IDs.

## Other available linters
There are other linters available - take a look at the linters [mainpage](https://github.com/AtomLinter/Linter).
Expand Down
7 changes: 7 additions & 0 deletions lib/init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ module.exports =
rcFile:
type: 'string'
default: ''
messageFormat:
type: 'string'
default: '%m'
description:
'Format for Pylint messages where %m is the message, %i is the
numeric mesasge ID (e.g. W0613) and %s is the human-readable
message ID (e.g. unused-argument).'

activate: ->
console.log 'Linter-Pylint: package loaded,
Expand Down
7 changes: 6 additions & 1 deletion lib/linter-pylint.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ class LinterPylint extends Linter
# Set to observe config options
@executableListener = atom.config.observe 'linter-pylint.executable', => @updateCommand()
@rcFileListener = atom.config.observe 'linter-pylint.rcFile', => @updateCommand()
@messageFormatListener = atom.config.observe 'linter-pylint.messageFormat', => @updateCommand()

destroy: ->
super
@executableListener.dispose()
@rcFileListener.dispose()
@messageFormat.dispose()

# Sets the command based on config options
updateCommand: ->
format = atom.config.get 'linter-pylint.messageFormat'
for pattern, value of {'%m': 'msg', '%i': 'msg_id', '%s': 'symbol'}
format = format.replace(new RegExp(pattern, 'g'), "{#{value}}")
cmd = [atom.config.get 'linter-pylint.executable']
cmd.push "--msg-template='{line},{column},{category},{msg_id}:{msg}'"
cmd.push "--msg-template='{line},{column},{category},{msg_id}:#{format}'"
cmd.push '--reports=n'
cmd.push '--output-format=text'

Expand Down