Skip to content

Repository files navigation

How to contribute

Pull Requests

Since the configuration for your hosted bot might be different to the configuration on the hosting server (or on my local machine), never create Pull Requests for the main branch. I would suggest using the unstable branch

TypeScript Styleguide

The prettier code formatter is used

Upper and lower case

Rule 1: Function and variable names in camelCase:

constNEWVARIABLE: string='';//BADconstNewVariable: string='';//BADconstnewVariable: string='';//GOODfunctionHelloWorld(): void{//BADfunctionHELLOWORLD(): void{//BADfunctionhelloWorld(): void{//GOOD

Rule 2: In class names, each beginning of a word is upper case:

classtest{//BADclassTEST{//BADclassTest{//GOOD

String handling

Rule 3: Always use template strings instead of string concatenation:

console.log('Hello '+name);//BADconsole.log(`Hello ${name}`);//GOOD

Rule 4: Always use single quotes for strings unless that would require to escape single quotes in the string:

console.log("Hello World");//BADconsole.log('Hello World');//GOODconsole.log('Hello, I\'m world');//BADconsole.log("Hello, I'm world");//GOOD

Spacing

Rule 5: Use two spaces:

//BAD:if(someBoolean){console.log('true');}//GOOD:if(someBoolean){console.log('true');}

Rule 6: Space between instruction (if, switch, …) and parenthesis. Space after curly brace, followed by line break. If no curly brace is required, then either on the same or on the next line:

if(someBoolean)//BADif(someBoolean)//GOOD//BAD:if(someBoolean){}//BAD:if(someBoolean){}//GOOD:if(someBoolean){}

Rule 7: Add spaces before and after curly braces if statement is in one line:

constobj: {value: string}={value: 'foo'};//BADconstobj: {value: string}={value: 'foo'};//GOOD

Semicolons

Rule 8: Always use semicolons:

console.log('Hello World')//BADconsole.log('Hello World');//GOOD

Rule 9: Use semicolons in object types and interfaces; add semicolon also to last index

//BAD:interfaceHuman{legs: number,arms: number}//BAD: interfaceHuman{legs: number;arms: number}//GOOD:interfaceHuman{legs: number;arms: number;}constarr: {value: string,valueTwo: string}[]=[]//BADconstarr: {value: string;valueTwo: string}[]=[]//GOOD

Types

Rule 10: Always add types; never use any unless it is unavoidable:

letsomeNumber=54;//BADletsomeNumber: number=54;//GOODconstsomeBoolean=true;//BADconstsomeBoolean: boolean=true;//GOODfunctionhelloWorld(){//BADfunctionhelloWorld(): void{//GOOD[3,2,1].sort((a: number,b: number)=>a>b ? 1 : -1);//BAD[3,2,1].sort((a: number,b: number): number=>a>b ? 1 : -1);//GOOD

Rule 11: Use [], not Array<T>:

constarray: Array<string>=['Test'];//BADconstarray: string[]=['Test'];//GOOD

Other rules

Rule 12: Always use three equal signs in comparisons:

if(a==b)//BADif(a===b)//GOODconstbool: boolean=a==b//BADconstbool: boolean=a===b//GOOD

Rule 13: Use const whenever possible; never use var unless it is unavoidable:

varsomeNumber: number=54;//BADletsomeNumber: number=54;//BAD unless it is changed laterconstsomeNumber: number=54;//GOOD//GOOD:letsomeNumber: number=54;someNumber++;//BAD:letarray: string[]=[];array.push('hi');//GOOD:constarray: string[]=[];array.push('hi');//BAD:letobj: {value: string}={value: 'foo'};obj.value='bar';//GOOD:constobj: {value: string}={value: 'foo'};obj.value='bar';

Rule 14: If-else without curly braces as well as Conditional (ternary) operators are permitted:

//GOOD:if(someBoolean)console.log('someBoolean true');elseconsole.log('someBoolean false');//GOOD:if(someBoolean)console.log('someBoolean true');elseconsole.log('someBoolean false');//GOOD:if(someBoolean){console.log('someBoolean true');}else{console.log('someBoolean false');}console.log(someBoolean ? 'someBoolean true' : 'someBoolean false');//GOOD but in this case…console.log(`someBoolean ${someBoolean}`);//…would be better

Rule 15: Never use lambda functions other than for very short operations:

//BAD:client.on('message',(message: Message): void=>{switch(message){case'Hello World':
message.channel.send('Hi!').catch(console.error);break;case'Bye World':
message.channel.send('Bye!').catch(console.error);break;}});//GOOD:client.on('message',onMessage);functiononMessage(message: Message){switch(message){case'Hello World':
message.channel.send('Hi!').catch(console.error);break;case'Bye World':
message.channel.send('Bye!').catch(console.error);break;}}[3,2,1].sort((a: number,b: number): number=>a>b ? 1 : -1);//GOOD

Rule 16: Use dot-notation, not [key]:

obj['foo'];//BADobj.foo;//GOOD

About

The discord bot for the Advent of Code Discord

Contributing

Stars

2 stars

Watchers

2 watching

Forks

Contributors

Languages