|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 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 | const newHookContext = () => ({
|
|---|
| 11 | beforeAll: 0,
|
|---|
| 12 | beforeEach: 0,
|
|---|
| 13 | afterAll: 0,
|
|---|
| 14 | afterEach: 0
|
|---|
| 15 | });
|
|---|
| 16 |
|
|---|
| 17 | var _default = (0, _utils.createRule)({
|
|---|
| 18 | name: __filename,
|
|---|
| 19 | meta: {
|
|---|
| 20 | docs: {
|
|---|
| 21 | category: 'Best Practices',
|
|---|
| 22 | description: 'Disallow duplicate setup and teardown hooks',
|
|---|
| 23 | recommended: false
|
|---|
| 24 | },
|
|---|
| 25 | messages: {
|
|---|
| 26 | noDuplicateHook: 'Duplicate {{hook}} in describe block'
|
|---|
| 27 | },
|
|---|
| 28 | schema: [],
|
|---|
| 29 | type: 'suggestion'
|
|---|
| 30 | },
|
|---|
| 31 | defaultOptions: [],
|
|---|
| 32 |
|
|---|
| 33 | create(context) {
|
|---|
| 34 | const hookContexts = [newHookContext()];
|
|---|
| 35 | return {
|
|---|
| 36 | CallExpression(node) {
|
|---|
| 37 | if ((0, _utils.isDescribeCall)(node)) {
|
|---|
| 38 | hookContexts.push(newHookContext());
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | if ((0, _utils.isHook)(node)) {
|
|---|
| 42 | const currentLayer = hookContexts[hookContexts.length - 1];
|
|---|
| 43 | currentLayer[node.callee.name] += 1;
|
|---|
| 44 |
|
|---|
| 45 | if (currentLayer[node.callee.name] > 1) {
|
|---|
| 46 | context.report({
|
|---|
| 47 | messageId: 'noDuplicateHook',
|
|---|
| 48 | data: {
|
|---|
| 49 | hook: node.callee.name
|
|---|
| 50 | },
|
|---|
| 51 | node
|
|---|
| 52 | });
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | },
|
|---|
| 56 |
|
|---|
| 57 | 'CallExpression:exit'(node) {
|
|---|
| 58 | if ((0, _utils.isDescribeCall)(node)) {
|
|---|
| 59 | hookContexts.pop();
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | };
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | });
|
|---|
| 67 |
|
|---|
| 68 | exports.default = _default; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.