Document your code
Every project on GitHub comes with a version-controlled wiki to give your documentation the high level of care it deserves. It’s easy to create well-maintained, Markdown or rich text documentation alongside your code.
Sign up for free See pricing for teams and enterprisesHow to Write a Plugin
Firstly import Plugin
from text_validator.base
:
from text_validator.base import Plugin
Then write a subclass of Plugin
that implements one or more of the following methods:
-
validate_line(self, filename, line_num, line)
— called for every line -
validate_first_line(self, filename, line_num, line)
— called for just the first line -
validate_last_line(self, filename, line_num, line)
— called for just the last line
The filename
and line_num
parameters contain the filename and line number.
The line
parameter contains the line to validate. Note that this is passed in as bytes so any string-based validation will need to decode it.
Any configuration parameters for the plugin from the TOML file are available on self.config
. For example:
if self.config.get("CHECK_TABS"):
...
To report an error on the line, call self.error_callback(filename, line_num, offset, message)
.
Finally, set a module-level variable plugin
to the Plugin
subclass you just defined. Your plugin is then referenced by the module name only.
In other words if your plugin is MyValidator
in module foo.my_validator
, then foo/my_validator.py
should define class MyValidator(Plugin)
and end with the line:
plugin = MyValidator
In the TOML file, it would be referred to as ["foo.my_validator"]