2015-06-24 13:27:01 +02:00
# Contributing
2015-05-05 01:26:39 +02:00
2019-12-18 02:10:03 +01:00
***Ask not what Notepad++ can do for you - ask what you can do for Notepad++***
2015-05-05 01:26:39 +02:00
2015-10-02 16:08:51 +02:00
## Reporting Issues
2015-06-24 13:27:01 +02:00
2023-04-07 12:15:50 +02:00
Bug reports are appreciated. Following a few guidelines listed below will help speed up the process of getting them fixed.
2015-06-24 13:27:01 +02:00
2015-10-02 16:08:51 +02:00
1. Search the issue tracker to see if it has already been reported.
2. Disable your plugins to see if one of them is the problem. You can do this by renaming your `plugins` folder to something else.
2022-11-30 18:28:27 +01:00
3. Only report an issue with a plugin if it is one of the standard plugins included in the Notepad++ installation. Any other plugin issue should be reported to its respective issue tracker (see e.g. [plugin_list_x86.md ](https://github.com/notepad-plus-plus/nppPluginList/blob/master/doc/plugin_list_x86.md ) or [plugin_list_x64.md ](https://github.com/notepad-plus-plus/nppPluginList/blob/master/doc/plugin_list_x64.md ) to find the homepage with further information on that for a plugins). The standard plugins include (for v7.9.5):
2015-10-02 16:08:51 +02:00
* NppExport
* Converter
* mimeTools
2023-08-28 16:01:13 +02:00
4. Fill the complete information: a template will be shown when you create an issue. Please fill the complete information in the template. To fill the field **Debug Information** you can get it from your Notepad++ via menu `?>Debug Info...` . Please take your time to fill these information. If you don't bother to complete the information we need to help you, we won't bother to solve your problem either.
2015-06-24 13:27:01 +02:00
2015-10-02 16:08:51 +02:00
## Pull Requests
2015-11-29 22:04:36 +01:00
Your pull requests are welcome; however, they may not be accepted for various reasons. If you want to make some GUI enhancement like renaming some graphic items or fixing typos, please create the issue instead of the pull requests. All Pull Requests, except for translations and user documentation, need to be attached to a issue on GitHub. For Pull Requests regarding enhancements and questions, the issue must first be approved by one of project's administrators before being merged into the project. An approved issue will have the label `Accepted` . For issues that have not been accepted, you may request to be assigned to that issue.
2015-06-24 13:27:01 +02:00
2022-08-30 19:25:35 +02:00
Opening an issue beforehand allows the administrators and the community to discuss bugs and enhancements before work begins, preventing wasted effort.
2015-06-24 13:27:01 +02:00
2015-10-02 16:08:51 +02:00
### Guidelines for pull requests
2015-05-05 01:26:39 +02:00
2021-02-20 13:02:31 +01:00
1. Respect existing Notepad++ coding style. Observe the code near your intended change, and attempt to preserve the style of that code with the changes you make.
2020-09-09 15:41:57 +02:00
2. Create a new branch for each PR. **Make sure your branch name wasn't used before** - you can add date (for example `patch3_20200528` ) to ensure its uniqueness.
2020-02-03 23:52:52 +01:00
3. Single feature or bug-fix per PR.
2021-01-16 12:07:51 +01:00
4. Create a PR with a single commit to make the review process easier.
2020-02-03 23:52:52 +01:00
5. Make your modification compact - don't reformat source code in your request. It makes code review more difficult.
6. PR of reformatting (changing of ws/TAB, line endings or coding style) of source code won't be accepted. Use issue trackers for your request instead.
2020-05-19 19:27:09 +02:00
7. Typo fixing and code refactoring won't be accepted - please create issues with title started with `TYPO` to request the changing.
2021-01-16 12:07:51 +01:00
8. Address the review change requests by pushing new commits to the same PR. Avoid amending a commit and then force pushing it. All the PR commits are squashed before merging to the main branch.
2023-04-07 12:15:50 +02:00
9. When creating new PR, try to base it on latest master.
10. Don't merge `upstream/master` (using git or via github sync), if your PR is based on older `upstream/master` . If you need to base it on latest `master` (e.g. to check and fix merge conflict), use commands `git fetch upstream` to get latest `master` and then `git rebase upstream/master` to rebase it onto this latest `upstream/master` .
11. Finally, please test your pull requests, at least once.
2015-06-24 13:45:12 +02:00
2015-05-06 00:46:37 +02:00
In short: The easier the code review is, the better the chance your pull request will get accepted.
2015-05-05 01:26:39 +02:00
2015-10-02 16:08:51 +02:00
### Coding style
2015-06-24 13:27:01 +02:00
2023-04-07 12:15:50 +02:00
![stay clean ](https://notepad-plus-plus.org/assets/images/good-bad-practice.jpg )
2015-05-29 03:56:29 +02:00
2015-07-16 22:29:09 +02:00
#### GENERAL
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
1. Do not use Java-like braces
* Good:
2015-05-29 03:56:29 +02:00
2015-07-16 22:29:09 +02:00
```cpp
2022-02-17 14:02:00 +01:00
void MyClass::method1()
2015-07-16 22:29:09 +02:00
{
2022-02-17 14:02:00 +01:00
if (aCondition)
{
// Do something
}
2015-07-16 22:29:09 +02:00
}
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
2022-02-17 14:02:00 +01:00
void MyClass::method1() {
if (aCondition) {
// Do something
}
2015-07-16 22:29:09 +02:00
}
```
2023-04-07 12:15:50 +02:00
However, the method definition could be defined in a header file (.h), if there's one line code only. In this case, Java-like braces should be used.
* Good:
2022-02-17 13:50:48 +01:00
```cpp
class MyClass
{
public:
void method1();
int method2() {
return _x; // only one line code can be placed in .h as method definition
2022-02-17 14:02:00 +01:00
};
2022-02-17 13:50:48 +01:00
private:
int _x;
}
```
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
2. Use tabs instead of white-spaces (we usually set our editors to 4 white-spaces for 1 tab, but the choice is up to you)
3. Always leave one space before and after binary and ternary operators
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
* Good:
2015-07-16 22:29:09 +02:00
```cpp
2015-08-04 01:47:14 +02:00
if (a == 10 & & b == 42)
2015-07-16 22:29:09 +02:00
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
if (a==10& & b==42)
```
2023-04-07 12:15:50 +02:00
4. Only leave one space after semi-colons in "for" statements
* Good:
2015-07-16 22:29:09 +02:00
```cpp
for (int i = 0; i != 10; ++i)
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
for(int i=0;i< 10 ; + + i )
```
2023-04-07 12:15:50 +02:00
5. Function names are not separated from the first parenthesis
* Good:
2015-07-16 22:29:09 +02:00
```cpp
2015-05-29 03:56:29 +02:00
foo();
myObject.foo(24);
2015-07-16 22:29:09 +02:00
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
2015-05-29 03:56:29 +02:00
foo ();
2015-07-16 22:29:09 +02:00
```
2023-04-07 12:15:50 +02:00
6. Keywords are separated from the first parenthesis by one space
* Good:
2015-05-29 03:56:29 +02:00
2015-07-16 22:29:09 +02:00
```cpp
2015-05-29 03:56:29 +02:00
if (true)
while (true)
2015-07-16 22:29:09 +02:00
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
2015-05-29 03:56:29 +02:00
if(myCondition)
2015-07-16 22:29:09 +02:00
```
2023-04-07 12:15:50 +02:00
7. Switch
* Use the following indenting for "switch" statements:
```cpp
switch (test)
{
case 1:
{
// Do something
break;
}
default:
// Do something else
} // No semi-colon here
```
* If possible use `default` statement, and prefer using it as last case.
* When using switch with enum or known range, try to cover all values if not using `default` .
```cpp
enum class Test {val1, val2, val3}
switch (Test)
{
case Test::val1:
{
// Do something
break;
}
//case Test::val2:
//case Test::val3:
default:
// Do something else
} // No semi-colon here
```
When using `default` adding uncovered values as comments can help to convey intention.
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
* Use `[[fallthrough]]` if fall through is intended.
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
```cpp
switch (test)
{
case 1:
{
// Do something
}
// I want fall through // adding comment can help to convey intention
[[fallthrough]];
case 2:
{
// Do something
break;
}
default:
// Do something else
} // No semi-colon here
```
8. Avoid magic numbers
* Good:
2015-07-16 22:29:09 +02:00
```cpp
2021-03-05 00:51:19 +01:00
if (foo == I_CAN_PUSH_ON_THE_RED_BUTTON)
startTheNuclearWar();
2015-07-16 22:29:09 +02:00
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
while (lifeTheUniverseAndEverything != 42)
lifeTheUniverseAndEverything = buildMorePowerfulComputerForTheAnswer();
```
2023-04-07 12:15:50 +02:00
9. Prefer enums for integer constants
10. Use initialization with curly braces
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
* Good:
2015-07-16 22:29:09 +02:00
```cpp
MyClass instance{10.4};
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
MyClass instance(10.4);
```
2023-04-07 12:15:50 +02:00
11. Always use `empty()` for testing if a string is empty or not
* Good:
2015-07-16 22:29:09 +02:00
```cpp
2021-07-14 14:04:42 +02:00
if (!string.empty())
2015-07-16 22:29:09 +02:00
...
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
if (string != "")
...
```
2023-04-07 12:15:50 +02:00
12. Always use `C++ conversion` instead of `C-Style cast`
* Generally, all the conversion among types should be avoided. If you have no choice, use C++ conversion.
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
* Good:
2016-08-17 11:54:53 +02:00
```cpp
char aChar = static_cast< char > (_pEditView->execute(SCI_GETCHARAT, j));
```
2023-04-07 12:15:50 +02:00
* Bad:
2016-08-17 11:54:53 +02:00
```cpp
char aChar = (char)_pEditView->execute(SCI_GETCHARAT, j);
```
2023-04-07 12:15:50 +02:00
13. Use `!` instead of `not` , `&&` instead of `and` , `||` instead of `or`
* Good:
2021-02-20 13:02:31 +01:00
```cpp
if (!::PathFileExists(dir2Search))
```
2023-04-07 12:15:50 +02:00
* Bad:
2021-02-20 13:02:31 +01:00
```cpp
if (not ::PathFileExists(dir2Search))
```
2015-07-16 22:29:09 +02:00
2023-08-12 02:37:55 +02:00
14. Always initialize local and global variables
2023-04-07 12:15:50 +02:00
* For primitive types and enum prefer initialization with `=` .
* For other prefer `{}` -initializer syntax.
* For "numerical" variables using literal suffix can help to convey intention.
```cpp
constexpr float g_globalVariable = 0.0F;
void test()
{
constexpr UINT strLen = 1024U;
wchar_t myString[strLen]{};
}
```
2015-07-16 22:29:09 +02:00
#### NAMING CONVENTIONS
2023-04-07 12:15:50 +02:00
1. Classes uses Pascal Case
* Good:
2015-07-16 22:29:09 +02:00
```cpp
class IAmAClass
{};
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
2019-12-28 06:05:19 +01:00
class iAmAClass
2015-07-16 22:29:09 +02:00
{};
2019-12-28 06:05:19 +01:00
class I_am_a_class
2015-07-16 22:29:09 +02:00
{};
```
2023-04-07 12:15:50 +02:00
2. Methods & method parameters
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
* Use camel Case
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
```cpp
void myMethod(uint myVeryLongParameter);
```
2019-12-28 06:05:19 +01:00
2023-04-07 12:15:50 +02:00
3. Member variables
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
* Any member variable name of class/struct should be preceded by an underscore.
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
```cpp
public:
int _publicAttribute;
private:
int _pPrivateAttribute;
float _pAccount;
```
4. Always prefer a variable name that describes what the variable is used for
* Good:
2015-07-16 22:29:09 +02:00
```cpp
if (hours < 24 & & minutes < 60 & & seconds < 60 )
```
2023-04-07 12:15:50 +02:00
* Bad:
2015-07-16 22:29:09 +02:00
```cpp
if (a < 24 & & b < 60 & & c < 60 )
```
#### COMMENTS
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
1. Use C++ comment line style rather than C comment style
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
* Good:
```cpp
2015-07-16 22:29:09 +02:00
// Two lines comment
// Use still C++ comment line style
```
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
* Bad:
```cpp
2015-07-16 22:29:09 +02:00
/*
Please don't piss me off with that
*/
```
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
#### BEST PRACTICES
1. Use C++11/14/17/20 whenever it is possible.
2. Use C++11 member initialization feature whenever it is possible.
```cpp
class Foo
{
int value = 0;
};
```
3. Incrementing
* Prefer Pre-increment
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
```cpp
++i
```
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
* Over Post-increment
2015-07-15 11:55:49 +02:00
2023-04-07 12:15:50 +02:00
```cpp
i++
```
2015-07-15 11:55:49 +02:00
2023-04-07 12:15:50 +02:00
(It does not change anything for built-in types but it would bring consistency)
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
4. Avoid using pointers. References are preferred instead. You might need the variable to be assigned a `NULL` value: in this case the `NULL` value has semantics and must be checked. Wherever possible, use a SmartPtr instead of old-school pointers.
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
5. Avoid using new if you can use automatic variable. However, avoid `shared_ptr` as much as possible. Prefer `unique_ptr` instead.
2015-07-16 22:29:09 +02:00
2023-04-07 12:15:50 +02:00
6. Don't place any "using namespace" directives in headers.
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
7. Compile time is without incidence. Increasing compile time to reduce execution time is encouraged.
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
8. Code legibility and length is less important than easy and fast end-user experience.
2015-05-29 03:56:29 +02:00
2023-04-07 12:15:50 +02:00
9. Prefer `constexpr` over `const` if value can be evaluated at compile time.
2015-05-29 03:56:29 +02:00
2023-08-12 02:37:55 +02:00
10. Check if there are helper functions in headers or lambda functions to reuse them instead of writing new code.
2023-04-07 12:15:50 +02:00
* Example
```cpp
// in StaticDialog.h
isCheckedOrNot();
setChecked();
// in Parameters.cpp
parseYesNoBoolAttribute();
```
2023-09-16 13:44:43 +02:00
11. Check if there are already defined global variables, and reuse them instead of defining new ones.
2023-04-07 12:15:50 +02:00
12. Avoid "Yoda conditions".
* Good:
```cpp
if (iAmYourFather == true)
...
```
* Bad:
```cpp
if (true == iAmYourFather)
...
```
2015-05-29 03:56:29 +02:00
2023-09-03 09:35:22 +02:00
13. Check [C++ Core Guidelines ](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md ) for additional guidelines.