Skip to content
Closed
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
43 changes: 43 additions & 0 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
import logging
import re
import os
from itertools import chain, takewhile
from SublimeLinter.lint import PythonLinter


logger = logging.getLogger('SublimeLinter.plugins.pylint')

HOME = os.path.expanduser('~')


def paths_upwards(path):
while True:
yield path

next_path = os.path.dirname(path)
# Stop just before root in *nix systems
if next_path == '/':
return

if next_path == path:
return

path = next_path


def paths_upwards_until_home(path):
return chain(takewhile(lambda p: p != HOME, paths_upwards(path)), [HOME])


def find_project_root(src):
"""Attempt to get the project root."""
for src in paths_upwards_until_home(src):
if os.path.exists(os.path.join(src, ".pylintrc")):
return src

if os.path.exists(os.path.join(src, "pyproject.toml")):
return src

if os.path.exists(os.path.join(src, ".git")):
return src

if os.path.exists(os.path.join(src, ".hg")):
return src

return src


class Pylint(PythonLinter):
regex = (
Expand Down Expand Up @@ -44,6 +85,8 @@ def cmd(self):
]
settings['init-hook'] = commands

self.context['project_root'] = find_project_root(self.view.file_name())

return (
'pylint',
'--msg-template=\'{line}:{column}:{msg_id}: {msg} ({symbol})\'',
Expand Down