Skip to content

Commit

Permalink
feat: allow passing context to linter
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed May 24, 2024
1 parent 47b44a3 commit b2193f1
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 72 deletions.
11 changes: 7 additions & 4 deletions lib/Linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Linter {
this._plugins = [ ...defaultPlugins, ...plugins ];
}

async lint(contents) {
async lint(contents, context) {
let rootElement;

if (isString(contents)) {
Expand Down Expand Up @@ -95,9 +95,12 @@ export class Linter {
executionPlatformVersion,
message: getErrorMessage(
report,
executionPlatform,
executionPlatformVersion,
this._modeler
{
...context,
executionPlatform,
executionPlatformVersion,
modeler: this._modeler
}
),
propertiesPanel: {
entryIds
Expand Down
117 changes: 80 additions & 37 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getIndefiniteArticle(type, uppercase = true) {
return uppercase ? 'A' : 'a';
}

export function getErrorMessage(report, executionPlatform, executionPlatformVersion, modeler = 'desktop') {
export function getErrorMessage(report, context = {}) {
const {
data,
message
Expand All @@ -82,81 +82,86 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers
const { type } = data;

if (type === ERROR_TYPES.CHILD_ELEMENT_TYPE_NOT_ALLOWED) {
return getChildElementTypeNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
return getChildElementTypeNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.ELEMENT_COLLAPSED_NOT_ALLOWED) {
return getElementCollapsedNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
return getElementCollapsedNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED) {
return getElementPropertyValueDuplicatedErrorMessage(report);
return getElementPropertyValueDuplicatedErrorMessage(report, context);
}

if (type === ERROR_TYPES.ELEMENT_TYPE_NOT_ALLOWED) {
return getElementTypeNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
return getElementTypeNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.EXTENSION_ELEMENT_NOT_ALLOWED) {
return getExtensionElementNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
return getExtensionElementNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.EXTENSION_ELEMENT_REQUIRED) {
return getExtensionElementRequiredErrorMessage(report);
return getExtensionElementRequiredErrorMessage(report, context);
}

if (type === ERROR_TYPES.PROPERTY_DEPENDENT_REQUIRED) {
return getPropertyDependentRequiredErrorMessage(report);
return getPropertyDependentRequiredErrorMessage(report, context);
}

if (type === ERROR_TYPES.PROPERTY_NOT_ALLOWED) {
return getPropertyNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion, modeler);
return getPropertyNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.PROPERTY_REQUIRED) {
return getPropertyRequiredErrorMessage(report, executionPlatform, executionPlatformVersion);
return getPropertyRequiredErrorMessage(report, context);
}

if (type === ERROR_TYPES.PROPERTY_VALUE_DUPLICATED) {
return getPropertyValueDuplicatedErrorMessage(report);
return getPropertyValueDuplicatedErrorMessage(report, context);
}

if (type == ERROR_TYPES.PROPERTY_VALUE_NOT_ALLOWED) {
return getPropertyValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion, modeler);
return getPropertyValueNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.PROPERTY_VALUE_REQUIRED) {
return getPropertyValueRequiredErrorMessage(report, executionPlatform, executionPlatformVersion);
return getPropertyValueRequiredErrorMessage(report, context);
}

if (type === ERROR_TYPES.EXPRESSION_REQUIRED) {
return getExpressionRequiredErrorMessage(report);
return getExpressionRequiredErrorMessage(report, context);
}

if (type === ERROR_TYPES.EXPRESSION_VALUE_NOT_ALLOWED) {
return getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
return getExpressionValueNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.EXPRESSION_NOT_ALLOWED) {
return getExpressionNotAllowedErrorMessage(report);
return getExpressionNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.EVENT_BASED_GATEWAY_TARGET_NOT_ALLOWED) {
return getEventBasedGatewayTargetNotAllowedErrorMessage(report);
return getEventBasedGatewayTargetNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.SECRET_EXPRESSION_FORMAT_DEPRECATED) {
return getSecretExpressionFormatDeprecatedErrorMessage(report);
return getSecretExpressionFormatDeprecatedErrorMessage(report, context);
}

if (type === ERROR_TYPES.LOOP_NOT_ALLOWED) {
return getLoopNotAllowedErrorMessage(report);
return getLoopNotAllowedErrorMessage(report, context);
}

return message;
}

function getChildElementTypeNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getChildElementTypeNotAllowedErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const { data } = report;

const {
Expand All @@ -176,7 +181,12 @@ function getChildElementTypeNotAllowedErrorMessage(report, executionPlatform, ex
);
}

function getElementCollapsedNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getElementCollapsedNotAllowedErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const {
data,
message
Expand All @@ -193,7 +203,12 @@ function getElementCollapsedNotAllowedErrorMessage(report, executionPlatform, ex
return message;
}

function getElementTypeNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getElementTypeNotAllowedErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const { data } = report;

const {
Expand All @@ -206,7 +221,7 @@ function getElementTypeNotAllowedErrorMessage(report, executionPlatform, executi
return getSupportedMessage(`${ getIndefiniteArticle(typeString) } <${ typeString }>`, executionPlatform, executionPlatformVersion, allowedVersion);
}

function getPropertyValueDuplicatedErrorMessage(report) {
function getPropertyValueDuplicatedErrorMessage(report, context) {
const {
data,
message
Expand All @@ -228,7 +243,12 @@ function getPropertyValueDuplicatedErrorMessage(report) {
return message;
}

function getPropertyValueRequiredErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getPropertyValueRequiredErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const {
data,
message
Expand Down Expand Up @@ -258,7 +278,12 @@ function getPropertyValueRequiredErrorMessage(report, executionPlatform, executi
return message;
}

function getExtensionElementNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getExtensionElementNotAllowedErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const {
data,
message
Expand Down Expand Up @@ -300,7 +325,7 @@ function getExtensionElementNotAllowedErrorMessage(report, executionPlatform, ex
return message;
}

function getExtensionElementRequiredErrorMessage(report) {
function getExtensionElementRequiredErrorMessage(report, context) {
const {
data,
message
Expand Down Expand Up @@ -345,7 +370,7 @@ function getExtensionElementRequiredErrorMessage(report) {
return message;
}

function getPropertyDependentRequiredErrorMessage(report) {
function getPropertyDependentRequiredErrorMessage(report, context) {
const {
data,
message
Expand All @@ -371,7 +396,13 @@ function getPropertyDependentRequiredErrorMessage(report) {
return message;
}

function getPropertyNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion, modeler = 'desktop') {
function getPropertyNotAllowedErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion,
modeler = 'desktop'
} = context;

const {
data,
message
Expand Down Expand Up @@ -418,7 +449,12 @@ function getPropertyNotAllowedErrorMessage(report, executionPlatform, executionP
}


function getPropertyRequiredErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getPropertyRequiredErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const {
data,
message
Expand Down Expand Up @@ -550,7 +586,7 @@ function getPropertyRequiredErrorMessage(report, executionPlatform, executionPla
return message;
}

function getExpressionRequiredErrorMessage(report) {
function getExpressionRequiredErrorMessage(report, context) {
const {
data,
message
Expand All @@ -571,7 +607,9 @@ function getExpressionRequiredErrorMessage(report) {
return message;
}

function getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
function getExpressionValueNotAllowedErrorMessage(report, context) {
const { executionPlatformVersion } = context;

const {
data,
message
Expand Down Expand Up @@ -620,7 +658,7 @@ function getSupportedMessage(prefix, executionPlatform, executionPlatformVersion
return `${ prefix } is not supported by ${ getExecutionPlatformLabel(executionPlatform, executionPlatformVersion) }`;
}

function getExpressionNotAllowedErrorMessage(report) {
function getExpressionNotAllowedErrorMessage(report, context) {
const {
data
} = report;
Expand All @@ -640,7 +678,7 @@ function getExpressionNotAllowedErrorMessage(report) {
return report.message;
}

function getEventBasedGatewayTargetNotAllowedErrorMessage(report) {
function getEventBasedGatewayTargetNotAllowedErrorMessage(report, context) {
const { data } = report;

const { node } = data;
Expand All @@ -652,7 +690,12 @@ function getEventBasedGatewayTargetNotAllowedErrorMessage(report) {
return report.message;
}

function getPropertyValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion, modeler = 'desktop') {
function getPropertyValueNotAllowedErrorMessage(report, context) {
const {
executionPlatform,
executionPlatformVersion
} = context;

const {
data,
message
Expand All @@ -674,15 +717,15 @@ function getPropertyValueNotAllowedErrorMessage(report, executionPlatform, execu
return message;
}

function getSecretExpressionFormatDeprecatedErrorMessage(report) {
function getSecretExpressionFormatDeprecatedErrorMessage(report, context) {
const { data } = report;

const { property } = data;

return `Property <${ property }> uses deprecated secret expression format secrets.SECRET, use {{secrets.SECRET}} instead`;
}

function getElementPropertyValueDuplicatedErrorMessage(report) {
function getElementPropertyValueDuplicatedErrorMessage(report, context) {
const {
data,
message
Expand All @@ -703,7 +746,7 @@ function getElementPropertyValueDuplicatedErrorMessage(report) {
return message;
}

function getLoopNotAllowedErrorMessage(report) {
function getLoopNotAllowedErrorMessage(report, context) {
const { data } = report;

const { elements } = data;
Expand Down
Loading

0 comments on commit b2193f1

Please sign in to comment.