Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-native): remove wrong jest import #1280

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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