add eslint rule to ensure exported const are prefixed with UMB_
This commit is contained in:
committed by
Jacob Overgaard
parent
33fbce39c8
commit
d65935323f
@@ -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"
|
||||
|
||||
@@ -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_',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -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'),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user