add eslint rule to ensure exported const are prefixed with UMB_

This commit is contained in:
Mads Rasmussen
2023-11-19 11:36:50 +01:00
committed by Jacob Overgaard
parent 33fbce39c8
commit d65935323f
3 changed files with 29 additions and 0 deletions

View File

@@ -51,6 +51,7 @@
"exceptions": ["@umbraco-cms", "@open-wc/testing", "@storybook", "msw", "."]
}
],
"local-rules/prefix-exported-constants": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": "warn"

View File

@@ -0,0 +1,27 @@
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Ensure all exported consts are prefixed with UMB_',
},
},
create: function (context) {
return {
ExportNamedDeclaration(node) {
if (node.declaration && node.declaration.type === 'VariableDeclaration') {
const declaration = node.declaration.declarations[0];
const { id, init } = declaration;
if (id && id.type === 'Identifier' && init && init.type === 'Literal' && typeof init.value === 'string') {
if (!id.name.startsWith('UMB_')) {
context.report({
node: id,
message: 'Exported constant should be prefixed with UMB_',
});
}
}
}
},
};
},
};

View File

@@ -18,4 +18,5 @@ module.exports = {
'prefer-import-aliases': preferImportAliasesRule,
'prefer-static-styles-last': preferStaticStylesLastRule,
'umb-class-prefix': umbClassPrefixRule,
'prefix-exported-constants': require('./devops/eslint/rules/prefix-exported-const.cjs'),
};