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

Add modeler Config to Rule Configs #92

Merged
merged 2 commits into from
Nov 21, 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
30 changes: 28 additions & 2 deletions lib/Linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { toSemverMinor } from './utils/version';

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

const NoopResolver = new StaticResolver({});

/**
* @param {Object} [options]
* @param {string} [options.modeler='desktop']
Expand Down Expand Up @@ -113,7 +115,7 @@ export class Linter {
{
extends: `plugin:bpmnlint-plugin-camunda-compat/${ configName }`
},
...this._plugins.map(({ config }) => config)
...this._plugins.map(({ config = {} }) => config)
];

return configs.reduce(
Expand Down Expand Up @@ -150,14 +152,18 @@ export class Linter {
};
}

config.rules = addConfig(config.rules, {
modeler: this._modeler
});

const ConfigResolver = new StaticResolver({
[ `config:bpmnlint-plugin-camunda-compat/${ configName }` ]: config
});

return new Resolver([
ConfigResolver,
RulesResolver,
...this._plugins.map(({ resolver }) => resolver)
...this._plugins.map(({ resolver = NoopResolver }) => resolver)
]);
}
}
Expand All @@ -171,4 +177,24 @@ function getConfigName(executionPlatform, executionPlatformVersion) {

function toLowerCase(string) {
return string.toLowerCase();
}

function addConfig(rules, configToAdd) {
let rulesWithConfig = {};

for (let name in rules) {
let type, config;

if (Array.isArray(rules[ name ])) {
type = rules[ name ][0];
config = rules[ name ][1] || {};
} else {
type = rules[ name ];
config = {};
}

rulesWithConfig[ name ] = [ type, { ...config, ...configToAdd } ];
}

return rulesWithConfig;
}
35 changes: 34 additions & 1 deletion test/spec/Linter.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import sinon from 'sinon';

import StaticResolver from 'bpmnlint/lib/resolver/static-resolver';

Expand Down Expand Up @@ -54,6 +54,39 @@ describe('Linter', function() {
expect(linter._modeler).to.equal('web');
});


it('should add modeler configuration to rule configurations', async function() {

// given
const spy = sinon.spy(() => {
return {
check: () => {}
};
});

const linter = new Linter({
modeler: 'web',
plugins: [
{
resolver: new StaticResolver({
'rule:bpmnlint-plugin-camunda-compat/element-type': spy
})
}
]
});

const { root } = await createModdle(simpleXML);

// when
await linter.lint(root);

// then
expect(spy).to.have.been.calledWithMatch({
modeler: 'web',
version: '8.0'
});
});

});


Expand Down
2 changes: 0 additions & 2 deletions test/spec/utils/documentation.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai';

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

describe('utils/documentation', function() {
Expand Down
2 changes: 0 additions & 2 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai';

import {
getErrorMessage,
getExecutionPlatformLabel
Expand Down
2 changes: 0 additions & 2 deletions test/spec/utils/lint-helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai';

import Linter from 'bpmnlint/lib/linter';

async function lintNode(node, rule, config = {},) {
Expand Down
2 changes: 0 additions & 2 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai';

import { Linter } from '../../..';

import {
Expand Down
2 changes: 0 additions & 2 deletions test/spec/utils/types.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai';

import { getTypeString } from '../../../lib/utils/types';

import { createElement } from '../../helper';
Expand Down
Loading