diff --git a/eslint.config.mjs b/eslint.config.mjs index ff148dc3552871..f702a77de0423b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -87,6 +87,18 @@ const restrictedImportPaths = [ }, ]; +const restrictedImportPatterns = [ + { + group: ['sentry/components/devtoolbar/*'], + message: 'Do not depend on toolbar internals', + }, + { + group: ['*.spec*'], + message: + 'Do not import from test files. This causes tests to be executed multiple times.', + }, +]; + // Used by both: `languageOptions` & `parserOptions` const ecmaVersion = 6; // TODO(ryan953): change to 'latest' @@ -418,17 +430,7 @@ export default typescript.config([ 'no-restricted-imports': [ 'error', { - patterns: [ - { - group: ['sentry/components/devtoolbar/*'], - message: 'Do not depend on toolbar internals', - }, - { - group: ['*.spec*'], - message: - 'Do not import from test files. This causes tests to be executed multiple times.', - }, - ], + patterns: restrictedImportPatterns, paths: restrictedImportPaths, }, ], @@ -824,6 +826,26 @@ export default typescript.config([ 'testing-library/no-unnecessary-act': 'off', }, }, + { + name: 'files/sentry-test', + files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'], + rules: { + 'no-restricted-imports': [ + 'error', + { + patterns: restrictedImportPatterns, + paths: [ + // @ts-ignore + ...restrictedImportPaths, + { + name: 'sentry/locale', + message: 'Translations are not needed in tests.', + }, + ], + }, + ], + }, + }, { // We specify rules explicitly for the sdk-loader here so we do not have // eslint ignore comments included in the source file, which is consumed diff --git a/static/app/components/charts/optionSelector.spec.tsx b/static/app/components/charts/optionSelector.spec.tsx index c71fd82d17fba2..7b85e09c90ba4f 100644 --- a/static/app/components/charts/optionSelector.spec.tsx +++ b/static/app/components/charts/optionSelector.spec.tsx @@ -5,7 +5,6 @@ import {initializeOrg} from 'sentry-test/initializeOrg'; import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; import OptionSelector from 'sentry/components/charts/optionSelector'; -import {t} from 'sentry/locale'; describe('Charts > OptionSelector (Multiple)', function () { const features = ['discover-basic']; @@ -32,7 +31,7 @@ describe('Charts > OptionSelector (Multiple)', function () { { diff --git a/static/app/locale.spec.tsx b/static/app/locale.spec.tsx index 24ed1da55610ad..e3de6afed630df 100644 --- a/static/app/locale.spec.tsx +++ b/static/app/locale.spec.tsx @@ -1,6 +1,7 @@ import {render, screen} from 'sentry-test/reactTestingLibrary'; import {textWithMarkupMatcher} from 'sentry-test/utils'; +// eslint-disable-next-line no-restricted-imports import {tct} from 'sentry/locale'; describe('locale.gettextComponentTemplate', () => { diff --git a/static/app/views/alerts/rules/issue/messagingIntegrationModal.spec.tsx b/static/app/views/alerts/rules/issue/messagingIntegrationModal.spec.tsx index 5b0ff541150835..bb55c8ab260385 100644 --- a/static/app/views/alerts/rules/issue/messagingIntegrationModal.spec.tsx +++ b/static/app/views/alerts/rules/issue/messagingIntegrationModal.spec.tsx @@ -9,7 +9,6 @@ import { ModalBody, ModalFooter, } from 'sentry/components/globalModal/components'; -import {t} from 'sentry/locale'; import MessagingIntegrationModal from 'sentry/views/alerts/rules/issue/messagingIntegrationModal'; import {MessagingIntegrationAnalyticsView} from 'sentry/views/alerts/rules/issue/setupMessagingIntegrationButton'; @@ -27,8 +26,8 @@ describe('MessagingIntegrationModal', function () { closeModal={closeModal} Header={makeClosableHeader(() => {})} Body={ModalBody} - headerContent={t('Connect with a messaging tool')} - bodyContent={t('Receive alerts and digests right where you work.')} + headerContent={'Connect with a messaging tool'} + bodyContent={'Receive alerts and digests right where you work.'} providers={providers} CloseButton={makeCloseButton(() => {})} Footer={ModalFooter} diff --git a/static/app/views/insights/mobile/screens/views/screensLandingPage.spec.tsx b/static/app/views/insights/mobile/screens/views/screensLandingPage.spec.tsx index 197bbf54728ecc..6d1c1357f559be 100644 --- a/static/app/views/insights/mobile/screens/views/screensLandingPage.spec.tsx +++ b/static/app/views/insights/mobile/screens/views/screensLandingPage.spec.tsx @@ -4,7 +4,6 @@ import {ProjectFixture} from 'sentry-fixture/project'; import {render, screen, waitFor, within} from 'sentry-test/reactTestingLibrary'; -import {t} from 'sentry/locale'; import {useLocation} from 'sentry/utils/useLocation'; import usePageFilters from 'sentry/utils/usePageFilters'; import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject'; @@ -199,14 +198,14 @@ describe('Screens Landing Page', function () { organization.features = []; render(, {organization}); expect( - await screen.findByText(t("You don't have access to this feature")) + await screen.findByText("You don't have access to this feature") ).toBeInTheDocument(); }); it('shows content if permission is there', async function () { organization.features = [MODULE_FEATURE]; render(, {organization}); - expect(await screen.findAllByText(t('Mobile Screens'))).toHaveLength(2); + expect(await screen.findAllByText('Mobile Screens')).toHaveLength(2); }); }); }); diff --git a/static/app/views/issueDetails/streamline/sidebar/solutionsHubDrawer.spec.tsx b/static/app/views/issueDetails/streamline/sidebar/solutionsHubDrawer.spec.tsx index ee3a30a2e4cf4b..2785a80d97fbef 100644 --- a/static/app/views/issueDetails/streamline/sidebar/solutionsHubDrawer.spec.tsx +++ b/static/app/views/issueDetails/streamline/sidebar/solutionsHubDrawer.spec.tsx @@ -14,7 +14,6 @@ import { waitForElementToBeRemoved, } from 'sentry-test/reactTestingLibrary'; -import {t} from 'sentry/locale'; import {EntryType} from 'sentry/types/event'; import {SolutionsHubDrawer} from 'sentry/views/issueDetails/streamline/sidebar/solutionsHubDrawer'; @@ -142,9 +141,7 @@ describe('SolutionsHubDrawer', () => { const startButton = screen.getByRole('button', {name: 'Start Autofix'}); await userEvent.click(startButton); - expect( - await screen.findByRole('button', {name: t('Start Over')}) - ).toBeInTheDocument(); + expect(await screen.findByRole('button', {name: 'Start Over'})).toBeInTheDocument(); }); it('displays autofix steps and Start Over button when autofixData is available', async () => { @@ -158,9 +155,7 @@ describe('SolutionsHubDrawer', () => { {organization} ); - expect( - await screen.findByRole('button', {name: t('Start Over')}) - ).toBeInTheDocument(); + expect(await screen.findByRole('button', {name: 'Start Over'})).toBeInTheDocument(); }); it('resets autofix on clicking the start over button', async () => { @@ -174,7 +169,7 @@ describe('SolutionsHubDrawer', () => { {organization} ); - const startOverButton = await screen.findByRole('button', {name: t('Start Over')}); + const startOverButton = await screen.findByRole('button', {name: 'Start Over'}); expect(startOverButton).toBeInTheDocument(); await userEvent.click(startOverButton); diff --git a/static/app/views/projectInstall/createProject.spec.tsx b/static/app/views/projectInstall/createProject.spec.tsx index b7514707f37fd4..8d61b0382e81a9 100644 --- a/static/app/views/projectInstall/createProject.spec.tsx +++ b/static/app/views/projectInstall/createProject.spec.tsx @@ -13,7 +13,6 @@ import { } from 'sentry-test/reactTestingLibrary'; import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator'; -import {tct} from 'sentry/locale'; import OrganizationStore from 'sentry/stores/organizationStore'; import TeamStore from 'sentry/stores/teamStore'; import type {Organization} from 'sentry/types/organization'; @@ -220,11 +219,7 @@ describe('CreateProject', function () { expect(frameWorkModalMockRequests.projectCreationMockRequest).toHaveBeenCalledTimes( 1 ); - expect(addSuccessMessage).toHaveBeenCalledWith( - tct('Created project [project]', { - project: 'testProj', - }) - ); + expect(addSuccessMessage).toHaveBeenCalledWith('Created project testProj'); }); it('should display error message on proj creation failure', async function () { @@ -261,11 +256,7 @@ describe('CreateProject', function () { expect(frameWorkModalMockRequests.projectCreationMockRequest).toHaveBeenCalledTimes( 1 ); - expect(addErrorMessage).toHaveBeenCalledWith( - tct('Failed to create project [project]', { - project: 'apple-ios', - }) - ); + expect(addErrorMessage).toHaveBeenCalledWith('Failed to create project apple-ios'); }); it('should display success message when using member endpoint', async function () { @@ -293,10 +284,7 @@ describe('CreateProject', function () { frameWorkModalMockRequests.experimentalprojectCreationMockRequest ).toHaveBeenCalledTimes(1); expect(addSuccessMessage).toHaveBeenCalledWith( - tct('Created [project] under new team [team]', { - project: 'testProj', - team: '#testTeam', - }) + 'Created testProj under new team #testTeam' ); }); diff --git a/static/app/views/projectInstall/createProject.tsx b/static/app/views/projectInstall/createProject.tsx index fedc1a2d372723..082bb93976be4b 100644 --- a/static/app/views/projectInstall/createProject.tsx +++ b/static/app/views/projectInstall/createProject.tsx @@ -167,17 +167,14 @@ function CreateProject() { ProjectsStore.onCreateSuccess(projectData, organization.slug); if (team) { - addSuccessMessage( - tct('Created project [project]', { - project: `${projectData.slug}`, - }) - ); + addSuccessMessage(t('Created project %s', `${projectData.slug}`)); } else { addSuccessMessage( - tct('Created [project] under new team [team]', { - project: `${projectData.slug}`, - team: `#${projectData.team_slug}`, - }) + t( + 'Created %s under new team %s', + `${projectData.slug}`, + `#${projectData.team_slug}` + ) ); } @@ -189,11 +186,7 @@ function CreateProject() { } catch (err) { setInFlight(false); setErrors(err.responseJSON); - addErrorMessage( - tct('Failed to create project [project]', { - project: `${projectName}`, - }) - ); + addErrorMessage(t('Failed to create project %s', `${projectName}`)); // Only log this if the error is something other than: // * The user not having access to create a project, or, diff --git a/tests/js/setup.ts b/tests/js/setup.ts index 2db719beec27c4..22b7d07fa09c32 100644 --- a/tests/js/setup.ts +++ b/tests/js/setup.ts @@ -11,6 +11,7 @@ import {ConfigFixture} from 'sentry-fixture/config'; import {resetMockDate} from 'sentry-test/utils'; import type {Client} from 'sentry/__mocks__/api'; +// eslint-disable-next-line no-restricted-imports import {DEFAULT_LOCALE_DATA, setLocale} from 'sentry/locale'; import ConfigStore from 'sentry/stores/configStore'; import {DANGEROUS_SET_TEST_HISTORY} from 'sentry/utils/browserHistory';