Files
flipper/desktop/eslint-plugin-flipper/src/rules/noElectronRemoteImports.ts
Andres Suarez 79023ee190 Update copyright headers from Facebook to Meta
Reviewed By: bhamodi

Differential Revision: D33331422

fbshipit-source-id: 016e8dcc0c0c7f1fc353a348b54fda0d5e2ddc01
2021-12-27 14:31:45 -08:00

54 lines
1.5 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {TSESTree} from '@typescript-eslint/experimental-utils';
import {createESLintRule} from '../utils/createEslintRule';
type Options = [];
export type MessageIds = 'noElectronRemoteImports';
export const RULE_NAME = 'no-electron-remote-imports';
export default createESLintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'suggestion',
docs: {
description: '`remote` is slow. Please be careful when using it.',
category: 'Possible Errors',
recommended: 'warn',
},
schema: [],
messages: {
noElectronRemoteImports:
'Accessing properties on the `remote` object is blocking and 10,000x slower than a local one. Please consider alternatives or cache your access.',
},
},
defaultOptions: [],
create(context) {
return {
ImportDeclaration(node: TSESTree.ImportDeclaration) {
if (node.source.value === 'electron') {
const hasImport =
node.specifiers.filter(
(v) =>
v.type === 'ImportSpecifier' && v.imported.name === 'remote',
).length > 0;
if (hasImport) {
context.report({
node,
messageId: 'noElectronRemoteImports',
});
}
}
},
};
},
});