adding lint rule for console.error

This commit is contained in:
Martin McKeaveney 2024-04-10 17:27:15 +01:00
parent 27dec6e390
commit 639b8970f9
2 changed files with 22 additions and 1 deletions

View File

@ -43,7 +43,8 @@
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"local-rules/no-budibase-imports": "error"
"local-rules/no-budibase-imports": "error",
"local-rules/no-console-error": "error"
}
},
{

View File

@ -1,4 +1,24 @@
module.exports = {
"no-console-error": {
create: function(context) {
return {
CallExpression(node) {
if (
node.callee.type === "MemberExpression" &&
node.callee.object.name === "console" &&
node.callee.property.name === "error" &&
node.arguments.length === 1 &&
node.arguments[0].name.startsWith("err")
) {
context.report({
node,
message: 'Using console.error(err) on its own is not allowed. Either provide context to the error (console.error(msg, err)) or throw it.',
})
}
},
};
},
},
"no-budibase-imports": {
create: function (context) {
return {