warn about ts file extension
Summary: remove statically analysable life from typescript guidelines and let eslint handle it Reviewed By: passy Differential Revision: D33819891 fbshipit-source-id: 3cc3cb512607c3651cd3a9e48228d83bab5bb64a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e9da574720
commit
4c83fbb524
@@ -144,6 +144,7 @@ module.exports = {
|
||||
'flipper/no-relative-imports-across-packages': [2],
|
||||
'flipper/no-electron-remote-imports': [1],
|
||||
'flipper/no-console-error-without-context': [2],
|
||||
'flipper/no-ts-file-extension': 1,
|
||||
'communist-spelling/communist-spelling': [1, {allow: ['cancelled']}],
|
||||
|
||||
// promise rules, see https://github.com/xjamundx/eslint-plugin-promise for details on each of them
|
||||
|
||||
@@ -16,11 +16,15 @@ import noElectronRemoteImports, {
|
||||
import noConsoleErrorWithoutContext, {
|
||||
RULE_NAME as noConsoleErrorWithoutContextRuleName,
|
||||
} from './rules/noConsoleErrorWithoutContext';
|
||||
import noTsFileExtension, {
|
||||
RULE_NAME as noTsFileExtensionRuleName,
|
||||
} from './rules/noTsFileExtension';
|
||||
|
||||
module.exports = {
|
||||
rules: {
|
||||
[noRelativeImportsAcrossPackagesRuleName]: noRelativeImportsAcrossPackages,
|
||||
[noElectronRemoteImportsRuleName]: noElectronRemoteImports,
|
||||
[noConsoleErrorWithoutContextRuleName]: noConsoleErrorWithoutContext,
|
||||
[noTsFileExtensionRuleName]: noTsFileExtension,
|
||||
},
|
||||
};
|
||||
|
||||
48
desktop/eslint-plugin-flipper/src/rules/noTsFileExtension.ts
Normal file
48
desktop/eslint-plugin-flipper/src/rules/noTsFileExtension.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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 path from 'path';
|
||||
import {createESLintRule} from '../utils/createEslintRule';
|
||||
|
||||
type Options = [];
|
||||
|
||||
export type MessageIds = 'noTsFileExtension';
|
||||
export const RULE_NAME = 'no-ts-file-extension';
|
||||
|
||||
export default createESLintRule<Options, MessageIds>({
|
||||
name: RULE_NAME,
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Prefer "tsx" file extensions',
|
||||
recommended: 'error',
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
noTsFileExtension: 'Use "tsx" file extension instead of "ts"',
|
||||
},
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const filename = context.getFilename();
|
||||
const ext = path.extname(filename);
|
||||
const isTs = ext === '.ts' && !filename.endsWith('.d.ts');
|
||||
|
||||
return {
|
||||
Program(node) {
|
||||
if (isTs) {
|
||||
context.report({
|
||||
node: node,
|
||||
messageId: 'noTsFileExtension',
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -158,7 +158,6 @@ To start Flipper against a specific OnDemand instance, set FB_ONDEMAND flag, e.g
|
||||
</FbInternalOnly>
|
||||
|
||||
## Guidelines for writing TypeScript
|
||||
* **Important:** Use `.tsx` file extension for all TypeScript files (instead of `.ts`)
|
||||
* Prefer `type` for React props and state over interfaces
|
||||
* Don’t prefix interfaces with `I`
|
||||
* Enums, Types and Interfaces use PascalCase (uppercase first letter)
|
||||
|
||||
Reference in New Issue
Block a user