|
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.4 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 |
|
|---|
| 8 | var _path = require("path");
|
|---|
| 9 |
|
|---|
| 10 | var _utils = require("./utils");
|
|---|
| 11 |
|
|---|
| 12 | const mocksDirName = '__mocks__';
|
|---|
| 13 |
|
|---|
| 14 | const isMockPath = path => path.split(_path.posix.sep).includes(mocksDirName);
|
|---|
| 15 |
|
|---|
| 16 | const isMockImportLiteral = expression => (0, _utils.isStringNode)(expression) && isMockPath((0, _utils.getStringValue)(expression));
|
|---|
| 17 |
|
|---|
| 18 | var _default = (0, _utils.createRule)({
|
|---|
| 19 | name: __filename,
|
|---|
| 20 | meta: {
|
|---|
| 21 | type: 'problem',
|
|---|
| 22 | docs: {
|
|---|
| 23 | category: 'Best Practices',
|
|---|
| 24 | description: 'Disallow manually importing from `__mocks__`',
|
|---|
| 25 | recommended: 'error'
|
|---|
| 26 | },
|
|---|
| 27 | messages: {
|
|---|
| 28 | noManualImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`jest.mock\` and import from the original module path.`
|
|---|
| 29 | },
|
|---|
| 30 | schema: []
|
|---|
| 31 | },
|
|---|
| 32 | defaultOptions: [],
|
|---|
| 33 |
|
|---|
| 34 | create(context) {
|
|---|
| 35 | return {
|
|---|
| 36 | ImportDeclaration(node) {
|
|---|
| 37 | if (isMockImportLiteral(node.source)) {
|
|---|
| 38 | context.report({
|
|---|
| 39 | node,
|
|---|
| 40 | messageId: 'noManualImport'
|
|---|
| 41 | });
|
|---|
| 42 | }
|
|---|
| 43 | },
|
|---|
| 44 |
|
|---|
| 45 | 'CallExpression[callee.name="require"]'(node) {
|
|---|
| 46 | const [arg] = node.arguments;
|
|---|
| 47 |
|
|---|
| 48 | if (arg && isMockImportLiteral(arg)) {
|
|---|
| 49 | context.report({
|
|---|
| 50 | node: arg,
|
|---|
| 51 | messageId: 'noManualImport'
|
|---|
| 52 | });
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | };
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | });
|
|---|
| 60 |
|
|---|
| 61 | exports.default = _default; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.