| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 |
|
|---|
| 8 | var _utils = require("./utils");
|
|---|
| 9 |
|
|---|
| 10 | var _default = (0, _utils.createRule)({
|
|---|
| 11 | name: __filename,
|
|---|
| 12 | meta: {
|
|---|
| 13 | docs: {
|
|---|
| 14 | category: 'Best Practices',
|
|---|
| 15 | description: 'Disallow specific matchers & modifiers',
|
|---|
| 16 | recommended: false
|
|---|
| 17 | },
|
|---|
| 18 | type: 'suggestion',
|
|---|
| 19 | schema: [{
|
|---|
| 20 | type: 'object',
|
|---|
| 21 | additionalProperties: {
|
|---|
| 22 | type: ['string', 'null']
|
|---|
| 23 | }
|
|---|
| 24 | }],
|
|---|
| 25 | messages: {
|
|---|
| 26 | restrictedChain: 'Use of `{{ chain }}` is disallowed',
|
|---|
| 27 | restrictedChainWithMessage: '{{ message }}'
|
|---|
| 28 | }
|
|---|
| 29 | },
|
|---|
| 30 | defaultOptions: [{}],
|
|---|
| 31 |
|
|---|
| 32 | create(context, [restrictedChains]) {
|
|---|
| 33 | return {
|
|---|
| 34 | CallExpression(node) {
|
|---|
| 35 | if (!(0, _utils.isExpectCall)(node)) {
|
|---|
| 36 | return;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | const {
|
|---|
| 40 | matcher,
|
|---|
| 41 | modifier
|
|---|
| 42 | } = (0, _utils.parseExpectCall)(node);
|
|---|
| 43 |
|
|---|
| 44 | if (matcher) {
|
|---|
| 45 | const chain = matcher.name;
|
|---|
| 46 |
|
|---|
| 47 | if (chain in restrictedChains) {
|
|---|
| 48 | const message = restrictedChains[chain];
|
|---|
| 49 | context.report({
|
|---|
| 50 | messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
|---|
| 51 | data: {
|
|---|
| 52 | message,
|
|---|
| 53 | chain
|
|---|
| 54 | },
|
|---|
| 55 | node: matcher.node.property
|
|---|
| 56 | });
|
|---|
| 57 | return;
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | if (modifier) {
|
|---|
| 62 | const chain = modifier.name;
|
|---|
| 63 |
|
|---|
| 64 | if (chain in restrictedChains) {
|
|---|
| 65 | const message = restrictedChains[chain];
|
|---|
| 66 | context.report({
|
|---|
| 67 | messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
|---|
| 68 | data: {
|
|---|
| 69 | message,
|
|---|
| 70 | chain
|
|---|
| 71 | },
|
|---|
| 72 | node: modifier.node.property
|
|---|
| 73 | });
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | if (matcher && modifier) {
|
|---|
| 79 | const chain = `${modifier.name}.${matcher.name}`;
|
|---|
| 80 |
|
|---|
| 81 | if (chain in restrictedChains) {
|
|---|
| 82 | const message = restrictedChains[chain];
|
|---|
| 83 | context.report({
|
|---|
| 84 | messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
|---|
| 85 | data: {
|
|---|
| 86 | message,
|
|---|
| 87 | chain
|
|---|
| 88 | },
|
|---|
| 89 | loc: {
|
|---|
| 90 | start: modifier.node.property.loc.start,
|
|---|
| 91 | end: matcher.node.property.loc.end
|
|---|
| 92 | }
|
|---|
| 93 | });
|
|---|
| 94 | return;
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | };
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | });
|
|---|
| 103 |
|
|---|
| 104 | exports.default = _default; |
|---|