|
| 1 | +# How to contribute |
| 2 | + |
| 3 | +The XRLint project welcomes contributions of any form |
| 4 | +as long as you respect our [code of conduct](CODE_OF_CONDUCT.md) and stay |
| 5 | +in line with the following instructions and guidelines. |
| 6 | + |
| 7 | +If you have suggestions, ideas, feature requests, or if you have identified |
| 8 | +a malfunction or error, then please |
| 9 | +[post an issue](https://github.com/bcdev/xrlint/issues). |
| 10 | + |
| 11 | +If you'd like to submit code or documentation changes, we ask you to provide a |
| 12 | +pull request (PR) |
| 13 | +[here](https://github.com/bcdev/xrlint/pulls). |
| 14 | +For code and configuration changes, your PR must be linked to a |
| 15 | +corresponding issue. |
| 16 | + |
| 17 | +To ensure that your code contributions are consistent with our project’s |
| 18 | +coding guidelines, please make sure all applicable items of the following |
| 19 | +checklist are addressed in your PR. |
| 20 | + |
| 21 | +**PR checklist** |
| 22 | + |
| 23 | +* Format code using [black](https://black.readthedocs.io/) with default settings. |
| 24 | + Check also section [code style](#code-style) below. |
| 25 | +* Your change shall not break existing unit tests. |
| 26 | + `pytest` must run without errors. |
| 27 | +* Add unit tests for any new code not yet covered by tests. |
| 28 | +* Make sure test coverage stays close to 100% for any change. |
| 29 | + Use `pytest --cov=zappend --cov-report=html` to verify. |
| 30 | +* If your change affects the current project documentation, |
| 31 | + please adjust it and include the change in the PR. |
| 32 | + Run `mkdocs serve` to verify. |
| 33 | + |
| 34 | +## Code style |
| 35 | + |
| 36 | +The XRLint code complies to [PEP-8](https://pep8.org/) except for a line |
| 37 | +length of 88 characters as recommended by [black](https://black.readthedocs.io/). |
| 38 | +Since black is un-opinionated regarding the order of imports, |
| 39 | +we use the following three import blocks separated by an empty |
| 40 | +line: |
| 41 | + |
| 42 | +1. Python standard library imports, e.g., `os`, `typing`, etc |
| 43 | +2. 3rd-party imports, e.g., `xarray`, `zarr`, etc |
| 44 | +3. XRLint module imports: |
| 45 | + Prefer absolute import paths: `from xrlint.a.b.c import d`. |
| 46 | + Relative imports such as `from .c import d` are ok |
| 47 | + while `..c import d` are not ok. |
| 48 | + |
| 49 | +Use `typing.TYPE_CHECKING` to resolve forward references |
| 50 | +and effectively avoid circular dependencies. |
| 51 | + |
| 52 | +## Contributing Rules |
| 53 | + |
| 54 | +### Rule Naming |
| 55 | + |
| 56 | +The rule naming conventions for XRLint are the same as or ESLint: |
| 57 | + |
| 58 | +* Lower-case only. |
| 59 | +* Use dashes between words (kebab-case). |
| 60 | +* If your rule only disallows something, |
| 61 | + prefix it with `no-` such as `no-empty-attrs` for disallowing |
| 62 | + empty attributes in dataset nodes. |
| 63 | +* If your rule is enforcing the inclusion of something, |
| 64 | + use a short name without a special prefix. |
| 65 | +* Plugins should add a prefix before their rule names |
| 66 | + separated by a slash, e.g., `xcube/spatial-dims-order`. |
| 67 | + |
| 68 | +### Rule Design |
| 69 | + |
| 70 | +* The reasoning behind a rule should be **easy to grasp**. |
| 71 | + |
| 72 | +* A rule should serve for a **single purpose only**. Try subdividing |
| 73 | + complex rule logic into multiple rules with simpler logic. |
| 74 | + |
| 75 | +* Each rule should be defined in a dedicated module named after the rule, |
| 76 | + i.e., `<plugin>/rules/<rule>`. The module name should be the rule's name |
| 77 | + with dashes replaced by underscores. |
| 78 | + |
| 79 | +* Write a comprehensive test for your rule logic using |
| 80 | + `xrlint.testing.RuleTester`. It should be defined in a dedicated |
| 81 | + test module, i.e., `tests/rules/test_<rule>`. |
0 commit comments