Skip to content

⬅️ 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

export default createRule({ ... })
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:

  • context any

Returns: { 'MemberExpression[computed = false]'(node: TSESTree.MemberExpressionNonComputedName): void; }

Calls:

  • ESLintUtils.getParserServices
  • services.getTypeAtLocation
  • objectType.getSymbol
  • objectSymbol?.getName
  • services.getSymbolAtLocation
  • symbol?.getDeclarations
  • decls?.some
  • decl.getSourceFile().fileName.includes
  • context.report
  • fixer.replaceText

Internal Comments:

// make sure the type name matches (x2)

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