Please don't use this rule book. The rules are extremely arbitrary and change all the time.
This is a journal to help me remain consistent. It also helps me spot and fix common mistakes.
- Repositories must have
README
files. - Editing code directly on this site mustn't occur (too often).
- Repository names must be capitalized.
- Repository names must be as short as possible.
- Repository names must use
-
to separate words. - Repository descriptions mustn't include a full stop.
- Repository descriptions must be as short as possible.
- Repositories intended for personal use must include an
MIT License
withMysteryPancake
as the legal name. - Repositories intended for external use must include an
Unlicense
. - Variables to insert must be named
<VAR>
, notINSERT_VAR_HERE
. - Images in
README
files must be included in the repository, not on an external site. - Commits closing issues must be named
resolved
,fixes
, orresolves
, followed by the issue number. - Small unused scripts must be added to the Fun repository.
- Repositories intended for external use must be named
GMod-<Addon-Name>
. - Repositories must include the tags
garrys-mod
,garrysmod
,garry-mod
,garrysmod-addon
,lua
,addon
,glua
,gmod
, andgmod-lua
. - Repositories for Scripted Tools must include the tag
garrysmod-tool
. - Repository descriptions must be
<Addon Name> for Garry's Mod
. - Repositories must include an addon icon and the associated Photoshop file.
- Repositories must include a link to the addon.
- Repository
README
files must use this template:
<img src="<ICON_PATH>?raw=true" width="75" align="left">
# Garry's Mod <Addon Name>
All the code for my <Addon Name> addon can be found here, and the actual addon is available [here](<WORKSHOP_LINK>).
- Repositories must include the tags
discord
,discord-bot
,discord-js
,discord-api
,discordjs
,discordjs-bot
,javascript
,discordjsbot
,discordapp
,discordbot
,nodejs-bot
,nodejs
,node-js
, andbot
. - Repositories must include a
Procfile
containingworker: npm start
. - Repository
README
files must include setup instructions. - Repository
README
files must include a command list. - Repositories must include a bot icon.
- Repository
package.json
files must use this template:
{
"name": "<Repository-Name>",
"version": "1.0.0",
"description": "<Repository Description>",
"main": "<SCRIPT_PATH>",
"engines": {
"node": "10.x",
"npm": "*"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node <SCRIPT_PATH>"
},
"keywords": [
"discord",
"discord-bot",
"discord-js",
"discord-api",
"discordjs",
"discordjs-bot",
"javascript",
"discordjsbot",
"discordapp",
"discordbot",
"nodejs-bot",
"nodejs",
"node-js",
"bot"
],
"author": "MysteryPancake",
"license": "MIT",
"dependencies": {
"discord.js": "<VERSION>"
}
}
- Repositories must include the tags
github-pages
,github-page
,github-io
,html
,css
,javascript
,github-api
,website
,online
, and all website keywords. - Website links must have lowercase domains.
- Website links mustn't have a
/
at the end. - Repositories must include a website link.
- Functions with applicable default arguments mustn't be called with the arguments.
- Generic
string
variables must be namedstr
, nottxt
, ortext
. -foo
and!foo
must be used to invert variables, notfoo * -1
.- Functions with
enum
arguments mustn't be called with raw values. - Literal collections must be on a single line unless wrapping.
if
statements must be on a single line unless wrapping.if bool then
must be used, notif bool == true then
.- Variables mustn't share the names of existing variables.
- The last condition of
switch
statements mustbreak
. return
early from functions containing lots of code.- Functions mustn't have unintentional side effects.
application/xml
must be used, nottext/xml
.switch
statements mustn't have additional tabs.- Unused variables must be set as
_
, or removed. x *= 0.75
must be used, notx = x - x / 4
.Clientside
must be used, notclient-side
.Serverside
must be used, notserver-side
.- Multiplication must be used, not division.
- Powers of two must be used where possible.
- Triple newlines
\n\n\n
mustn't be used. - Validate, sanitize and escape user data.
- Variable names must be in
camelCase
. Generic
must be used, notgeneral
.- No unnecessary variables in loops.
Setup
must be used, notinit
.- Strings must use
"
, not'
. - Errors must be handled safely.
- No unnecessary
(
or)
. - No unnecessary variables.
tbl[ math.random( #tbl ) ]
must be used to get a random value from a table.- Sequential tables must be iterated with
ipairs
or a numericfor
loop. next( table ) == nil
must be used to check if a string-table is empty.- Variables must be
local
unless intended to be globally overridden. #table == 0
must be used to check if an integer-table is empty.math.random( 1, n )
must be shortened tomath.random( n )
.- Strings in tables must be
tbl.string
, nottbl[ "string" ]
. math.random() >= 0.5
must be used to get a random boolean.- Unused keys and values in loops must be set as
_
. - Generic table variables must be named
tbl
. return end
must be followed by a newline.not foo
must be used to invert booleans.- Tab indentation must be used, not spaces.
- Tables must be sequential where possible.
return
must be used, notreturn nil
.- Spaces must be on both sides of
..
. - Spacing must be between everything.
local foo = foo
mustn't be used.- No unnecessary metamethods.
module
mustn't be used.select
mustn't be used.
player_manager.AddValidModel( "Model Name", "models/player/model.mdl" )
must be used to add playermodels.foo:BoundingRadius()
must be used, notfoo:OBBMins():Distance( foo:OBBMaxs() )
.tobool( foo:GetInfo( "bar" ) )
must be used to check a ConVar as a bool.- In
PlayerSay
andOnPlayerChat
,text
must be used, nottxt
orstr
. foo:GetInfo( "bar" )
must be used, notfoo:GetInfoNum( "bar" )
.IsValid( foo )
must be used for validation, notfoo:IsValid()
.player.GetHumans()
must be used, notplayer.GetAll()
.AddCSLuaFile
mustn't be used for files inlua/autorun
.or
,and
,not
,~=
,--[[ ]]
and--
must be used.- Generic player variables must be named
ply
, notpl
. - Assume data sent to the server has malicious intent.
self:GetOwner()
must be used, notself.Owner
.SOLID_OBB
must be used, notSOLID_BBOX
.- Hooks must be added in
lua/autorun
files. CurTime
must be used for in-game events.SysTime
must be used for benchmarking.RealTime
must be used for HUD events.Panel
must be used, notDPanel
.foo:PhysWake()
must be used.table.Random
mustn't be used.Material
must be cached.SENT
s must use this template:
AddCSLuaFile()
ENT.Type = "anim"
ENT.Spawnable = true
ENT.AdminOnly = true
ENT.Editable = false
ENT.PrintName = "Entity Name"
ENT.Author = "MysteryPancake"
ENT.Purpose = "Entity purpose"
ENT.Instructions = "Entity instructions"
ENT.Category = "Entity category"
ENT.RenderGroup = RENDERGROUP_OPAQUE
- The iOS requirement must be kept as low as possible.
- Projects must include a complete icon set.
- All build warnings must be enabled.
- Warnings must be treated as errors.
- Repeating arrays must be
x: [Any] = Array(repeating: n, count: n)
, notx = [Any](repeating: n, count: n)
. arc4random_uniform(max - min) + min
must be used to get random numbers in a range.UserDefaults.standard
must be used to save data such as scores and progress.arc4random
andarc4random_uniform
must be used to get random numbers..init
mustn't be used when calling functions with specific arguments.- Variables must be
private
unless intended to be globally overridden. - Overridable classes must have as many
final
properties as possible. - Dictionaries must be
x: [Any: Any] = [:]
, notx = [Any: Any]()
. .
must be used when calling functions with specific arguments.- Extensions and enums must be used to reduce namespace clutter.
"String \(foo)"
must be used to join variables with strings.- Variables must use
get
,set
, anddidSet
where possible. - Variables mustn't be type declared unless they're numbers.
- Classes must be
final
unless intended to be overridden. - Generic
SKAction.wait
variables must be nameddelay
. struct
must be used, notclass
, where possible.- Variables mustn't be above the level of
internal
. - Arrays must be
x: [Any] = []
, notx = [Any]()
. Array
andDictionary
must be used, notSet
.- Double space indentation must be used, not tabs.
let
must be used unlessvar
is essential.- Ranges in
for
loops mustn't include spaces. ===
and!==
must be used where possible.- Unnecessary libraries mustn't be imported.
&&
must be used unless,
is essential.?
and!
variables mustn't be used.- Unused pointers must be set as
nil
. DispatchQueue
mustn't be used.- A newline mustn't be before
}
. SKShapeNode
mustn't be used.Int
must be used, notUInt
.&
must be used for pointers.
Classes must be indented like this:
class Person
{
private:
string name;
public:
void setName(string);
};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><Repository Name></title>
<meta name="description" content="<Repository Description>">
<meta name="keywords" content="<Repository, Key, Words>">
<meta property="og:title" content="<Repository Title>">
<meta property="og:type" content="website">
<meta property="og:url" content="<WEBSITE_URL>">
<meta property="og:image" content="<ICON_PATH>">
<meta property="og:site_name" content="<Repository Title>">
<meta property="og:description" content="<Repository Description>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
</head>
<body>
<span>Content</span>
</body>
</html>
- CSS must be used for sizing iframes, not
<iframe width=<WIDTH> height=<HEIGHT>
. <script>
must be used, not<script type="text/javascript">
.<style>
must be used, not<style type="text/css">
.async
anddefer
must be used carefully.- Attributes must be quoted.
- Alphabetize keywords.
font-size: small
andfont-size: large
must be used, notfont-size: smaller
orfont-size:larger
.-moz-user-select: none
must be used alongsideuser-select: none
.- Box shadows must be used for inset borders.
- Hex colors must be lowercase.
- Use
outline: none
sparingly. - Alphabetize declarations.
encodeURIComponent
anddecodeURIComponent
must be used, notencodeURI
ordecodeURI
.haystack.indexOf(needle) !== -1;
must be used to check if a string contains a substring..split("str")[0]
must be used to get text before a string, not.split("str").shift()
.foo += bar
andfoo -= bar
must be used, notfoo = foo + bar
orfoo = foo - bar
.window.innerWidth
andwindow.innerHeight
must be used to get the document size.- JavaScript names mustn't be used in objects:
{ "false": true }[false] -> true
.catch(console.error)
is preferred over.catch(e => console.error(e))
.foo++
andfoo--
must be used, notfoo += 1
orfoo -= 1
.responseText
andresponseXML
must be used, notresponse
.console.error
must be used to log errors, notconsole.log
.onmousedown
must be used instead ofonclick
where possible.Math.log2(x)
must be used, notMath.log(x) / Math.log(2)
.str.replace(/\.[^/.]+$/, "")
must be used to get a file name.fetch
must be used for newer websites, notXMLHttpRequest
.str.split(".").pop()
must be used to get a file extension.string.charAt
must be used to get a character in a string.textContent
must be used, unlessinnerHTML
is essential.bool ? foo : bar
must be used, notbool && foo || bar
.window.
must be beforewindow
methods and properties.- Global variables must be declared at the top of the script.
style.display = none
must be used, notremoveChild
.parseInt
andparseFloat
must be used, notNumber
.- Function arguments must have spacing
(like, this)
. parentNode
must be used, notparentElement
.textContent
must be used, notinnerText
.const
must be used for arrays and objects.- Objects must have spacing
{ like: this }
. - Asynchronous callbacks must use promises.
childNodes
must be used, notchildren
.- Canvas contexts must have alpha disabled.
&&
,!
, and||
must be used carefully..toString()
must be used, notString
."property" in window
mustn't be used.XMLHttpRequest
must be asynchronous.keydown
must be used, notkeypress
.wheel
must be used, notmousewheel
.initial
must be used, notorigin
.for
must be used, notforEach
.- Constructors must be capitalized.
Object.keys()
mustn't be used.- No use before define.
;
must be used.- This must be used to remove an element from an array:
var index = array.indexOf(foo);
if (index !== -1) {
array.splice(index, 1);
}
- Class functions must be sorted by
Awake
,Start
,Update
,FixedUpdate
,OnCollisionEnter
,OnCollisionStay
,OnCollisionExit
,OnTriggerEnter
,OnTriggerStay
,OnTriggerExit
, andOnBecameInvisible
. rigid2D.simulated = false
must be used to disable aRigidbody2D
, notisKinematic = true
, orSleep()
.localPosition
,localRotation
, andlocalScale
must be used, unlessposition
orrotation
are essential.- For 2D games,
Vector2
must be used where possible, unlessVector3
is essential. - Class variables must be sorted by
internal
,public
, thenprivate
. - Variables not intended to be set in the editor must be
internal
. - Class functions must be sorted by accessibility levels.
sqrMagnitude
must be used when comparing vectors.override
must be placed after the access modifier.Time.time > last
must only be used for delays.- String switches must be used, not enum switches.
Awake
must be used, unlessStart
is essential.Time.deltaTime
must only be used for timers.StartCoroutine
must be used, notInvoke
.int
must be used, unlessfloat
is essential.- Animation layers must be used, not animators.
StartsWith
andEndsWith
mustn't be used.- Variables must be as inaccessible as possible.
- Variables must be
private
where possible. - Animations mustn't affect enabled states.
for
must be used, notforeach
.- Floats must be followed by
f
. GetComponent
must be cached.- Coroutines must be cached.
window.alert
must be used for important errors, notconsole.warn
orconsole.log
.- Strings must be concatenated with
"foo" + bar
, not"foo${bar}"
. - Always
"use strict";
.