|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.7 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 |
|
|---|
| 8 | var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
|---|
| 9 |
|
|---|
| 10 | var _utils = require("./utils");
|
|---|
| 11 |
|
|---|
| 12 | var _default = (0, _utils.createRule)({
|
|---|
| 13 | name: __filename,
|
|---|
| 14 | meta: {
|
|---|
| 15 | docs: {
|
|---|
| 16 | category: 'Best Practices',
|
|---|
| 17 | description: 'Disallow using `exports` in files containing tests',
|
|---|
| 18 | recommended: 'error'
|
|---|
| 19 | },
|
|---|
| 20 | messages: {
|
|---|
| 21 | unexpectedExport: `Do not export from a test file.`
|
|---|
| 22 | },
|
|---|
| 23 | type: 'suggestion',
|
|---|
| 24 | schema: []
|
|---|
| 25 | },
|
|---|
| 26 | defaultOptions: [],
|
|---|
| 27 |
|
|---|
| 28 | create(context) {
|
|---|
| 29 | const exportNodes = [];
|
|---|
| 30 | let hasTestCase = false;
|
|---|
| 31 | return {
|
|---|
| 32 | 'Program:exit'() {
|
|---|
| 33 | if (hasTestCase && exportNodes.length > 0) {
|
|---|
| 34 | for (const node of exportNodes) {
|
|---|
| 35 | context.report({
|
|---|
| 36 | node,
|
|---|
| 37 | messageId: 'unexpectedExport'
|
|---|
| 38 | });
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | },
|
|---|
| 42 |
|
|---|
| 43 | CallExpression(node) {
|
|---|
| 44 | if ((0, _utils.isTestCaseCall)(node)) {
|
|---|
| 45 | hasTestCase = true;
|
|---|
| 46 | }
|
|---|
| 47 | },
|
|---|
| 48 |
|
|---|
| 49 | 'ExportNamedDeclaration, ExportDefaultDeclaration'(node) {
|
|---|
| 50 | exportNodes.push(node);
|
|---|
| 51 | },
|
|---|
| 52 |
|
|---|
| 53 | 'AssignmentExpression > MemberExpression'(node) {
|
|---|
| 54 | let {
|
|---|
| 55 | object,
|
|---|
| 56 | property
|
|---|
| 57 | } = node;
|
|---|
| 58 |
|
|---|
| 59 | if (object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
|---|
| 60 | ({
|
|---|
| 61 | object,
|
|---|
| 62 | property
|
|---|
| 63 | } = object);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports?$/u.test(property.name)) {
|
|---|
| 67 | exportNodes.push(node);
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | };
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | });
|
|---|
| 75 |
|
|---|
| 76 | exports.default = _default; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.