Skip to content

Commit

Permalink
fix(react-native): remove wrong jest import (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
subzero10 authored Jan 4, 2024
1 parent 89e33e0 commit ec9498a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
10 changes: 6 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"eslint-plugin-local-rules"
],
"rules": {
"quotes": [
"error",
Expand All @@ -32,16 +36,14 @@
{
"argsIgnorePattern": "^_"
}
]
],
"local-rules/no-test-imports": "error"
},
"settings": {
"import/ignore": [
"node_modules/react-native/index\\.js$"
]
},
"plugins": [
"@typescript-eslint"
],
"env":
{
"jest": true,
Expand Down
45 changes: 45 additions & 0 deletions eslint-local-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const TEST_FILE_REGEX= /\.(spec|test)\.(js|ts|tsx)/
// we can add more modules here
const TEST_MODULES_REGEX= /jest/

module.exports = {
'no-test-imports': {
meta: {
type: 'problem',
docs: {
description: 'Disallow importing test files in source code',
},
fixable: 'code',
schema: [] // no options
},
create: function(context) {
return {
ImportDeclaration: function(node) {
const physicalFilename = context.getPhysicalFilename().toLowerCase();

// stop if the filename is not in the src/ directory or is a test file
if (!physicalFilename.includes('src/') ||
physicalFilename.match(TEST_FILE_REGEX)) {
return;
}

// if we get here, we're in a source file, not a test file
const importSource = node.source.value.trim();
// do not allow importing test files or modules that include 'jest', such as 'jest-fetch-mock'
if (importSource.match(TEST_FILE_REGEX) ||
importSource.match(TEST_MODULES_REGEX)) {
context.report({
node: node,
message: 'Do not import test modules in source code',
fix: function(fixer) {
return fixer.remove(node);
}
});
}
}
};
}
}
};
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@typescript-eslint/parser": "^5.6.0",
"eslint": "^8.20.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-local-rules": "^2.0.1",
"eslint-plugin-promise": "^6.0.0",
"lerna": "^6.0.1"
},
Expand Down
1 change: 0 additions & 1 deletion packages/react-native/src/transport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Types, Util } from '@honeybadger-io/core'
import { Platform } from 'react-native'
import * as pkg from '../package.json'
import fetch from 'jest-fetch-mock';

export class Transport implements Types.Transport {
defaultHeaders(): Record<string, string> {
Expand Down

0 comments on commit ec9498a

Please sign in to comment.