@mindfiredigital/eslint-plugin-hub
Version:
eslint-plugin-hub is a powerful, flexible ESLint plugin that provides a curated set of rules to enhance code readability, maintainability, and prevent common errors. Whether you're working with vanilla JavaScript, TypeScript, React, or Angular, eslint-plu
41 lines (37 loc) • 1.06 kB
JavaScript
const camelCase = /^[a-z][a-zA-Z0-9]*$/;
module.exports = {
rules: {
'vars-camelcase': {
meta: {
type: 'problem',
docs: {
description:
'Enforce camelCase naming convention for variables declared with var, let, or const',
},
schema: [], // No options needed
messages: {
notCamelCase: "Variable '{{name}}' should be in camelCase.",
},
},
create(context) {
return {
VariableDeclarator(node) {
const variableName = node.id && node.id.name;
// Ensure variableName is a string before proceeding
if (typeof variableName !== 'string') {
return;
}
// Check if variable name is in camelCase
if (!camelCase.test(variableName)) {
context.report({
node: node.id,
messageId: 'notCamelCase',
data: { name: variableName },
});
}
},
};
},
},
},
};