|
| 1 | +# Contributing |
| 2 | +First off, thanks for taking the time to contribute! ❤️ |
| 3 | + |
| 4 | +All types of contributions are encouraged and valued. |
| 5 | +See the [Table of Contents](#table-of-contents) for different ways to help and details about how we handle them. |
| 6 | +Please make sure to read the relevant section before making your contribution. |
| 7 | +It will make it a lot easier for us maintainers and smooth out the experience for all involved. |
| 8 | +Iconica looks forward to your contributions. 🎉 |
| 9 | + |
| 10 | +## Table of contents |
| 11 | + - [Code of conduct](#code-of-conduct) |
| 12 | + - [I Have a Question](#i-have-a-question) |
| 13 | + - [I Want To Contribute](#i-want-to-contribute) |
| 14 | + - [Reporting Bugs](#reporting-bugs) |
| 15 | + - [Contributing code](#contributing-code) |
| 16 | + |
| 17 | +## Code of conduct |
| 18 | + |
| 19 | +### Legal notice |
| 20 | +When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license. |
| 21 | +All accepted pull requests and other additions to this project will be considered intellectual property of Iconica. |
| 22 | + |
| 23 | +All repositories should be kept clean of jokes, easter eggs and other unnecessary additions. |
| 24 | + |
| 25 | +## I have a question |
| 26 | + |
| 27 | +If you want to ask a question, we assume that you have read the available documentation found within the code. |
| 28 | +Before you ask a question, it is best to search for existing issues that might help you. |
| 29 | +In case you have found a suitable issue but still need clarification, you can ask your question |
| 30 | +It is also advisable to search the internet for answers first. |
| 31 | + |
| 32 | +If you then still feel the need to ask a question and need clarification, we recommend the following: |
| 33 | + |
| 34 | +- Open an issue. |
| 35 | +- Provide as much context as you can about what you're running into. |
| 36 | + |
| 37 | +We will then take care of the issue as soon as possible. |
| 38 | + |
| 39 | +## I want to contribute |
| 40 | + |
| 41 | +### Reporting bugs |
| 42 | + |
| 43 | +<!-- omit in toc --> |
| 44 | +**Before submitting a bug report** |
| 45 | + |
| 46 | +A good bug report shouldn't leave others needing to chase you up for more information. |
| 47 | +Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. |
| 48 | +Please complete the following steps in advance to help us fix any potential bug as fast as possible. |
| 49 | + |
| 50 | +- Make sure that you are using the latest version. |
| 51 | +- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (If you are looking for support, you might want to check [this section](#i-have-a-question)). |
| 52 | +- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error. |
| 53 | +- Also make sure to search the internet (including Stack Overflow) to see if users outside of Iconica have discussed the issue. |
| 54 | +- Collect information about the bug: |
| 55 | +- Stack trace (Traceback) |
| 56 | +- OS, Platform and Version (Windows, Linux, macOS, x86, ARM) |
| 57 | +- Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. |
| 58 | +- Time and date of occurance |
| 59 | +- Describe the expected result and actual result |
| 60 | +- Can you reliably reproduce the issue? And can you also reproduce it with older versions? Describe all steps that lead to the bug. |
| 61 | + |
| 62 | +Once it's filed: |
| 63 | + |
| 64 | +- The project team will label the issue accordingly. |
| 65 | +- A team member will try to reproduce the issue with your provided steps. |
| 66 | + If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for additional information. |
| 67 | +- If the team is able to reproduce the issue, it will be moved into the backlog, as well as marked with a priority, and the issue will be left to be [implemented by someone](#contributing-code). |
| 68 | + |
| 69 | +### Contributing code |
| 70 | + |
| 71 | +When you start working on your contribution, make sure you are aware of the relevant documentation and the functionality of the component you are working on. |
| 72 | + |
| 73 | +When writing code, follow the style guidelines set by Dart: [Effective Dart](https://Dart.dev/guides/language/effective-Dart). This contains most information you will need to write clean Dart code that is well documented. |
| 74 | + |
| 75 | +**Documentation** |
| 76 | + |
| 77 | +As Effective Dart indicates, documenting your public methods with Dart doc comments is recommended. |
| 78 | +Aside from Effective Dart, we require specific information in the documentation of a method: |
| 79 | + |
| 80 | +At the very least, your documentation should first name what the code does, then followed below by requirements for calling the method, the result of the method. |
| 81 | +Any references to internal variables or other methods should be done through [var] to indicate a reference. |
| 82 | + |
| 83 | +If the method or class is complex enough (determined by the reviewers) an example is required. |
| 84 | +If unsure, add an example in the docs using code blocks. |
| 85 | + |
| 86 | +For classes and methods, document the individual parameters with their implications. |
| 87 | + |
| 88 | +> Tip: Remember that the shortest documentation can be written by having good descriptive names in the first place. |
| 89 | +
|
| 90 | +An example: |
| 91 | +```Dart |
| 92 | +library iconica_utilities.bidirectional_sorter; |
| 93 | +
|
| 94 | +part 'sorter.Dart'; |
| 95 | +part 'enum.Dart'; |
| 96 | +
|
| 97 | +/// Generic sort method, allow sorting of list with primitives or complex types. |
| 98 | +/// Uses [SortDirection] to determine the direction, either Ascending or Descending, |
| 99 | +/// Gets called on [List] toSort of type [T] which cannot be shorter than 2. |
| 100 | +/// Optionally for complex types a [Comparable] [Function] can be given to compare complex types. |
| 101 | +/// ``` |
| 102 | +/// List<TestObject> objects = []; |
| 103 | +/// for (int i = 0; i < 10; i++) { |
| 104 | +/// objects.add(TestObject(name: "name", id: i)); |
| 105 | +/// } |
| 106 | +/// |
| 107 | +/// sort<TestObject>( |
| 108 | +/// SortDirection.descending, objects, (object) => object.id); |
| 109 | +/// |
| 110 | +/// ``` |
| 111 | +/// In the above example a list of TestObjects is created, and then sorted in descending order. |
| 112 | +/// If the implementation of TestObject is as following: |
| 113 | +/// ``` |
| 114 | +/// class TestObject { |
| 115 | +/// final String name; |
| 116 | +/// final int id; |
| 117 | +/// |
| 118 | +/// TestObject({required this.name, required this.id}); |
| 119 | +/// } |
| 120 | +/// ``` |
| 121 | +/// And the list is logged to the console, the following will appear: |
| 122 | +/// ``` |
| 123 | +/// [name9, name8, name7, name6, name5, name4, name3, name2, name1, name0] |
| 124 | +/// ``` |
| 125 | +
|
| 126 | +void sort<T>( |
| 127 | + /// Determines the sorting direction, can be either Ascending or Descending |
| 128 | + SortDirection sortDirection, |
| 129 | +
|
| 130 | + /// Incoming list, which gets sorted |
| 131 | + List<T> toSort, [ |
| 132 | +
|
| 133 | + /// Optional comparable, which is only necessary for complex types |
| 134 | + SortFieldGetter<T>? sortValueCallback, |
| 135 | +]) { |
| 136 | + if (toSort.length < 2) return; |
| 137 | + assert( |
| 138 | + toSort.whereType<Comparable>().isNotEmpty || sortValueCallback != null); |
| 139 | + BidirectionalSorter<T>( |
| 140 | + sortInstructions: <SortInstruction<T>>[ |
| 141 | + SortInstruction( |
| 142 | + sortValueCallback ?? (t) => t as Comparable, sortDirection), |
| 143 | + ], |
| 144 | + ).sort(toSort); |
| 145 | +} |
| 146 | +
|
| 147 | +/// same functionality as [sort] but with the added functionality |
| 148 | +/// of sorting multiple values |
| 149 | +void sortMulti<T>( |
| 150 | + /// Incoming list, which gets sorted |
| 151 | + List<T> toSort, |
| 152 | +
|
| 153 | + /// list of comparables to sort multiple values at once, |
| 154 | + /// priority based on index |
| 155 | + List<SortInstruction<T>> sortValueCallbacks, |
| 156 | +) { |
| 157 | + if (toSort.length < 2) return; |
| 158 | + assert(sortValueCallbacks.isNotEmpty); |
| 159 | + BidirectionalSorter<T>( |
| 160 | + sortInstructions: sortValueCallbacks, |
| 161 | + ).sort(toSort); |
| 162 | +} |
| 163 | +
|
| 164 | +``` |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | +**Tests** |
| 169 | + |
| 170 | +For each public method that was created, excluding widgets, which contains any form of logic (e.g. Calculations, predicates or major side-effects) tests are required. |
| 171 | + |
| 172 | +A set of tests is written for each method, covering at least each path within the method. For example: |
| 173 | + |
| 174 | +```Dart |
| 175 | +void foo() { |
| 176 | + try { |
| 177 | + var bar = doSomething(); |
| 178 | + if (bar) { |
| 179 | + doSomethingElse(); |
| 180 | + } else { |
| 181 | + doSomethingCool(); |
| 182 | + } |
| 183 | + } catch (_) { |
| 184 | + displayError(); |
| 185 | + } |
| 186 | +} |
| 187 | +``` |
| 188 | +The method above should result in 3 tests: |
| 189 | + |
| 190 | +1. A test for the path leading to displayError by the cause of an exception |
| 191 | +2. A test for if bar is true, resulting in doSomethingElse() |
| 192 | +3. A test for if bar is false, resulting in the doSomethingCool() method being called. |
| 193 | + |
| 194 | +This means that we require 100% coverage of each method you test. |
0 commit comments