Enforce function parameters to adhere to a pattern (parameter-pattern)
This rule enforces that parameter names start with a p
and are pascal cased. There’s an exception for
starting with the _
character as that (by convention) is often used for unused parameters.
🔧 The --fix option
on the command line renames parameters to the correct pattern (including
any use in the function body).
Rule Details
Examples of incorrect code for this rule:
function f(thing, callback) {
// do stuff
}
const f = (thing) => {
/* do stuff */
};
const f = (piedPiper) => {
/* do stuff */
};
const f = (параметр) => {
/* do stuff */
};
Examples of correct code for this rule:
function f(pThing, pFunction) {
// do stuff
}
const f = (pThing) => {
/* do stuff */
};
const f = (pPiedPiper) => {
/* do stuff */
};
const f = (pПараметр) => {
/* do stuff */
};
function f(_, pThing) {
// to stuff with pThing, but not with _
}
Options
exceptions
Type: array
If you want to allow some parameter names to not adhere to the rule, you can
specify these. E.g. if you want to allow ekseption
as a parameter, do this:
"budapestian/parameter-pattern": [
"error",
{ "exceptions": ["ekseption"] }
]
When Not To Use It
- If you don’t want to have this parameter naming convention.
- When you use parameter names that contain non-ascii characters from alphabets that
don’t have upper and lower case.
E.g.参数
will be flagged and cannot be auto corrected a.t.m., butпараметр
andparamètre
can be auto corrected. LikewisepПараметр
andpParamètre
are valid.