
import re

import wlint.common
import wlint.punctuation


class PunctuationStyle(wlint.common.Tool):

    def __init__(self, description):
        super().__init__(description)
        self.checks = wlint.punctuation.PunctuationRules().rules

    def setup(self, arguments):
        self.result = 0

    def process(self, fileHandle):
        lineNumber = 0
        for text in fileHandle:
            lineNumber += 1
            for message, fn in self.checks.items():
                if fn(text, lambda pos: print(
                    "{}-{}:{} {}".format(fileHandle.name, lineNumber,
                                         pos, message))):
                    self.result = 1


punctuationStyle = PunctuationStyle("Check for common punctuation issues")
punctuationStyle.execute()
exit(punctuationStyle.result)


import operator

import wlint.common
import wlint.punctuation


class PunctuationStyle(wlint.common.Tool):

    def __init__(self, description):
        super().__init__(description)
        self.checks = wlint.punctuation.PunctuationRules().rules

    def setup(self, arguments):
        self.result = 0

    def process(self, fileHandle):
        lineNumber = 0
        hits = []
        for text in fileHandle:
            lineNumber += 1
            for message, fn in self.checks.items():
                if fn(text, lambda pos: hits.append(lineNumber, pos, message)):
                    self.result = 1

        hits.sort()
        for (line, col, message) in hits:
            print("{}-{}:{} {}".format(fileHandle.name, line, pos, message))


punctuationStyle = PunctuationStyle("Check for common punctuation issues")
punctuationStyle.execute()
exit(punctuationStyle.result)

Sort punctuation hits so output is based on line and column, not the order rules are checked
Sort punctuation hits so output is based on line and column, not the order rules are checked

  
- import re
+ import operator
  
  import wlint.common
  import wlint.punctuation
  
  
  class PunctuationStyle(wlint.common.Tool):
  
      def __init__(self, description):
          super().__init__(description)
          self.checks = wlint.punctuation.PunctuationRules().rules
  
      def setup(self, arguments):
          self.result = 0
  
      def process(self, fileHandle):
          lineNumber = 0
+         hits = []
          for text in fileHandle:
              lineNumber += 1
              for message, fn in self.checks.items():
+                 if fn(text, lambda pos: hits.append(lineNumber, pos, message)):
-                 if fn(text, lambda pos: print(
-                     "{}-{}:{} {}".format(fileHandle.name, lineNumber,
-                                          pos, message))):
                      self.result = 1
+ 
+         hits.sort()
+         for (line, col, message) in hits:
+             print("{}-{}:{} {}".format(fileHandle.name, line, pos, message))
  
  
  punctuationStyle = PunctuationStyle("Check for common punctuation issues")
  punctuationStyle.execute()
  exit(punctuationStyle.result)
  
Sort punctuation hits so output is based on line and column, not the order rules are checked
## Code Before:

import re

import wlint.common
import wlint.punctuation


class PunctuationStyle(wlint.common.Tool):

    def __init__(self, description):
        super().__init__(description)
        self.checks = wlint.punctuation.PunctuationRules().rules

    def setup(self, arguments):
        self.result = 0

    def process(self, fileHandle):
        lineNumber = 0
        for text in fileHandle:
            lineNumber += 1
            for message, fn in self.checks.items():
                if fn(text, lambda pos: print(
                    "{}-{}:{} {}".format(fileHandle.name, lineNumber,
                                         pos, message))):
                    self.result = 1


punctuationStyle = PunctuationStyle("Check for common punctuation issues")
punctuationStyle.execute()
exit(punctuationStyle.result)

## Instruction:
Sort punctuation hits so output is based on line and column, not the order rules are checked
## Code After:

import operator

import wlint.common
import wlint.punctuation


class PunctuationStyle(wlint.common.Tool):

    def __init__(self, description):
        super().__init__(description)
        self.checks = wlint.punctuation.PunctuationRules().rules

    def setup(self, arguments):
        self.result = 0

    def process(self, fileHandle):
        lineNumber = 0
        hits = []
        for text in fileHandle:
            lineNumber += 1
            for message, fn in self.checks.items():
                if fn(text, lambda pos: hits.append(lineNumber, pos, message)):
                    self.result = 1

        hits.sort()
        for (line, col, message) in hits:
            print("{}-{}:{} {}".format(fileHandle.name, line, pos, message))


punctuationStyle = PunctuationStyle("Check for common punctuation issues")
punctuationStyle.execute()
exit(punctuationStyle.result)
