Beispiel #1
0
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
        """Prettier will use the closest configuration file to the file currently being formatted,
        so add all of them In the event of multiple configuration files, Prettier has an order of
        precedence specified here: https://prettier.io/docs/en/configuration.html."""

        config_files = (
            *[f"prettier.config{ext}" for ext in [".js", ".cjs"]],
            *[
                f".prettierrc{ext}"
                for ext in [
                    "",
                    ".json",
                    ".yml",
                    ".yaml",
                    ".json5",
                    ".js",
                    ".cjs",
                    ".toml",
                ]
            ],
        )
        check_existence = [os.path.join(d, file) for file in config_files for d in ("", *dirs)]
        return ConfigFilesRequest(
            discovery=True,
            check_existence=check_existence,
        )
Beispiel #2
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_existence=[".isort.cfg"],
         check_content={"pyproject.toml": b"[tool.isort]"},
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #3
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_existence=[".coveragerc"],
         check_content={"setup.cfg": b"[coverage:"},
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #4
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_existence=["mypy.ini", ".mypy.ini"],
         check_content={"setup.cfg": b"[mypy"},
         option_name="[mypy].config",
     )
Beispiel #5
0
 def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
     # Refer to https://editorconfig.org/#file-location for how config files are discovered.
     candidates = (os.path.join(d, ".editorconfig") for d in ("", *dirs))
     return ConfigFilesRequest(
         discovery=self.config_discovery,
         check_content={fp: b"[*.sh]"
                        for fp in candidates},
     )
Beispiel #6
0
 def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
     # Refer to https://www.mankier.com/1/shellcheck#RC_Files for how config files are
     # discovered.
     candidates = []
     for d in ("", *dirs):
         candidates.append(os.path.join(d, ".shellcheckrc"))
         candidates.append(os.path.join(d, "shellcheckrc"))
     return ConfigFilesRequest(discovery=self.config_discovery,
                               check_existence=candidates)
Beispiel #7
0
 def config_request(self) -> ConfigFilesRequest:
     # Refer to https://github.com/hadolint/hadolint#configure for how config files are
     # discovered.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=self.config_discovery,
         check_existence=[".hadolint.yaml", ".hadolint.yml"],
     )
Beispiel #8
0
 def config_request(self) -> ConfigFilesRequest:
     # Refer to https://twine.readthedocs.io/en/latest/#configuration for how config files are
     # discovered.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=self.config_discovery,
         check_existence=[".pypirc"],
     )
Beispiel #9
0
 def config_request(self) -> ConfigFilesRequest:
     # Refer to https://mypy.readthedocs.io/en/stable/config_file.html.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"{self.options_scope}.config",
         discovery=cast(bool, self.options.config_discovery),
         check_existence=["mypy.ini", ".mypy.ini"],
         check_content={"setup.cfg": b"[mypy"},
     )
Beispiel #10
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_existence=["pylintrc", ".pylinrc"],
         check_content={
             "pyproject.toml": b"[tool.pylint]",
             "setup.cfg": b"[pylint."
         },
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #11
0
 def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
     # Refer to https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#where-black-looks-for-the-file
     # for how Black discovers config.
     candidates = {os.path.join(d, "pyproject.toml"): b"[tool.black]" for d in ("", *dirs)}
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=self.config_discovery,
         check_content=candidates,
     )
Beispiel #12
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_existence=["flake8", ".flake8"],
         check_content={
             "setup.cfg": b"[flake8]",
             "tox.ini": b"[flake8]"
         },
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #13
0
 def config_request(self) -> ConfigFilesRequest:
     # See https://flake8.pycqa.org/en/latest/user/configuration.html#configuration-locations
     # for how Flake8 discovers config files.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=self.config_discovery,
         check_existence=["flake8", ".flake8"],
         check_content={"setup.cfg": b"[flake8]", "tox.ini": b"[flake8]"},
     )
Beispiel #14
0
 def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
     # Refer to http://pylint.pycqa.org/en/latest/user_guide/run.html#command-line-options for
     # how config files are discovered.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=self.config_discovery,
         check_existence=[".pylintrc", *(os.path.join(d, "pylintrc") for d in ("", *dirs))],
         check_content={"pyproject.toml": b"[tool.pylint.", "setup.cfg": b"[pylint."},
     )
Beispiel #15
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_existence=["pytest.ini"],
         check_content={
             "pyproject.toml": b"[tool.pytest.ini_options]",
             "tox.ini": b"[pytest]",
             "setup.cfg": b"[tool:pytest]",
         },
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #16
0
 def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
     """clang-format will use the closest configuration file to the file currently being
     formatted, so add all of them."""
     config_files = (
         ".clang-format",
         "_clang-format",
     )
     check_existence = [os.path.join(d, file) for file in config_files for d in ("", *dirs)]
     return ConfigFilesRequest(
         discovery=True,
         check_existence=check_existence,
     )
Beispiel #17
0
 def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
     # Refer to https://github.com/psf/black#where-black-looks-for-the-file for how Black
     # discovers config.
     candidates = {
         os.path.join(d, "pyproject.toml"): b"[tool.black]"
         for d in ("", *dirs)
     }
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=cast(bool, self.options.config_discovery),
         check_content=candidates,
     )
Beispiel #18
0
 def config_request(self) -> ConfigFilesRequest:
     # Refer to https://coverage.readthedocs.io/en/stable/config.html.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"[{self.options_scope}].config",
         discovery=cast(bool, self.options.config_discovery),
         check_existence=[".coveragerc"],
         check_content={
             "setup.cfg": b"[coverage:",
             "tox.ini": b"[coverage:]",
             "pyproject.toml": b"[tool.coverage",
         },
     )
Beispiel #19
0
 def warn(existence: list[str], content: dict[str, bytes]) -> None:
     caplog.clear()
     rule_runner.request(
         ConfigFiles,
         [
             ConfigFilesRequest(
                 specified=None,
                 check_existence=existence,
                 check_content=content,
                 option_name="[subsystem].config",
             )
         ],
     )
Beispiel #20
0
 def discover(
     existence: list[str], content: dict[str, bytes], *, specified: str | None = None
 ) -> tuple[str, ...]:
     return rule_runner.request(
         ConfigFiles,
         [
             ConfigFilesRequest(
                 specified=specified,
                 specified_option_name="foo",
                 discovery=True,
                 check_existence=existence,
                 check_content=content,
             )
         ],
     ).snapshot.files
Beispiel #21
0
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
        # Refer to https://docs.pytest.org/en/stable/customize.html#finding-the-rootdir for how
        # config files are discovered.
        check_existence = []
        check_content = {}
        for d in ("", *dirs):
            check_existence.append(os.path.join(d, "pytest.ini"))
            check_content[os.path.join(
                d, "pyproject.toml")] = b"[tool.pytest.ini_options]"
            check_content[os.path.join(d, "tox.ini")] = b"[pytest]"
            check_content[os.path.join(d, "setup.cfg")] = b"[tool:pytest]"

        return ConfigFilesRequest(
            discovery=cast(bool, self.options.config_discovery),
            check_existence=check_existence,
            check_content=check_content,
        )
Beispiel #22
0
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
        # Refer to https://github.com/google/yapf#formatting-style.
        check_existence = []
        check_content = {}
        for d in ("", *dirs):
            check_existence.append(os.path.join(d, ".yapfignore"))
            check_content.update({
                os.path.join(d, "pyproject.toml"): b"[tool.yapf",
                os.path.join(d, "setup.cfg"): b"[yapf]",
                os.path.join(d, ".style.yapf"): b"[style]",
            })

        return ConfigFilesRequest(
            specified=self.config,
            specified_option_name=f"[{self.options_scope}].config",
            discovery=cast(bool, self.options.config_discovery),
            check_existence=check_existence,
            check_content=check_content,
        )
Beispiel #23
0
    def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
        # Refer to https://pycqa.github.io/isort/docs/configuration/config_files/.
        check_existence = []
        check_content = {}
        for d in ("", *dirs):
            check_existence.append(os.path.join(d, ".isort.cfg"))
            check_content.update({
                os.path.join(d, "pyproject.toml"): b"[tool.isort]",
                os.path.join(d, "setup.cfg"): b"[isort]",
                os.path.join(d, "tox.ini"): b"[isort]",
                os.path.join(d, ".editorconfig"): b"[*.py]",
            })

        return ConfigFilesRequest(
            specified=self.config,
            specified_option_name=f"[{self.options_scope}].config",
            discovery=cast(bool, self.options.config_discovery),
            check_existence=check_existence,
            check_content=check_content,
        )
Beispiel #24
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=self.config,
         check_content={"pyproject.toml": b"[tool.black]"},
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #25
0
 def resolve(specified: list[str]) -> tuple[str, ...]:
     return rule_runner.request(
         ConfigFiles,
         [ConfigFilesRequest(specified=specified, specified_option_name="[subsystem].config")],
     ).snapshot.files
Beispiel #26
0
 def resolve(specified: list[str]) -> ConfigFiles:
     return rule_runner.request(ConfigFiles, [
         ConfigFilesRequest(specified=specified,
                            option_name="[subsystem].config")
     ])
Beispiel #27
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=cast("str | None", self.options.config),
         check_existence=[".shellcheckrc", "shellcheckrc"],
         option_name=f"[{self.options_scope}].config",
     )
Beispiel #28
0
 def config_request(self) -> ConfigFilesRequest:
     # Note that there are no default locations for Bandit config files.
     return ConfigFilesRequest(specified=self.config,
                               option_name=f"{self.options_scope}.config")
Beispiel #29
0
 def config_request(self) -> ConfigFilesRequest:
     # Refer to https://bandit.readthedocs.io/en/latest/config.html. Note that there are no
     # default locations for Bandit config files.
     return ConfigFilesRequest(
         specified=self.config,
         specified_option_name=f"{self.options_scope}.config")
Beispiel #30
0
 def config_request(self) -> ConfigFilesRequest:
     return ConfigFilesRequest(
         specified=cast("str | None", self.options.config),
         check_content={".editorconfig": b"[*.sh]"},
         option_name=f"[{self.options_scope}].config",
     )