Skip to content

Latest commit

 

History

History
107 lines (73 loc) · 1.9 KB

constants.md

File metadata and controls

107 lines (73 loc) · 1.9 KB

Enforce capital letters in constant variable names. (constants)

Capital letters in constants increase the clarity of the code.

This does not apply if the constants are already in capital letters.

Users change lowercase letters directly to uppercase letters will not result in errors.

Rule Details

Examples of 🔴 incorrect code for this rule:

const number_value = 123456;
const string_value = "string";

Examples of 🟢 correct code for this rule:

const NUMBER_VALUE = 123456;
const STRING_VALUE = "string";

Rule Options

"rules": {
  "component/constants":  [
    <enabled>,
    { customType: <customType> }
  ]
}
  • enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
  • customType: optional data type to ["number", "string", "bigint", "object", "array"] (default to ["number", "string"]).

customType

🔴 Incorrect

When customType is ["array", "object"]:

const array_value = [];
const object_value = {};

When customType is ["bigint", "number", "string"]:

const bigint_value = 100n;
const number_value = 29;
const string_value = "string";

When customType is ["array", "number"]:

const array_value = [], number_value = 29, string_value = "string";

When customType is ["null"]:

const null_value = null;

🟢 Correct

When customType is ["array", "object"]:

const ARRAY_VALUE = [];
const OBJECT_VALUE = {};

When customType is ["bigint", "number", "string"]:

const BIGINT_VALUE = 100n;
const NUMBER_VALUE = 29;
const STRING_VALUE = "string";

When customType is ["array", "number"]:

const ARRAY_VALUE = [], NUMBER_VALUE = 29, string_value = "string";

When customType is ["null"]:

const NULL_VALUE = null;

When Not To Use It

Do not use it if there is no code convention for a constant.