Mandate use of js-sdk/src/matrix import over js-sdk/src (#21257)

pull/21277/head
Michael Telatynski 2022-03-01 19:26:22 +00:00 committed by GitHub
parent 087aed80dd
commit 240c3be014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 6 deletions

View File

@ -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",
}],
}],
},
}],
};

View File

@ -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).

View File

@ -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';

View File

@ -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";

View File

@ -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';