src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9653
e67609152c5e
equal deleted inserted replaced
9481:0b936ff1bbb9 9482:a2bc06a54d9d
5 5
6 """ 6 """
7 Module implementing a class to fix certain code style issues. 7 Module implementing a class to fix certain code style issues.
8 """ 8 """
9 9
10 import codecs
10 import contextlib 11 import contextlib
11 import os 12 import os
12 import re 13 import re
14 import textwrap
13 import tokenize 15 import tokenize
14 16
15 from io import StringIO 17 from io import StringIO
16 18
17 # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues which fails 19 # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues which fails
267 Public method to save the modified file. 269 Public method to save the modified file.
268 270
269 @param encoding encoding of the source file (string) 271 @param encoding encoding of the source file (string)
270 @return error message on failure (tuple of str) 272 @return error message on failure (tuple of str)
271 """ 273 """
272 import codecs
273
274 if not self.__modified: 274 if not self.__modified:
275 # no need to write 275 # no need to write
276 return None 276 return None
277 277
278 if self.__createBackup: 278 if self.__createBackup:
2740 and not newText[-1].isalnum() 2740 and not newText[-1].isalnum()
2741 ): 2741 ):
2742 # Trim comments that end with things like --------- 2742 # Trim comments that end with things like ---------
2743 return newText[:maxLength] + self.__eol 2743 return newText[:maxLength] + self.__eol
2744 elif isLast and re.match(r"\s*#+\s*\w+", newText): 2744 elif isLast and re.match(r"\s*#+\s*\w+", newText):
2745 import textwrap
2746
2747 splitLines = textwrap.wrap( 2745 splitLines = textwrap.wrap(
2748 newText.lstrip(" \t#"), 2746 newText.lstrip(" \t#"),
2749 initial_indent=indentation, 2747 initial_indent=indentation,
2750 subsequent_indent=indentation, 2748 subsequent_indent=indentation,
2751 width=maxLength, 2749 width=maxLength,

eric ide

mercurial