Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possible choices in the generated toml doc #8949

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/exts/pylint_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def _create_checker_section(
checker_table.add(tomlkit.nl())
continue

# Display possible choices
choices = option.optdict.get("choices", "")
if choices:
checker_table.add(tomlkit.comment(f"Possible choices: {choices}"))

# Tomlkit doesn't support regular expressions
if isinstance(value, re.Pattern):
value = value.pattern
Expand Down Expand Up @@ -153,11 +158,8 @@ def _write_options_page(options: OptionsDataDict, linter: PyLinter) -> None:
sections.append(_create_checker_section(checker, checker_options, linter))

sections_string = "\n\n".join(sections)
with open(
PYLINT_USERGUIDE_PATH / "configuration" / "all-options.rst",
"w",
encoding="utf-8",
) as stream:
all_options_path = PYLINT_USERGUIDE_PATH / "configuration" / "all-options.rst"
with open(all_options_path, "w", encoding="utf-8") as stream:
stream.write(
f"""

Expand Down
15 changes: 15 additions & 0 deletions doc/user_guide/configuration/all-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,12 @@ Standard Checkers
.. code-block:: toml

[tool.pylint.basic]
# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps these could be enums - making the possible values a bit easier to maintain?
for example:

from enum import StrEnum


class NamingStyle(StrEnum):
    SNAKE_CASE: "snake_case"
    CAMEL_CASE: "camelCase"
    ...

attr-naming-style = NamingStyle.SNAKE_CASE.value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do a refactor in another MR if necessary but I think it's internal so only pylint dev are using this and I feel like it's working well enough.

argument-naming-style = "snake_case"

# argument-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
attr-naming-style = "snake_case"

# attr-rgx =
Expand All @@ -550,24 +552,29 @@ Standard Checkers

bad-names-rgxs = []

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
class-attribute-naming-style = "any"

# class-attribute-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
class-const-naming-style = "UPPER_CASE"

# class-const-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
class-naming-style = "PascalCase"

# class-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
const-naming-style = "UPPER_CASE"

# const-rgx =

docstring-min-length = -1

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
function-naming-style = "snake_case"

# function-rgx =
Expand All @@ -578,14 +585,17 @@ Standard Checkers

include-naming-hint = false

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
inlinevar-naming-style = "any"

# inlinevar-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
method-naming-style = "snake_case"

# method-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
module-naming-style = "snake_case"

# module-rgx =
Expand All @@ -600,6 +610,7 @@ Standard Checkers

# typevar-rgx =

# Possible choices: ['snake_case', 'camelCase', 'PascalCase', 'UPPER_CASE', 'any']
variable-naming-style = "snake_case"

# variable-rgx =
Expand Down Expand Up @@ -919,6 +930,7 @@ Standard Checkers
.. code-block:: toml

[tool.pylint.format]
# Possible choices: ['', 'LF', 'CRLF']
expected-line-ending-format = ""

ignore-long-lines = "^\\s*(# )?<?https?://\\S+>?$"
Expand Down Expand Up @@ -1083,6 +1095,7 @@ Standard Checkers
.. code-block:: toml

[tool.pylint.logging]
# Possible choices: ['old', 'new']
logging-format-style = "old"

logging-modules = ["logging"]
Expand Down Expand Up @@ -1331,6 +1344,7 @@ Standard Checkers
[tool.pylint.spelling]
max-spelling-suggestions = 4

# Possible choices: ['', 'en', 'en_AU', 'en_CA', 'en_GB', 'en_US']
spelling-dict = ""

spelling-ignore-comment-directives = "fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:"
Expand Down Expand Up @@ -1829,6 +1843,7 @@ Extensions

accept-no-yields-doc = true

# Possible choices: ['sphinx', 'epytext', 'google', 'numpy', 'default']
default-docstring-type = "default"


Expand Down