mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-11-29 19:05:22 +01:00
63 lines
No EOL
1.8 KiB
JavaScript
63 lines
No EOL
1.8 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
var _utils = require("./utils");
|
|
const isChainRestricted = (chain, restriction) => {
|
|
if (_utils.ModifierName.hasOwnProperty(restriction) || restriction.endsWith('.not')) {
|
|
return chain.startsWith(restriction);
|
|
}
|
|
return chain === restriction;
|
|
};
|
|
var _default = (0, _utils.createRule)({
|
|
name: __filename,
|
|
meta: {
|
|
docs: {
|
|
category: 'Best Practices',
|
|
description: 'Disallow specific matchers & modifiers',
|
|
recommended: false
|
|
},
|
|
type: 'suggestion',
|
|
schema: [{
|
|
type: 'object',
|
|
additionalProperties: {
|
|
type: ['string', 'null']
|
|
}
|
|
}],
|
|
messages: {
|
|
restrictedChain: 'Use of `{{ restriction }}` is disallowed',
|
|
restrictedChainWithMessage: '{{ message }}'
|
|
}
|
|
},
|
|
defaultOptions: [{}],
|
|
create(context, [restrictedChains]) {
|
|
return {
|
|
CallExpression(node) {
|
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'expect') {
|
|
return;
|
|
}
|
|
const chain = jestFnCall.members.map(nod => (0, _utils.getAccessorValue)(nod)).join('.');
|
|
for (const [restriction, message] of Object.entries(restrictedChains)) {
|
|
if (isChainRestricted(chain, restriction)) {
|
|
context.report({
|
|
messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
|
data: {
|
|
message,
|
|
restriction
|
|
},
|
|
loc: {
|
|
start: jestFnCall.members[0].loc.start,
|
|
end: jestFnCall.members[jestFnCall.members.length - 1].loc.end
|
|
}
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
exports.default = _default; |