Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from nitpick.formats import JSONFormat
from nitpick.generic import flatten, unflatten
from nitpick.plugins import hookimpl
from nitpick.plugins.base import NitpickPlugin
from nitpick.schemas import BaseNitpickSchema
from nitpick.typedefs import JsonDict, YieldFlake8Error
KEY_CONTAINS_KEYS = "contains_keys"
KEY_CONTAINS_JSON = "contains_json"
LOGGER = logging.getLogger(__name__)
class JSONFileSchema(BaseNitpickSchema):
"""Validation schema for any JSON file added to the style."""
contains_keys = fields.List(fields.NonEmptyString)
contains_json = fields.Dict(fields.NonEmptyString, fields.JSONString)
class JSONPlugin(NitpickPlugin):
"""Checker for any JSON file.
Add the configurations for the file name you wish to check.
Example: :ref:`the default config for package.json `.
"""
error_base_number = 340
validation_schema = JSONFileSchema
identify_tags = {"json"}
SOME_VALUE_PLACEHOLDER = ""
clean_sentence = sentence.strip(" .")
return "{}. See {}{}.".format(clean_sentence, READ_THE_DOCS_URL, help_page)
class BaseNitpickSchema(Schema):
"""Base schema for all others, with default error messages."""
error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html")}
class ToolNitpickSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[tool.nitpick]`` section on ``pyproject.toml``."""
error_messages = {"unknown": help_message("Unknown configuration", "tool_nitpick_section.html")}
style = PolyField(deserialization_schema_selector=fields.string_or_list_field)
class NitpickStylesSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[nitpick.styles]`` section on the style file."""
error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html#nitpick-styles")}
include = PolyField(deserialization_schema_selector=fields.string_or_list_field)
class SetupCfgSchema(BaseNitpickSchema):
"""Validation schema for setup.cfg."""
error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html#comma-separated-values")}
comma_separated_values = fields.List(fields.String(validate=fields.validate_section_dot_field))
from nitpick import fields
from nitpick.plugins import hookimpl
from nitpick.plugins.base import NitpickPlugin
from nitpick.schemas import help_message
from nitpick.typedefs import JsonDict, YieldFlake8Error
LOGGER = logging.getLogger(__name__)
TEXT_FILE_RTFD_PAGE = "config_files.html#text-files"
class TextItemSchema(Schema):
"""Validation schema for the object inside ``contains``."""
error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)}
line = fields.NonEmptyString()
class TextSchema(Schema):
"""Validation schema for the text file TOML configuration."""
error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)}
contains = fields.List(fields.Nested(TextItemSchema))
class TextPlugin(NitpickPlugin):
"""Checker for text files.
To check if ``some.txt`` file contains the lines ``abc`` and ``def`` (in any order):
.. code-block:: toml
class NitpickStylesSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[nitpick.styles]`` section on the style file."""
error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html#nitpick-styles")}
include = PolyField(deserialization_schema_selector=fields.string_or_list_field)
class SetupCfgSchema(BaseNitpickSchema):
"""Validation schema for setup.cfg."""
error_messages = {"unknown": help_message("Unknown configuration", "nitpick_section.html#comma-separated-values")}
comma_separated_values = fields.List(fields.String(validate=fields.validate_section_dot_field))
class NitpickFilesSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[nitpick.files]`` section on the style file."""
error_messages = {"unknown": help_message("Unknown file", "nitpick_section.html#nitpick-files")}
absent = fields.Dict(fields.NonEmptyString, fields.String())
present = fields.Dict(fields.NonEmptyString, fields.String())
# TODO: load this schema dynamically, then add this next field setup_cfg
setup_cfg = fields.Nested(SetupCfgSchema, data_key=SetupCfgPlugin.file_name)
class NitpickSectionSchema(BaseNitpickSchema):
"""Validation schema for the ``[nitpick]`` section on the style file."""