def getFirstBracketError(self, view):

    opener = list("({[")
    closer = list(")}]")

    matchingStack = []
    successResult = BracketResult(True, -1, -1)
    codeStr = view.substr(sublime.Region(0, view.size()))

    for index, char in enumerate(codeStr):

      # this leaks memory ?
      # if len(codeStr) != view.size():
      #   return successResult

      if char not in opener and not char in closer:
        continue

      scopeName = view.scope_name(index)
      hasScope = lambda s: s in scopeName

      # workaround for the following code in markdown: ![example](img/example.png)
      markdownBracketScopeBegin = "punctuation.definition.string.begin.markdown"
      markdownBracketScopeEnd = "punctuation.definition.string.end.markdown"
      isMarkdownStringBeginOrEnd = lambda s: hasScope(markdownBracketScopeBegin) or hasScope(markdownBracketScopeEnd)

      if hasScope("string") and not hasScope("unquoted") and not isMarkdownStringBeginOrEnd(markdownBracketScopeBegin) or hasScope("comment"):
        # ignore unmatched brackets in strings and comments
        continue

      if opener in char:
        matchingStack.append(BracketPosition(index, char))
      elif char in closer:
        matchingOpener = opener[closer.index(char)]

        if len(matchingStack) == 0:
          return BracketResult(False, -1, index)

        poppedOpener = matchingStack.pop()
        if matchingOpener != poppedOpener.opener:
          return BracketResult(False, poppedOpener.position, index)


    if len(matchingStack) == 0:
      return successResult
    else:
      poppedOpener = matchingStack.pop()
      return BracketResult(False, poppedOpener.position, -1)
dataset/ETHPy150Open philippotto/Sublime-BracketGuard/BracketGuard.py/EventListener.getFirstBracketError/swapped operands of `in`