β¬ οΈ Back to Table of Contents
π no-poorly-typed-ts-props¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 1 |
| π¦ Imports | 4 |
| π Variables & Constants | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin-internal/src/rules/no-poorly-typed-ts-props.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'no-poorly-typed-ts-props' |
meta.type |
'problem' |
meta.docs.description |
"Enforce that rules don't use TS API properties with known bad type definitions" |
meta.docs.requiresTypeChecking |
true |
meta.fixable |
'code' |
meta.hasSuggestions |
true |
meta.messages.doNotUse |
'Do not use {{type}}.{{property}} because it is poorly typed.' |
meta.messages.doNotUseWithFixer |
'Do not use {{type}}.{{property}} because it is poorly typed. Use {{type}}.{{fixWith}} instead.' |
meta.messages.suggestedFix |
'Use {{type}}.{{fixWith}} instead.' |
meta.schema |
[] |
defaultOptions |
[] |
Entry point: create β documented under Functions.
π¦ Imports¶
| Name | Source |
|---|---|
TSESLint |
@typescript-eslint/utils |
TSESTree |
@typescript-eslint/utils |
ESLintUtils |
@typescript-eslint/utils |
createRule |
../util/index.js |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
BANNED_PROPERTIES |
{ type: string; fixWith: string; prop... |
const | [ { type: 'Symbol', fixWith: 'getDeclarations()', property: 'declarations', }... |
β |
Functions¶
create(context: any): { 'MemberExpression[computed = false]'(node: TSESTree.Membe⦶
Parameters:
contextany
Returns: { 'MemberExpression[computed = false]'(node: TSESTree.MemberExpressionNonComputedName): void; }
Calls:
ESLintUtils.getParserServicesservices.getTypeAtLocationobjectType.getSymbolobjectSymbol?.getNameservices.getSymbolAtLocationsymbol?.getDeclarationsdecls?.somedecl.getSourceFile().fileName.includescontext.reportfixer.replaceText
Internal Comments:
Code
create(context) {
const services = ESLintUtils.getParserServices(context);
return {
'MemberExpression[computed = false]'(
node: TSESTree.MemberExpressionNonComputedName,
): void {
for (const banned of BANNED_PROPERTIES) {
if (node.property.name !== banned.property) {
continue;
}
// make sure the type name matches
const objectType = services.getTypeAtLocation(node.object);
const objectSymbol = objectType.getSymbol();
if (objectSymbol?.getName() !== banned.type) {
continue;
}
const symbol = services.getSymbolAtLocation(node.property);
const decls = symbol?.getDeclarations();
const isFromTs = decls?.some(decl =>
decl.getSourceFile().fileName.includes('/node_modules/typescript/'),
);
if (isFromTs !== true) {
continue;
}
return context.report({
node,
messageId: banned.fixWith ? 'doNotUseWithFixer' : 'doNotUse',
data: banned,
suggest: [
{
messageId: 'suggestedFix',
data: banned,
fix(fixer): TSESLint.RuleFix | null {
return fixer.replaceText(node.property, banned.fixWith);
},
},
],
});
}
},
};
}
Generated by Syntax Scribe