|
| 1 | +# Frequently Asked Questions |
| 2 | + |
| 3 | +This page provides answers to common questions about using and configuring the `docstring-format-checker` package. |
| 4 | + |
| 5 | + |
| 6 | +## 🎯 Which docstring style is this built for? |
| 7 | + |
| 8 | +`docstring-format-checker` is primarily designed to support [**Google-style**][google-style] docstrings. This style is popular because it is highly readable and uses clear indentation to separate different sections like parameters and return values. |
| 9 | + |
| 10 | +However, the tool is not strictly limited to a single style. Because it is configuration-driven, you can **customise** the section names and types in your [pyproject.toml](pyproject.toml) to match your team's specific requirements. You can define your own sections using types like `free_text`, `list_name`, `list_type`, and `list_name_and_type`. |
| 11 | + |
| 12 | + |
| 13 | +## 🧩 Why doesn't it support NumPy or reStructuredText (reST) styles? |
| 14 | + |
| 15 | +We chose to focus on a "section-based" model that works exceptionally well with Google-style formatting. By focusing on AST (Abstract Syntax Tree) parsing rather than complex regular expressions, we can provide much more reliable validation for the most common use cases. |
| 16 | + |
| 17 | +While NumPy and reST are powerful, they often require significantly more complex parsing logic. By keeping the tool focused, we ensure it remains fast, lightweight, and extremely accurate for the styles it does support. |
| 18 | + |
| 19 | + |
| 20 | +## 🪄 Does it automatically fix my docstrings, like other packages such as [`black`][black] and [`isort`][isort] fixes my code? |
| 21 | + |
| 22 | +No, `docstring-format-checker` is currently a **validator**, not a formatter. It will tell you exactly what is wrong and where, but it won't change the docs in your code. |
| 23 | + |
| 24 | +Think of it like `pylint` or `pyright`, it's designed to be used in your CI/CD pipelines or as a pre-commit hook to ensure that everyone on your team follows the same standards. |
| 25 | + |
| 26 | + |
| 27 | +## 🌳 What is "AST parsing" and why should I care? |
| 28 | + |
| 29 | +AST stands for **Abstract Syntax Tree**. Most simple tools use "Regular Expressions" (regex) to look for patterns in your text. This can often get confused by complex code structures, decorators, or nested classes. |
| 30 | + |
| 31 | +`docstring-format-checker` actually "reads" your Python code just like the Python interpreter does using the [`ast`][ast] module. This means it has a perfect understanding of which docstring belongs to which function or class, making it much more robust and less likely to give you "false positives" (wrongly reported errors). |
| 32 | + |
| 33 | + |
| 34 | +## 👯 Why are there two commands (`dfc` and `docstring-format-checker`)? |
| 35 | + |
| 36 | +Both commands perform exactly the same actions. We provide `docstring-format-checker` as the primary command, and is descriptive for clarity and discoverability. However, because that can be quite a lot to type, we also provide `dfc` as a convenient short-hand alias for daily use in your terminal. |
| 37 | + |
| 38 | +Similarly, you can use either `[tool.dfc]` or `[tool.docstring-format-checker]` in your [pyproject.toml](pyproject.toml) file. The tool will look for `dfc` first, and then fall back to the longer name if the shorter one isn't found. This ensures your configuration remains tidy while still being descriptive. |
| 39 | + |
| 40 | + |
| 41 | +## 🤐 Can I skip private functions or specific files? |
| 42 | + |
| 43 | +Absolutely! We recognise that you might not want to document every single helper function in your codebase. |
| 44 | + |
| 45 | +- **Private Items**: You can toggle `check_private = false` in your configuration to ignore anything starting with an underscore. |
| 46 | +- **Exclusions**: Use the `--exclude` flag or define exclusion patterns in your [pyproject.toml](pyproject.toml) to skip specific files or entire directories (like `src/tests/` or `migrations/`). |
| 47 | + |
| 48 | + |
| 49 | +## 🛠️ How do I handle "Optional" types in my parameters? |
| 50 | + |
| 51 | +The tool includes an `optional_style` configuration. This allows you to decide how strictly you want to enforce the `Optional` label in your docstrings when a parameter has a default value of `None`. |
| 52 | + |
| 53 | +You can choose from three behaviours: |
| 54 | + |
| 55 | +- `silent`: No special checks for `Optional`. |
| 56 | +- `validate`: Ensures that if you say a parameter is optional, it actually has a default value. |
| 57 | +- `strict`: **Requires** you to mark parameters as optional in the docstring if they have a default value of `None` in the signature. |
| 58 | + |
| 59 | + |
| 60 | +## 🚀 How do I use this in my CI/CD pipeline? |
| 61 | + |
| 62 | +We recommend running `dfc` (or `docstring-format-checker`) with the `--check` flag in your pipeline. This flag will cause the tool to return a non-zero exit code if any errors are found, which will "break the build" and alert you to the problem. |
| 63 | + |
| 64 | +```bash |
| 65 | +# Example for a CI pipeline |
| 66 | +dfc --check src/ |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +[google-style]: https://google.github.io/styleguide/pyguide.html |
| 71 | +[black]: https://black.readthedocs.io/en/ |
| 72 | +[isort]: https://pycqa.github.io/isort/ |
| 73 | +[ast]: https://docs.python.org/3/library/ast.html |
0 commit comments