This document outlines code styling conventions to follow when contributing to this project.
Obviously, all of the following are strictly forbidden :
- Malicious code.
- Code exposing secrets/passwords.
Third party code may be allowed if and only if its licensing matches that of this project (currently MIT).
IntelliJ IDEA is the recommended IDE to use for this project.
- Every statement (separated with a semicolon) belongs on a separate line.
- Lines should stay under 120 characters long. This rule is strict when it comes to comments/javadoc, but otherwise it is acceptable to have lines about 10 characters longer.
- The brace style used is the K&R variant sometimes called 1TBS/OTBS (One True Brace Style) :
- No line break before the opening brace, only a single space.
- Lines inside the block are indented once (1 tab or 4 spaces)
- The closing brace is vertically aligned with the start of the statement that opened the code block (i.e the
ifstatement, thewhileloop, etc) - There may be no code following a closing brace, with the exception of
else if/elseafter anif/else ifstatement,catch/finallyafter atryblock andwhile (condition)at the end of ado ... whileloop, in which case it is separated by a space.
Example :
public static void main(String[] args) {
while (someCondition) {
var someInt = 2;
var result = computation(someInt);
if (matchesCondition(result)) {
success();
} else {
failure();
}
}
}- Braces may only be omitted with
if,for,whilecontaining a single statement if it doesn't hurt the readability of the code. In the case ofif, there must be no attachedelse if/elseblocks, in which case all blocks must have braces. When braces are removed, the statement inside must still be indented and on its own line.
Example :
if (simpleCondition) {
simpleStatement();
}may become
if (simpleCondition)
simpleStatement();- Classes use PascalCase
- Constant fields (enums included) use SCREAMING_SNAKE_CASE
- Methods, fields and local variables use camelCase
- Packages are all lowercase with no spaces or delimiters.
- Classes extending
ConditionalExpressionshould start with theCondExprprefix - Classes extending
Expressionthat behave as literals (i.e that don't take any expression as input, and whose values do not depend on the placement in the code) should start with theLitprefix - Other classes extending
Expressionshould start with theExprprefix. - Classes extending
Effectshould start with theEffprefix. - Classes extending
CodeSectionshould start with theSecprefix. - Classes extending
SkriptEventshould start with theEvtprefix. - Classes extending
TriggerContextshould end with theContextsuffix.
- This project uses Java 11, all features introduced thereafter cannot be used.
- The
varkeyword should be used as often as possible when it doesn't hamper readability. - Fields may be marked
finalif and only if they are effectively final. Parameters should never be, and local variables should only be markedfinalwhen required by a lambda. - Methods should only be marked
finalto disallow overriding them, and for thisstaticmethods should absolutely never be markedfinal. - Classes shouldn't be marked
final. - The
@Overrideannotation should be added when applicable.
- When implementing any
SyntaxElement,initmust come first andtoStringshould come last.
- Every parameter, field, and return value from the project is presumed to be not null unless explicitly marked so as such using the
org.jetbrains.annotations.Nullableannotation. - When creating a new package, create a
package-info.javafile, and add thejavax.annotation.ParametersAreNonnullByDefault. - If you are absolutely certain that a variable is non-null despite it being marked as nullable, use an assertion.
Important note : in the future, the project is planned to instead use the java.util.Optional API instead.