5.0 KiB
Contribution Guidelines
-
Include documentation reference(s) at the top of each file:
// http://officeopenxml.com/WPdocument.php
-
Follow Prettier standards, and consider using the Prettier VSCode plugin.
-
Follow the
TSLint
rules
Always think about the user
The number one pillar for contribution is to ALWAYS think about how the user will use the library.
Put yourself in their position, and imagine how they would feel about your feature you wrote.
- Is it easy to use?
- Has it been documented well?
- Is it intuative?
- Is it consistent with the rest of the API?
- Is it fun to use?
Good Commit Names
Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/
Do not:
c // What?
rtl // Adding acryonyms without explaining anything else is not helpful
works! // Glad its working, but the message is not helpful
demo updated // Getting better, but capitalize the first letter
Unesesary coment removed // Make sure to use correct spelling
No leaky components in API interface
This mainly applies to the API the end user will consume.
Try to make method parameters accept primatives, or json
objects, so that child components are created inside the component, rather than being injected in.
This is so that:
-
Imports are much cleaner, no need for:
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
-
This is what I consider "leakage". The code is aware of the underlying implementation of the component.
-
It means the end user does not need to import and create the child component to be injected.
Do not
TableFloatProperties
is a class. The outside world would have to construct the object, and inject it in
public float(tableFloatProperties: TableFloatProperties): Table
Do
ITableFloatOptions
is an interface for a JSON of primatives.
public float(tableFloatOptions: ITableFloatOptions): Table
Add vs Create
This is just a guideline, and the rules can sometimes be broken.
-
Use
create
if the methodnew
's up an element inside:public createParagraph() { const paragraph = new Paragraph(); this.root.push(paragraph); }
-
Use
add
if you add the element into the method as a parameter:public addParagraph(paragraph: Paragraph) { this.root.push(paragraph); }
Getters and Setters
Getters and Setters are done with a capital letter like so:
public get Level() {
...
}
There is no performance advantage by doing this. It means we don't need to prefix all private variables with the ugly _
:
Do not:
private get _level: string;
Do
private get level: string;
Interfaces over type alias
Do not use type
, but rather use Interfaces
. type
cannot be extended, and a class cannot implement it.
"In general, use what you want ( type alias / interface ) just be consistent" "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions"
Interface
is generally preferred over type
: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types
Do not:
type RelationshipFileInfo = { id: number, target: string };
Do:
interface IRelationshipFileInfo {
id: number;
target: string;
}
String enums vs type
To take full advantage of TypeScript's typing system, its best to use string enums
:
Do not:
type WeaponType = "bow" | "sword" | "wand";
Do:
enum WeaponType = {
BOW = "bow",
SWORD = "sword",
WAND = "wand",
}
Spell correctly, full and in American English
I am not sure where these habits in software development come from, but I do not believe it is beneficial:
Do not:
readdy // misspelling
perm // abbreviation
conf // abbreviation
cnty // abbreviation
relationFile // abbreviation
colour // U.K. English
Do:
ready
permission
config
country
relationshipFile
color
Keep files small (within reason)
To minimize merge conflicts, reduce complexity, and improve readability, keep the files small.
Name files and folders with /foo-bar/kebab-case.ts
To be consistent and in-line with the project, name files like-this.ts
.
https://stackoverflow.com/questions/7273316/what-is-the-javascript-filename-naming-convention
Testing
Please write a test of every file you make and suffix it with .spec.ts
.
Here is a template of a test:
import { assert } from "chai";
describe("ClassName", () => {
beforeEach(() => {
// TODO
});
describe("#methodName()", () => {
it("should ", () => {
// TODO
});
});
});
Try not to use the tests/utility.ts
file as this is being deprecated.