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.FilledString, fields.String()) present = fields.Dict(fields.FilledString, fields.String()) # TODO: load this schema dynamically, then add this next field setup_cfg setup_cfg = fields.Nested(SetupCfgSchema, data_key=SetupCfgFile.file_name)
def file_field_pair(file_name: str, base_file_class: Type[NitpickPlugin]) -> Dict[str, fields.Field]: """Return a schema field with info from a config file class.""" valid_toml_key = TOMLFormat.group_name_for(file_name) unique_file_name_with_underscore = slugify(file_name, separator="_") kwargs = {"data_key": valid_toml_key} if base_file_class.validation_schema: field = fields.Nested(base_file_class.validation_schema, **kwargs) else: # For default files (pyproject.toml, setup.cfg...), there is no strict schema; # it can be anything they allow. # It's out of Nitpick's scope to validate those files. field = fields.Dict(fields.String, **kwargs) return {unique_file_name_with_underscore: field}
def file_field_pair( filename: str, base_file_class: type[NitpickPlugin]) -> dict[str, fields.Field]: """Return a schema field with info from a config file class.""" unique_filename_with_underscore = slugify(filename, separator="_") kwargs = {"data_key": filename} if base_file_class.validation_schema: file_field = fields.Nested(base_file_class.validation_schema, **kwargs) else: # For some files (e.g.: TOML/ INI files), there is no strict schema; # it can be anything they allow. # It's out of Nitpick's scope to validate those files. file_field = fields.Dict(fields.String, **kwargs) return {unique_filename_with_underscore: file_field}
class JSONFileSchema(BaseNitpickSchema): """Validation schema for any JSON file added to the style.""" contains_keys = fields.List(fields.FilledString) contains_json = fields.Dict(fields.FilledString, fields.JSONString)