Skip to content

Commit

Permalink
feat: add element-templates linter plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Jul 20, 2023
1 parent a8ac15e commit fbb556a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 27 deletions.
2 changes: 1 addition & 1 deletion client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ export class App extends PureComponent {

const plugins = this.getPlugins(`lintRules.${ type }`);

const linter = tabProvider.getLinter(plugins);
const linter = await tabProvider.getLinter(plugins, tab, this);

if (!linter) {
return;
Expand Down
13 changes: 11 additions & 2 deletions client/src/app/TabsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ import DMNIcon from '../../resources/icons/file-types/DMN-16x16.svg';
import FormIcon from '../../resources/icons/file-types/Form-16x16.svg';
import { getDefaultVersion } from './tabs/EngineProfile';

import { getCloudTemplates } from '../util/elementTemplates';
import { CloudElementTemplatesLinterPlugin } from 'bpmn-js-element-templates';

const BPMN_HELP_MENU = [
{
label: 'BPMN 2.0 Tutorial',
Expand Down Expand Up @@ -194,10 +197,16 @@ export default class TabsProvider {
action: 'create-cloud-bpmn-diagram'
} ];
},
getLinter(plugins) {
async getLinter(plugins = [], tab, app) {
const templates = await app.getConfig('bpmn.elementTemplates', tab.file) || [];
const cloudTemplates = getCloudTemplates(templates);

return new BpmnLinter({
modeler: 'desktop',
plugins
plugins: [
...plugins,
CloudElementTemplatesLinterPlugin(cloudTemplates)
]
});
}
},
Expand Down
110 changes: 86 additions & 24 deletions client/src/app/__tests__/TabsProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ describe('TabsProvider', function() {
'dmn'
].forEach((type) => {

it(type, function() {
it(type, async function() {

// given
Flags.init({
Expand All @@ -961,7 +961,7 @@ describe('TabsProvider', function() {
const tabsProvider = new TabsProvider().getProvider(type);

// when
const linter = tabsProvider.getLinter();
const linter = await tabsProvider.getLinter();

// then
expect(linter).to.be.null;
Expand All @@ -976,13 +976,17 @@ describe('TabsProvider', function() {
'form'
].forEach((type) => {

it(type, function() {
it(type, async function() {

// given
const tabsProvider = new TabsProvider().getProvider(type);

// when
const linter = tabsProvider.getLinter();
const linter = await tabsProvider.getLinter(
[],
{ },
{ getConfig: () => {} }
);

// then
expect(linter).to.exist;
Expand All @@ -991,32 +995,90 @@ describe('TabsProvider', function() {
});


[
'bpmn',
'cloud-bpmn'
].forEach((type) => {
it('cloud-bpmn should configure element template plugin', async function() {

it(`${ type } plugins`, function() {
// given
const tabsProvider = new TabsProvider().getProvider('cloud-bpmn');
const templates = [
{
'$schema': 'https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json',
'name': 'empty',
'id': 'constraints.empty',
'appliesTo': [
'bpmn:Task'
],
'properties': []
}
];
const appMock = {
getConfig: () => templates
};

// given
const plugin = {
config: {},
resolver: {
resolveConfig() {},
resolveRule() {}
}
};
const tabMock = { file: 'foo' };

const tabsProvider = new TabsProvider().getProvider(type);
// when
const linter = await tabsProvider.getLinter(
[],
tabMock,
appMock
);

// when
const linter = tabsProvider.getLinter([ plugin ]);
// then
const plugins = linter.getPlugins();

// then
expect(linter).to.exist;
expect(linter.getPlugins()).to.have.length(1);
});
expect(linter).to.exist;
expect(plugins).to.have.length(1);

const rules = plugins[0].config.rules;
expect(rules['element-templates/validate']).to.exist;
expect(rules['element-templates/validate'][1].templates).to.eql(templates);
});


it('cloud-bpmn plugins', async function() {

// given
const plugin = {
config: {},
resolver: {
resolveConfig() {},
resolveRule() {}
}
};

const tabsProvider = new TabsProvider().getProvider('cloud-bpmn');

// when
const linter = await tabsProvider.getLinter(
[ plugin ],
{},
{ getConfig: () => {} });

// then
expect(linter).to.exist;
expect(linter.getPlugins()).to.have.length(2);
});


it('bpmn plugins', async function() {

// given
const plugin = {
config: {},
resolver: {
resolveConfig() {},
resolveRule() {}
}
};

const tabsProvider = new TabsProvider().getProvider('bpmn');

// when
const linter = await tabsProvider.getLinter([ plugin ]);

// then
expect(linter).to.exist;
expect(linter.getPlugins()).to.have.length(1);
});

});
Expand Down

0 comments on commit fbb556a

Please sign in to comment.