# eric7.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker

Module implementing the code style checker.

### Global Attributes

None

### Classes

CodeStyleCheckerReport | Class implementing a special report to be used with our dialog.

### Functions

__checkCodeStyle | Private module function to perform the source code style check and/or fix found errors.
__checkSyntax | Private module function to perform a syntax check.
codeStyleBatchCheck | Module function to check source code style for a batch of files.
codeStyleCheck | Do the source code style check and/or fix found errors.
extractLineFlags | Function to extract flags starting and ending with '__' from a line comment.
ignoreCode | Function to check, if the given code should be ignored as per line flags.
initBatchService | Initialize the batch service and return the entry point.
initService | Initialize the service and return the entry point.
securityOk | Function to check, if the given error code is an acknowledged security report.
workerTask | Module function acting as the parallel worker for the style check.

## CodeStyleCheckerReport

Class implementing a special report to be used with our dialog.

### Derived from

pycodestyle.BaseReport

### Class Attributes

None

### Class Methods

None

### Methods

CodeStyleCheckerReport | Constructor
error_args | Public method to collect the error messages.

### Static Methods

None

#### CodeStyleCheckerReport (Constructor)

CodeStyleCheckerReport(options)

Constructor

options (optparse.Values)
  options for the report

#### CodeStyleCheckerReport.error_args

error_args(line_number, offset, errorCode, check, *args)

Public method to collect the error messages.

line_number (int)
  line number of the issue
offset (int)
  position within line of the issue
errorCode (str)
  error message code
check (function)
  reference to the checker function
args (list)
  arguments for the message

Return:
  error code

Return Type:
  str

Up

## __checkCodeStyle

__checkCodeStyle(filename, source, args)

Private module function to perform the source code style check and/or fix found errors.

filename (str)
  source filename
source (list of str)
  list of code lines to be checked
args (list of (str, str, bool, str, str, bool, int, list of (int, int),)
  arguments used by the codeStyleCheck function (list of excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, hangClosing, docType, codeComplexityArgs, miscellaneousArgs, annotationArgs, securityArgs, importsArgs, nameOrderArgs, unusedArgs, errors, eol, encoding, backup) bool, str, dict, dict, dict, dict, dict, dict, list of str, str, str, bool)

Return:
  tuple of statistics data and list of result dictionaries with keys:
  - file: file name
  - line: line_number
  - offset: offset within line
  - code: error message code
  - args: list of arguments to format the message
  - ignored: flag indicating this issue was ignored
  - fixed: flag indicating this issue was fixed
  - autofixing: flag indicating that a fix can be done
  - fixcode: message code for the fix
  - fixargs: list of arguments to format the fix message

Return Type:
  tuple of (dict, list of dict)

Up

## __checkSyntax

__checkSyntax(filename, source)

Private module function to perform a syntax check.

filename (str)
  source filename
source (list of str)
  list of code lines to be checked

Return:
  tuple containing the error dictionary with syntax error details, a statistics dictionary and None or a tuple containing two None and the generated AST tree

Return Type:
  tuple of (dict, dict, None) or tuple of (None, None, ast.Module)

Up

## codeStyleBatchCheck

codeStyleBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0)

Module function to check source code style for a batch of files.

argumentsList (list)
  list of arguments tuples as given for codeStyleCheck
send (func)
  reference to send function
fx (str)
  registered service name
cancelled (func)
  reference to function checking for a cancellation
maxProcesses (int)
  number of processes to be used

Up

## codeStyleCheck

codeStyleCheck(filename, source, args)

Do the source code style check and/or fix found errors.

filename (str)
  source filename
source (list of str)
  list of code lines to be checked
args (list of (str, str, bool, str, str, bool, int, list of (int, int),)
  arguments used by the codeStyleCheck function (list of excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, hangClosing, docType, codeComplexityArgs, miscellaneousArgs, annotationArgs, securityArgs, importsArgs, nameOrderArgs, unusedArgs, errors, eol, encoding, backup) bool, str, dict, dict, dict, dict, dict, dict, list of str, str, str, bool)

Return:
  tuple of statistics (dict) and list of results (tuple for each found violation of style (lineno, position, text, ignored, fixed, autofixing, fixedMsg))

Return Type:
  tuple of (dict, list of tuples of (int, int, str, bool, bool, bool, str))

Up

## extractLineFlags

extractLineFlags(line, startComment=")

Function to extract flags starting and ending with '__' from a line comment.

line (str)
  line to extract flags from
startComment (str)
  string identifying the start of the comment
endComment (str)
  string identifying the end of a comment
flagsLine (bool)
  flag indicating to check for a flags only line

Return:
  list containing the extracted flags

Return Type:
  list of str

Up

## ignoreCode

ignoreCode(errorCode, lineFlags)

Function to check, if the given code should be ignored as per line flags.

errorCode (str)
  error code to be checked
lineFlags (list of str)
  list of line flags to check against

Return:
  flag indicating to ignore the error code

Return Type:
  bool

Up

## initBatchService

initBatchService()

Initialize the batch service and return the entry point.

Return:
  the entry point for the background client

Return Type:
  function

Up

## initService

initService()

Initialize the service and return the entry point.

Return:
  the entry point for the background client

Return Type:
  function

Up

## securityOk

securityOk(errorCode, lineFlags)

Function to check, if the given error code is an acknowledged security report.

errorCode (str)
  error code to be checked
lineFlags (list of str)
  list of line flags to check against

Return:
  flag indicating an acknowledged security report

Return Type:
  bool

Up

## workerTask

workerTask(inputQueue, outputQueue)

Module function acting as the parallel worker for the style check.

inputQueue (multiprocessing.Queue)
  input queue
outputQueue (multiprocessing.Queue)
  output queue

Up