Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Linter): correctly parse C7 XML #85

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const modeler = new Modeler({

// configure to be used with desktop or web modeler
const linter = new Linter({
modeler: 'web'
modeler: 'web', // `desktop` or `web` modeler, defaults to `desktop`
type: 'cloud' // `cloud` or `platform` diagrams, defaults to `cloud`
});

// lint by passing definitions
Expand Down
27 changes: 20 additions & 7 deletions lib/Linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { resolver as RulesResolver } from './compiled-config';

import modelerModdle from 'modeler-moddle/resources/modeler.json';
import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe.json';
import camundaModdle from 'camunda-bpmn-moddle/resources/camunda.json';

import { getErrorMessage } from './utils/error-messages';
import { getEntryIds } from './utils/properties-panel';
Expand All @@ -19,18 +20,30 @@ import { toSemverMinor } from './utils/version';

import { getDocumentationUrl } from './utils/documentation';

const moddle = new BpmnModdle({
modeler: modelerModdle,
zeebe: zeebeModdle
});

/**
* @param {Object} [options]
* @param {string} [options.modeler='desktop']
* @param {Array<Object>} [options.plugins=[]]
* @param {string} [options.type='cloud']
*/
export class Linter {
constructor(options = {}) {
const {
modeler = 'desktop',
plugins = []
plugins = [],
type = 'cloud'
} = options;

this._moddle = new BpmnModdle({
modeler: modelerModdle,

// Zeebe and Camunda moddle extensions can't be used together
// cf. https://github.com/camunda/camunda-modeler/issues/3853#issuecomment-1731145100
...(type === 'cloud' ?
{ zeebe: zeebeModdle } :
{ camunda: camundaModdle })
});

this._modeler = modeler;
this._plugins = plugins;
}
Expand All @@ -39,7 +52,7 @@ export class Linter {
let rootElement;

if (isString(contents)) {
({ rootElement } = await moddle.fromXML(contents));
({ rootElement } = await this._moddle.fromXML(contents));
} else {
rootElement = contents;
}
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"bpmnlint": "^9.2.0",
"bpmnlint-plugin-camunda-compat": "^2.7.1",
"bpmnlint-utils": "^1.0.2",
"camunda-bpmn-moddle": "^7.0.1",
"clsx": "^2.0.0",
"min-dash": "^4.0.0",
"min-dom": "^4.1.0",
Expand Down
94 changes: 75 additions & 19 deletions test/spec/Linter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ describe('Linter', function() {

describe('camunda-cloud', function() {

beforeEach(function() {
linter = new Linter({ type: 'cloud' });
});

const versions = [
[ '1.0', camundaCloud10XML, camundaCloud10ErrorsXML ],
[ '1.1', camundaCloud11XML, camundaCloud11ErrorsXML ],
Expand All @@ -165,7 +169,7 @@ describe('Linter', function() {

describe(`Camunda Cloud ${ version }`, function() {

describe('no errors', function() {
describe('from moddle', function() {

it('should not have errors', async function() {

Expand All @@ -179,10 +183,6 @@ describe('Linter', function() {
expect(reports).to.be.empty;
});

});


describe('errors', function() {

it('should have errors', async function() {

Expand All @@ -198,6 +198,30 @@ describe('Linter', function() {

});


describe('from XML', function() {

it('should not have errors', async function() {

// when
const reports = await linter.lint(xml);

// then
expect(reports).to.be.empty;
});


it('should have errors', async function() {

// when
const reports = await linter.lint(errorsXML);

// then
expect(reports).not.to.be.empty;
});

});

});

});
Expand All @@ -207,6 +231,10 @@ describe('Linter', function() {

describe('camunda-platform', function() {

beforeEach(function() {
linter = new Linter({ type: 'platform' });
});

const versions = [
[ '7.19', camundaPlatform719XML, camundaPlatform719ErrorsXML ],
[ '7.20', camundaPlatform720XML, camundaPlatform720ErrorsXML ]
Expand All @@ -229,29 +257,57 @@ describe('Linter', function() {

describe(`Camunda Platform ${ version }`, function() {

it('should not have errors', async function() {
describe('from moddle', function() {

it('should not have errors', async function() {

// given
const { root } = await createModdleCamundaPlatform(xml);

// when
const reports = await linter.lint(root);

// then
expect(reports).to.be.empty;
});


// given
const { root } = await createModdleCamundaPlatform(xml);
it('should have errors', async function() {

// given
const { root } = await createModdleCamundaPlatform(errorsXML);

// when
const reports = await linter.lint(root);

// when
const reports = await linter.lint(root);
// then
expect(reports).not.to.be.empty;
});

// then
expect(reports).to.be.empty;
});


it('should have errors', async function() {
describe('from xml', function() {

it('should not have errors', async function() {

// when
const reports = await linter.lint(xml);

// then
expect(reports).to.be.empty;
});


it('should have errors', async function() {

// given
const { root } = await createModdleCamundaPlatform(errorsXML);
// when
const reports = await linter.lint(errorsXML);

// when
const reports = await linter.lint(root);
// then
expect(reports).not.to.be.empty;
});

// then
expect(reports).not.to.be.empty;
});

});
Expand Down
Loading