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

Commit 65b3c79

Browse files
committed
Merge pull request #24 from evilhamsterman/master
Add support for configuration and removed executable check
2 parents 713a91d + 07f7a7d commit 65b3c79

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ This package will lint your opened Python-files in Atom, using [pylint](http://w
88
* `$ apm install linter` (if you don't have [AtomLinter/Linter](https://github.com/AtomLinter/Linter) installed).
99
* `$ apm install linter-pylint`
1010

11-
## Settings
12-
Linter-pylint offers currently no settings.
11+
## Configuration
12+
* **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
13+
* **RC File** Path to a custom pylintrc
1314

1415
## Other available linters
1516
There are other linters available - take a look at the linters [mainpage](https://github.com/AtomLinter/Linter).

lib/init.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
module.exports =
2+
config:
3+
executable:
4+
type: 'string'
5+
default: 'pylint'
6+
rcFile:
7+
type: 'string'
8+
default: ''
9+
210
activate: ->
311
console.log 'Linter-Pylint: package loaded,
412
ready to get initialized by AtomLinter.'

lib/linter-pylint.coffee

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ Linter = require "#{linterPath}/lib/linter"
55

66

77
class LinterPylint extends Linter
8-
@enabled = false # false until executable checked
98
@syntax: 'source.python' # fits all *.py-files
10-
cmd: ['pylint'
11-
"--msg-template='{line},{column},{category},{msg_id}:{msg}'"
12-
'--reports=n']
139

1410
linterName: 'pylint'
1511

@@ -19,35 +15,31 @@ class LinterPylint extends Linter
1915
regexFlags: 'm'
2016

2117
constructor: (@editor) ->
22-
super @editor # sets @cwd to the dirname of the current file
18+
super @editor
19+
20+
# sets @cwd to the dirname of the current file
2321
# if we're in a project, use that path instead
2422
@cwd = atom.project.path ? @cwd
25-
exec 'pylint --version', cwd: @cwd, @executionCheckHandler
26-
log 'Linter-Pylint: initialization completed'
27-
28-
# Private: handles the initial 'version' call, extracts the version and
29-
# enables the linter
30-
executionCheckHandler: (error, stdout, stderr) =>
31-
versionRegEx = /pylint(-script.py)? ([\d\.]+)\,/
32-
if not versionRegEx.test(stdout)
33-
result = if error? then '#' + error.code + ': ' else ''
34-
result += 'stdout: ' + stdout if stdout.length > 0
35-
result += 'stderr: ' + stderr if stderr.length > 0
36-
console.error "Linter-Pylint: 'pylint' was not executable: " + result
37-
else
38-
log "Linter-Pylint: found pylint " + versionRegEx.exec(stdout).slice(-1)[0]
39-
@enabled = true # everything is fine, the linter is ready to work
40-
41-
lintFile: (filePath, callback) =>
42-
if @enabled
43-
# Only lint when pylint is present
44-
super filePath, callback
45-
else
46-
# Otherwise it's important that we call @processMessage to avoid leaking
47-
# the temporary file.
48-
@processMessage "", callback
49-
50-
formatMessage: (match) ->
51-
"#{match.msg_id}: #{match.message}"
23+
24+
# Set to observe config options
25+
atom.config.observe 'linter-pylint.executable', => @updateCommand()
26+
atom.config.observe 'linter-pylint.rcFile', => @updateCommand()
27+
28+
destroy: ->
29+
atom.config.unobserve 'linter-pylint.executable'
30+
atom.config.unobserve 'linter-pylint.rcFile'
31+
32+
# Sets the command based on config options
33+
updateCommand: ->
34+
cmd = [atom.config.get 'linter-pylint.executable']
35+
cmd.push "--msg-template='{line},{column},{category},{msg_id}:{msg}'"
36+
cmd.push '--reports=n'
37+
38+
rcFile = atom.config.get 'linter-pylint.rcFile'
39+
if rcFile
40+
cmd.push "--rcfile=#{rcFile}"
41+
42+
@cmd = cmd
43+
5244

5345
module.exports = LinterPylint

0 commit comments

Comments
 (0)