From 240c3be014be47e5292a73680082a20c510bec7d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Mar 2022 19:26:22 +0000 Subject: [PATCH] Mandate use of js-sdk/src/matrix import over js-sdk/src (#21257) --- .eslintrc.js | 33 +++++++++++++++++++++++++++++++++ docs/translating-dev.md | 2 +- src/vector/app.tsx | 2 +- test/app-tests/joining-test.tsx | 4 ++-- test/app-tests/loading-test.tsx | 4 ++-- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b59ea416ad..bb3a06d355 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,6 +25,39 @@ module.exports = { // We disable this while we're transitioning "@typescript-eslint/no-explicit-any": "off", + + // Ban matrix-js-sdk/src imports in favour of matrix-js-sdk/src/matrix imports to prevent unleashing hell. + "no-restricted-imports": ["error", { + "paths": [{ + "name": "matrix-js-sdk", + "message": "Please use matrix-js-sdk/src/matrix instead", + }, { + "name": "matrix-js-sdk/", + "message": "Please use matrix-js-sdk/src/matrix instead", + }, { + "name": "matrix-js-sdk/src", + "message": "Please use matrix-js-sdk/src/matrix instead", + }, { + "name": "matrix-js-sdk/src/", + "message": "Please use matrix-js-sdk/src/matrix instead", + }, { + "name": "matrix-js-sdk/src/index", + "message": "Please use matrix-js-sdk/src/matrix instead", + }, { + "name": "matrix-react-sdk", + "message": "Please use matrix-react-sdk/src/index instead", + }, { + "name": "matrix-react-sdk/", + "message": "Please use matrix-react-sdk/src/index instead", + }], + "patterns": [{ + "group": ["matrix-js-sdk/lib", "matrix-js-sdk/lib/", "matrix-js-sdk/lib/**"], + "message": "Please use matrix-js-sdk/src/* instead", + }, { + "group": ["matrix-react-sdk/lib", "matrix-react-sdk/lib/", "matrix-react-sdk/lib/**"], + "message": "Please use matrix-react-sdk/src/* instead", + }], + }], }, }], }; diff --git a/docs/translating-dev.md b/docs/translating-dev.md index cac5174d77..505558bc3d 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -30,7 +30,7 @@ function getColorName(hex) { ## Adding new strings - 1. Check if the import ``import { _t } from 'matrix-react-sdk/lib/languageHandler';`` is present. If not add it to the other import statements. Also import `_td` if needed. + 1. Check if the import ``import { _t } from 'matrix-react-sdk/src/languageHandler';`` is present. If not add it to the other import statements. Also import `_td` if needed. 1. Add ``_t()`` to your string. (Don't forget curly braces when you assign an expression to JSX attributes in the render method). If the string is introduced at a point before the translation system has not yet been initialized, use `_td()` instead, and call `_t()` at the appropriate time. 1. Run `yarn i18n` to update ``src/i18n/strings/en_EN.json`` 1. If you added a string with a plural, you can add other English plural variants to ``src/i18n/strings/en_EN.json`` (remeber to edit the one in the same project as the source file containing your new translation). diff --git a/src/vector/app.tsx b/src/vector/app.tsx index 61069fa236..e92ad90136 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -19,7 +19,7 @@ limitations under the License. */ import React from 'react'; -import * as sdk from 'matrix-react-sdk'; +import * as sdk from 'matrix-react-sdk/src/index'; import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; import { _td, newTranslatableError } from 'matrix-react-sdk/src/languageHandler'; import AutoDiscoveryUtils from 'matrix-react-sdk/src/utils/AutoDiscoveryUtils'; diff --git a/test/app-tests/joining-test.tsx b/test/app-tests/joining-test.tsx index 2dfaa293b0..23f956f2d4 100644 --- a/test/app-tests/joining-test.tsx +++ b/test/app-tests/joining-test.tsx @@ -18,8 +18,8 @@ limitations under the License. import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; import WebPlatform from '../../src/vector/platform/WebPlatform'; -import * as sdk from "matrix-react-sdk"; -import * as jssdk from "matrix-js-sdk"; +import * as sdk from "matrix-react-sdk/src/index"; +import * as jssdk from "matrix-js-sdk/src/matrix"; import "../skin-sdk"; import "../jest-mocks"; import React from "react"; diff --git a/test/app-tests/loading-test.tsx b/test/app-tests/loading-test.tsx index 9eb6415696..e86c83759f 100644 --- a/test/app-tests/loading-test.tsx +++ b/test/app-tests/loading-test.tsx @@ -25,8 +25,8 @@ import React from 'react'; import ReactDOM from 'react-dom'; import ReactTestUtils from 'react-dom/test-utils'; import MatrixReactTestUtils from 'matrix-react-test-utils'; -import * as jssdk from 'matrix-js-sdk'; -import * as sdk from 'matrix-react-sdk'; +import * as jssdk from 'matrix-js-sdk/src/matrix'; +import * as sdk from 'matrix-react-sdk/src/index'; import {MatrixClientPeg} from 'matrix-react-sdk/src/MatrixClientPeg'; import {Views} from 'matrix-react-sdk/src/components/structures/MatrixChat'; import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';