How to use the nitpick.formats.JSONFormat function in nitpick

To help you get started, we’ve selected a few nitpick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andreoliwa / nitpick / src / nitpick / plugins / json.py View on Github external
def _check_contained_keys(self) -> YieldFlake8Error:
        json_fmt = JSONFormat(path=self.file_path)
        suggested_json = self.get_suggested_json(json_fmt.as_data)
        if not suggested_json:
            return
        yield self.flake8_error(8, " has missing keys:", JSONFormat(data=suggested_json).reformatted)
github andreoliwa / nitpick / src / nitpick / plugins / json.py View on Github external
def suggest_initial_contents(self) -> str:
        """Suggest the initial content for this missing file."""
        suggestion = self.get_suggested_json()
        return JSONFormat(data=suggestion).reformatted if suggestion else ""
github andreoliwa / nitpick / src / nitpick / plugins / json.py View on Github external
def _check_contained_keys(self) -> YieldFlake8Error:
        json_fmt = JSONFormat(path=self.file_path)
        suggested_json = self.get_suggested_json(json_fmt.as_data)
        if not suggested_json:
            return
        yield self.flake8_error(8, " has missing keys:", JSONFormat(data=suggested_json).reformatted)
github andreoliwa / nitpick / src / nitpick / plugins / json.py View on Github external
def _check_contained_json(self) -> YieldFlake8Error:
        actual_fmt = JSONFormat(path=self.file_path)
        expected = {}
        # TODO: accept key as a jmespath expression, value is valid JSON
        for key, json_string in (self.file_dict.get(KEY_CONTAINS_JSON) or {}).items():
            try:
                expected[key] = json.loads(json_string)
            except json.JSONDecodeError as err:
                # This should not happen, because the style was already validated before.
                # Maybe the NIP??? code was disabled by the user?
                LOGGER.error("%s on %s while checking %s", err, KEY_CONTAINS_JSON, self.file_path)
                continue

        yield from self.warn_missing_different(
            JSONFormat(data=actual_fmt.as_data).compare_with_dictdiffer(expected, unflatten)
        )