This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Update: Use latest linter API #55
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{CompositeDisposable} = require 'atom' | ||
helpers = require 'atom-linter' | ||
path = require 'path' | ||
_ = require 'lodash' | ||
os = require 'os' | ||
|
||
module.exports = | ||
config: | ||
executable: | ||
type: 'string' | ||
default: 'pylint' | ||
description: 'Command or path to executable.' | ||
pythonPath: | ||
type: 'string' | ||
default: '' | ||
description: 'Paths to be added to $PYTHONPATH. Use %p for current project directory (no trailing /).' | ||
rcFile: | ||
type: 'string' | ||
default: '' | ||
description: 'Path to .pylintrc file.' | ||
messageFormat: | ||
type: 'string' | ||
default: '%i %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: -> | ||
@subscriptions = new CompositeDisposable | ||
@subscriptions.add atom.config.observe 'linter-pylint.executable', | ||
(newExecutableValue) => | ||
@executable = newExecutableValue | ||
@subscriptions.add atom.config.observe 'linter-pylint.rcFile', | ||
(newRcFileValue) => | ||
@rcFile = newRcFileValue | ||
@subscriptions.add atom.config.observe 'linter-pylint.messageFormat', | ||
(newMessageFormatValue) => | ||
@messageFormat = newMessageFormatValue | ||
@subscriptions.add atom.config.observe 'linter-pylint.pythonPath', | ||
(newPythonPathValue) => | ||
@pythonPath = _.trim newPythonPathValue, path.delimiter | ||
|
||
@regex = '^(?<line>\\d+),(?<col>\\d+),\ | ||
(?<type>\\w+),\ | ||
(\\w\\d+):(?<message>.*)$' | ||
|
||
@errorWhitelist = [ | ||
/^No config file found, using default configuration$/ | ||
] | ||
|
||
deactivate: -> | ||
@subscriptions.dispose() | ||
|
||
provideLinter: -> | ||
provider = | ||
grammarScopes: ['source.python'] | ||
scope: 'file' | ||
lintOnFly: true | ||
lint: (activeEditor) => | ||
file = activeEditor.getPath() | ||
return helpers.tempFile path.basename(file), activeEditor.getText(), (tmpFilename) => | ||
projDir = @getProjDir(file) | ||
cwd = projDir | ||
pythonPath = @pythonPath.replace(/%p/g, projDir) | ||
env = Object.create process.env, | ||
PYTHONPATH: | ||
value: _.compact([process.env.PYTHONPATH, projDir, pythonPath]).join path.delimiter | ||
format = @messageFormat | ||
for pattern, value of {'%m': 'msg', '%i': 'msg_id', '%s': 'symbol'} | ||
format = format.replace(new RegExp(pattern, 'g'), "{#{value}}") | ||
args = [ | ||
"--msg-template='{line},{column},{category},{msg_id}:#{format}'" | ||
'--reports=n' | ||
'--output-format=text' | ||
] | ||
if @rcFile | ||
args.push "--rcfile=#{@rcFile}" | ||
args.push tmpFilename | ||
return helpers.exec(@executable, args, {env: env, cwd: cwd, stream: 'both'}).then (data) => | ||
filteredErrors = @filterWhitelistedErrors(data.stderr) | ||
throw new Error(filteredErrors) if filteredErrors | ||
helpers.parse(data.stdout, @regex, {filePath: file}) | ||
.filter((lintIssue) ->lintIssue.type isnt 'info') | ||
.map (lintIssue) -> | ||
[[lineStart, colStart], [lineEnd, colEnd]] = lintIssue.range | ||
if lineStart == lineEnd and colStart <= colEnd <= 0 | ||
return _.merge {}, lintIssue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
range: helpers.rangeFromLineNumber activeEditor, lineStart, colStart | ||
lintIssue | ||
|
||
getProjDir: (filePath) -> | ||
_.find atom.project.getPaths(), (projPath) -> | ||
filePath.indexOf(projPath) == 0 | ||
|
||
filterWhitelistedErrors: (output) -> | ||
outputLines = _.compact output.split(os.EOL) | ||
filteredOutputLines = _.reject outputLines, (outputLine) => | ||
_.some @errorWhitelist, (errorRegex) -> | ||
errorRegex.test outputLine | ||
|
||
filteredOutputLines.join os.EOL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
{ | ||
"name": "linter-pylint", | ||
"linter-package": true, | ||
"main": "./lib/init", | ||
"main": "./lib/main", | ||
"version": "0.2.2", | ||
"description": "Lint python on the fly, using pylint", | ||
"repository": "https://github.com/AtomLinter/linter-pylint", | ||
"license": "MIT", | ||
"engines": { | ||
"atom": ">0.50.0" | ||
"atom": ">=1" | ||
}, | ||
"dependencies": {} | ||
"providedServices": { | ||
"linter": { | ||
"versions": { | ||
"1.0.0": "provideLinter" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"atom-linter": "^3.2.0", | ||
"lodash": "^3.10.1" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't pylint automatically search for rc file in the file tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be useful to be able to use a rc file that lives in a different location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, then I am neutral on the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was part of keeping feature and behavior parity with the current version. In general it seems ok to expose often used cli flags via the config. I'm also neutral though 😁