Skip to content

Commit

Permalink
Merge pull request #58 from SublimeLinter/sqiggle-position
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Feb 6, 2023
2 parents 5b2de02 + 90e01b6 commit 1028085
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os
import shutil
import re
import tempfile
import time
import threading
Expand All @@ -26,7 +27,8 @@

MYPY = False
if MYPY:
from typing import Dict, DefaultDict, Iterator, List, Optional, Protocol
from typing import Dict, DefaultDict, Iterator, List, Optional, Protocol, Tuple
from SublimeLinter.lint.linter import VirtualView

class TemporaryDirectory(Protocol):
name = None # type: str
Expand Down Expand Up @@ -154,6 +156,31 @@ def find_errors(self, output):
errors.append(error)
yield from errors

def reposition_match(self, line, col, m, vv):
# type: (int, Optional[int], LintMatch, VirtualView) -> Tuple[int, int, int]
message = m['message']
if message.startswith('Unused "type: ignore'):
text = vv.select_line(line)
# Search for the type comment on the actual line in the buffer
match = re.search(r"#\s*type:\s*ignore(\[.+])?", text)
if match:
# Probably select the whole type comment
a, b = match.span()
# When we have a specific rule in the error,
# e.g. 'Unused "type: ignore[import]" comment'
match = re.search(r"type:\s*ignore\[([^,]+)]", message)
if match:
# Grab the rulename,
rulename = match.group(1)
try:
# ... and find it in the type comment
a = text[a:b].index(rulename) + a
b = a + len(rulename)
except ValueError:
pass
return line, a, b
return super().reposition_match(line, col, m, vv)


class FakeTemporaryDirectory:
def __init__(self, name):
Expand Down

0 comments on commit 1028085

Please sign in to comment.