@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
43 lines (38 loc) • 1.2 kB
JavaScript
const path = require('path');
module.exports = {
rules: {
'folder-kebabcase': {
meta: {
type: 'problem',
docs: {
description: 'Enforce lowercase and kebab-case naming for folders',
},
messages: {
invalidFolderName:
'Folder "{{name}}" should be lowercase and follow kebab-case if it has more than 10 characters.',
},
},
create(context) {
return {
Program(node) {
const filePath = context.getFilename();
const dirName = path.basename(path.dirname(filePath));
// Regex for lowercase and kebab-case
const lowerCaseRegex = /^[a-z0-9]+(-[a-z0-9]+)*$/;
// Validate the directory name
const isDirNameInvalid =
(dirName.length > 10 && !lowerCaseRegex.test(dirName)) ||
(dirName.length <= 10 && dirName !== dirName.toLowerCase());
if (isDirNameInvalid) {
context.report({
node,
messageId: 'invalidFolderName',
data: { name: dirName },
});
}
},
};
},
},
},
};