-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to camunda/camunda-modeler#3951 feat: add `no-duplicate-execution-listeners` rule feat: add `no-execution-listeners` rule feat: add `execution-listener` rule
- Loading branch information
Showing
10 changed files
with
699 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { | ||
ERROR_TYPES, | ||
findExtensionElement | ||
} = require('../utils/element'); | ||
|
||
const { reportErrors } = require('../utils/reporter'); | ||
|
||
const { skipInNonExecutableProcess } = require('../utils/rule'); | ||
|
||
module.exports = skipInNonExecutableProcess(function() { | ||
function check(node, reporter) { | ||
const executionListeners = findExtensionElement(node, 'zeebe:ExecutionListeners'); | ||
|
||
if (!executionListeners) { | ||
return; | ||
} | ||
|
||
const errors = hasDuplicatedExecutionListeners(executionListeners, node); | ||
|
||
if (errors && errors.length) { | ||
reportErrors(node, reporter, errors); | ||
} | ||
} | ||
|
||
return { | ||
check | ||
}; | ||
}); | ||
|
||
// helpers ////////// | ||
function hasDuplicatedExecutionListeners(executionListeners, parentNode = null) { | ||
const listeners = executionListeners.get('listeners'); | ||
|
||
// (1) find duplicates | ||
const duplicates = []; | ||
const events = new Map(); | ||
for (const listener of listeners) { | ||
const eventName = listener.get('eventType'), | ||
type = listener.get('type'); | ||
|
||
if (!events.has(eventName)) { | ||
events.set(eventName, new Set([ type ])); | ||
continue; | ||
} | ||
|
||
const types = events.get(eventName); | ||
if (types.has(type)) { | ||
duplicates.push(listener); | ||
} else { | ||
types.add(type); | ||
} | ||
} | ||
|
||
// (2) report error for each duplicate | ||
if (duplicates.length) { | ||
return duplicates.map(duplicate => { | ||
const eventName = duplicate.get('eventType'), | ||
type = duplicate.get('type'); | ||
|
||
// (3) find properties with duplicate | ||
const duplicateProperties = listeners.filter(listener => listener.get('eventType') === eventName && listener.get('type') === type); | ||
|
||
// (4) report error | ||
return { | ||
message: `Duplicate execution listener with event type <${eventName}> and job type <${type}>`, | ||
path: null, | ||
data: { | ||
type: ERROR_TYPES.PROPERTY_VALUE_DUPLICATED, | ||
node: executionListeners, | ||
parentNode: parentNode === executionListeners ? null : parentNode, | ||
duplicatedProperty: 'type', | ||
duplicatedPropertyValue: type, | ||
properties: duplicateProperties, | ||
propertiesName: 'listeners' | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { | ||
findExtensionElement, | ||
hasProperties | ||
} = require('../utils/element'); | ||
|
||
const { reportErrors } = require('../utils/reporter'); | ||
|
||
const { skipInNonExecutableProcess } = require('../utils/rule'); | ||
|
||
|
||
module.exports = skipInNonExecutableProcess(function() { | ||
function check(node, reporter) { | ||
|
||
console.log(node); | ||
|
||
const executionListeners = findExtensionElement(node, 'zeebe:ExecutionListeners'); | ||
|
||
if (!executionListeners) { | ||
return; | ||
} | ||
|
||
const listeners = executionListeners.get('listeners'); | ||
const errors = listeners.flatMap(listener => hasProperties(listener, { | ||
type: { | ||
required: true | ||
} | ||
}, node)); | ||
|
||
if (errors.length) { | ||
reportErrors(node, reporter, errors); | ||
} | ||
} | ||
|
||
return { | ||
check | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { reportErrors } = require('../utils/reporter'); | ||
|
||
const { skipInNonExecutableProcess } = require('../utils/rule'); | ||
|
||
const { hasNoExtensionElement } = require('../utils/element'); | ||
|
||
const ALLOWED_VERSION = '8.6'; | ||
|
||
module.exports = skipInNonExecutableProcess(function() { | ||
function check(node, reporter) { | ||
const errors = hasNoExtensionElement(node, 'zeebe:ExecutionListeners', node, ALLOWED_VERSION); | ||
|
||
if (errors && errors.length) { | ||
reportErrors(node, reporter, errors); | ||
} | ||
} | ||
|
||
return { | ||
check | ||
}; | ||
}); |
Oops, something went wrong.