Checker¶
Entry point to the app.
Writing new plugin¶
First of all, you have to decide:
- Are you writing a separate plugin and adding it as a dependency?
- Are you writing an built-in extension to this styleguide?
How to make a decision?
Will this plugin be useful to other developers without this styleguide?¶
If so, it would be wise to create a separate flake8
plugin.
Then you can add newly created plugin as a dependency.
Our rules do not make any sense without each other.
Real world examples:
Can this plugin be used with the existing checker?¶
flake8
has a very strict API about plugins.
Here are some problems that you may encounter:
- Some plugins are called once per file, some are called once per line
- Plugins should define clear
violation code
/checker
relation - It is impossible to use the same letter violation codes for several checkers
Real world examples:
Writing new visitor¶
If you are still willing to write a builtin extension to our styleguide, you will have to write a violation and/or visitor.
Checker API¶
-
class
Checker
(tree, file_tokens, filename='stdin')[source]¶ Bases:
object
Main checker class.
It is an entry point to the whole app.
-
name
¶ required by the
flake8
API, should match the package name.
-
version
¶ required by the
flake8
API, defined in the packaging file.
-
config
¶ custom configuration object used to provide and parse options.
-
options
¶ option structure passed by
flake8
.
-
visitors
¶ sequence of visitors that we run with this checker.
-
__init__
(tree, file_tokens, filename='stdin')[source]¶ Creates new checker instance.
These parameter names should not be changed.
flake8
has special API that passes concrete parameters to the plugins that ask for them.flake8
also decides how to execute this plugin based on its parameters. This one is executed once per module.Parameters: - tree (
AST
) –ast
parsed byflake8
. Differs fromast.parse
. - file_tokens (
Sequence
[TokenInfo
]) –tokenize.tokenize
parsed file tokens. - filename (
str
) – module file name, might be empty if piping is used.
Return type: None
- tree (
-
classmethod
add_options
(parser)[source]¶ flake8
api method to register new plugin options.See
Configuration
docs for detailed options reference.Parameters: parser ( OptionManager
) –flake8
option parser instance.Return type: None
-
classmethod
parse_options
(options)[source]¶ Parses registered options for providing them to each visitor.
Return type: None
-
run
()[source]¶ Runs the checker.
This method is used by
flake8
API. It is executed after all configuration is parsed.Return type: Generator
[Tuple
[int
,int
,str
,type
],None
,None
]
-
__weakref__
¶ list of weak references to the object (if defined)
-