Choosing good names is critical to creating code that is easy to use and easy to understand. You should always take the time to think about whether you have chosen the right name for something.
All code, names, comments, etc. must be in English.
Do not reuse names. Do not use names that can mean multiple things. Always use the same name for the same thing.
Names must be descriptive for the working or usage of the class, method or variable.
A name should make sense within its context and should not have unnecessary information for that
context. For example a variable that holds the name of a user can be named name
within a User
context. However if you need to hold the name of a user in another place, userName
might be a
better name. Adding user
within a User
context (user.userName
) is redundant and should be
avoided.
Interfaces should use the I
as prefix. Like IMyInterface
Prefer using a verb as a name to indicate it will do something. Like render
, open
or getData
.
All non-functions should have a noun as a name, not a verb.
Should start with is
, has
, will
or should
. Like isValid
or hasValues
.
Avoid negations. Prefer isShown
over isHidden
or
isEnabled
over isDisabled
. Do not use names like notEditable
.
PascalCase Every individual word start with an upper case character, no underscores, no dashes.
camelCase Starts with a lower case character, every following individual word start with an upper case character, no underscores, no dashes.
SNAKE_UPPER_CASE Only use upper case characters, individual words must be separated with an underscore.
camelCase Starts with a lower case character, every following individual word start with an upper case character, no underscores, no dashes.
PascalCase Every individual word start with an upper case character, no underscores, no dashes.
Deconstruct props in the function parameters rather than inside the function body
interface IProps {
propOne: string
propTwo: string
}
const Component = ({ propOne, propTwo }: IProps) => { ... }
// rather than
const Component = (props: IProps) => {
const { propOne, propTwo } = props
...
}
Named export rather than default export
export const Component = () => { ... }
// rather than
const Component = () => { ... }
export default Component
When in need to use a colour, use the defined variable from the globals.ccs
file rather than adding hex codes.
.class {
color: var(--text);
}
/* rather than */
.class {
color: #272727;
}