id-match
要求标识符匹配指定的正则表达式
"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton
在项目中一致地命名事物是代码创建的一个经常被低估的方面。如果做得正确,它可以为您的团队节省不必要的头疼和误导时间。此规则允许您精确定义和强制执行团队应使用的变量和函数名称。不再局限于 camelCase、snake_case、PascalCase 或 oHungarianNotation。id-match 满足您的所有需求!
规则详情
此规则要求分配和 function
定义中的标识符与指定的正则表达式匹配。
选项
此规则具有指定正则表达式的字符串选项。
fJnESZ8MCn9lxFB0/qPFY+Q0hHaEmJrPrUQ4R178vQVqXRuwZx3UnW4/3E2Pv/Y/
{
"id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}
NS3nOhe77b03gAl00PuBTth/TSJ8tVx11FoqQweTg37viARK9xi6S++nP6Pzd7QeQZaWuBFOOHV1WThYZmg6gHt5sHftkLk2rkF0ReM4YoMLjIHUZrWL1Go6puoVu1m8
/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/
var my_favorite_color = "#112C85";
var _myFavoriteColor = "#112C85";
var myFavoriteColor_ = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
// ...
}
obj.do_something = function() {
// ...
};
class My_Class {}
class myClass {
do_something() {}
}
class myClass {
#do_something() {}
}
NS3nOhe77b03gAl00PuBTth/TSJ8tVx11FoqQweTg37viARK9xi6S++nP6Pzd7QebOOpdnhoU9K/hz7EHOHbYalHsSOTomRZeOXQwbI1Uk0q8Cdnz9M34QeRW/vib4gH
/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/
var myFavoriteColor = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
my_pref: 1
};
class myClass {}
class myClass {
doSomething() {}
}
class myClass {
#doSomething() {}
}
8pL03zs6hZobHhmJ5wsandpdaRcjH6aPQALoLE0Fz/HNdCOjd7leS8z+vp9suWsx
- 30EkeAXfVP9YEEHfpJCRY3UazgwFkx0H/OHoPL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==
properties
NS3nOhe77b03gAl00PuBTth/TSJ8tVx11FoqQweTg35PE0Vr/hANjhH2v2g4pH6LZ+IlBf6EyZufAduFUAmtdhAaHm4lBjylwS5JcY3oqSfkwv1bUfbDuKNRc2P/TOSyB/SAaj6IHphroPb/AIxHqA==
/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/
var obj = {
my_pref: 1
};
classFields
NS3nOhe77b03gAl00PuBTth/TSJ8tVx11FoqQweTg35PE0Vr/hANjhH2v2g4pH6LirrQ3FKe/hi/xrk8NpRw6OmSccBfP+yU81GR2y62LcakXD8bZMbxwapf5VvNxvhHtwyByznbQh+8M6FfhSNbug==
/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/
class myClass {
my_pref = 1;
}
class myClass {
#my_pref = 1;
}
onlyDeclarations
NS3nOhe77b03gAl00PuBTth/TSJ8tVx11FoqQweTg35PE0Vr/hANjhH2v2g4pH6LZFc0BhUXpduguD4+KrAMc9gVWvL7s0Ola1efUm4ke5u9+9+ky6d4h3rRcuKAi6mYIbmikon3r0/4/mp9EAF9RIt7N595AmBlbQeQVXXy7lQ=
/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/
do_something(__dirname);
ignoreDestructuring: false
P9K6qX5NEbGUTYyzcipfhoCP91lSFuDC8JLzaRg21fPEniRwb7iMc4rM1CQR9tVgA86IT2dOiU0aRqOL/BguJyDxdsAyLQKD/yqabsIzlqTQWlZ8knH8FH2j9fiWwBrAU+Lp2np21asyz2ODtTgspQ==
/*eslint id-match: [2, "^[^_]+$", { "ignoreDestructuring": false }]*/
var { category_id } = query;
var { category_id = 1 } = query;
var { category_id: category_id } = query;
var { category_id: category_alias } = query;
var { category_id: categoryId, ...other_props } = query;
ignoreDestructuring: true
NS3nOhe77b03gAl00PuBTkGFVPLG9+QgDaT93kAXUC4X+6h6ARAcU25si6G/sI83rrsDoWsIFau1nkefC8WomlxHHwJKL1vn5Dqlh9vQuSOfRFeB72vxvLIkBFpItQBNU/Lsw4XO0rDSbjByMIDRXw==
/*eslint id-match: [2, "^[^_]+$", { "ignoreDestructuring": true }]*/
var { category_id: category_alias } = query;
var { category_id, ...other_props } = query;
NS3nOhe77b03gAl00PuBTkGFVPLG9+QgDaT93kAXUC4X+6h6ARAcU25si6G/sI83rrsDoWsIFau1nkefC8WomlxHHwJKL1vn5Dqlh9vQuSNt5x2tVVEuJTT7ZipUepigLfRmzTamxYgGFB/XE/tHjA==
/*eslint id-match: [2, "^[^_]+$", { "ignoreDestructuring": true }]*/
var { category_id } = query;
var { category_id = 1 } = query;
var { category_id: category_id } = query;
何时不使用
ev8kq/DWfVh0ue6A8DZoV/NGjG0lEzYbwRHcOVas/nL1iUSMzoV3B+kUZimhj9ksI7cnldYaYZEB5Jgc57rXo8HWJxVjkNZAUZm3QHsKqjTOIxt14FgpE1YyugaqIPVZ1ErrAQdp4LIYnDxdkK8IMbCKBGA5CA4h7RngkHpOM/fiPk6e3gnND9jK2QuBlpg4S2G79XcTIl6Zd7YQkXY+gKyvwE5lAg5OOPkUlV8PuVU6GCdrJl9X54pEO84nPDPKS8vZYdhwgKgy8BziMwtj+g==