contextCompat.d.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Scope, SourceCode, Rule } from 'eslint';
  2. import * as ESTree from 'estree';
  3. type LegacyContext = {
  4. getFilename: () => string,
  5. getPhysicalFilename: () => string,
  6. getSourceCode: () => SourceCode,
  7. getScope: never,
  8. getAncestors: never,
  9. getDeclaredVariables: never,
  10. };
  11. type NewContext = {
  12. filename: string,
  13. sourceCode: SourceCode,
  14. getPhysicalFilename?: () => string,
  15. getScope: () => Scope.Scope,
  16. getAncestors: () => ESTree.Node[],
  17. getDeclaredVariables: (node: ESTree.Node) => Scope.Variable[],
  18. };
  19. export type Context = LegacyContext | NewContext | Rule.RuleContext;
  20. declare function getAncestors(context: Context, node: ESTree.Node): ESTree.Node[];
  21. declare function getDeclaredVariables(context: Context, node: ESTree.Node): Scope.Variable[];
  22. declare function getFilename(context: Context): string;
  23. declare function getPhysicalFilename(context: Context): string;
  24. declare function getScope(context: Context, node: ESTree.Node): Scope.Scope;
  25. declare function getSourceCode(context: Context): SourceCode;
  26. export {
  27. getAncestors,
  28. getDeclaredVariables,
  29. getFilename,
  30. getPhysicalFilename,
  31. getScope,
  32. getSourceCode,
  33. };