index.d.cts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. export { ObjectSchema } from "@eslint/object-schema";
  2. export type PropertyDefinition = import("@eslint/object-schema").PropertyDefinition;
  3. export type ObjectDefinition = import("@eslint/object-schema").ObjectDefinition;
  4. export type ConfigObject = import("./types.ts").ConfigObject;
  5. export type IMinimatchStatic = import("minimatch").IMinimatchStatic;
  6. export type IMinimatch = import("minimatch").IMinimatch;
  7. export type ObjectSchemaInstance = import("@eslint/object-schema").ObjectSchema;
  8. /**
  9. * Represents an array of config objects and provides method for working with
  10. * those config objects.
  11. */
  12. export class ConfigArray extends Array<any> {
  13. /**
  14. * Creates a new instance of ConfigArray.
  15. * @param {Iterable|Function|Object} configs An iterable yielding config
  16. * objects, or a config function, or a config object.
  17. * @param {Object} options The options for the ConfigArray.
  18. * @param {string} [options.basePath=""] The path of the config file
  19. * @param {boolean} [options.normalized=false] Flag indicating if the
  20. * configs have already been normalized.
  21. * @param {Object} [options.schema] The additional schema
  22. * definitions to use for the ConfigArray schema.
  23. * @param {Array<string>} [options.extraConfigTypes] List of config types supported.
  24. */
  25. constructor(configs: Iterable<any> | Function | any, { basePath, normalized, schema: customSchema, extraConfigTypes, }?: {
  26. basePath?: string;
  27. normalized?: boolean;
  28. schema?: any;
  29. extraConfigTypes?: Array<string>;
  30. });
  31. /**
  32. * The path of the config file that this array was loaded from.
  33. * This is used to calculate filename matches.
  34. * @property basePath
  35. * @type {string}
  36. */
  37. basePath: string;
  38. /**
  39. * The supported config types.
  40. * @type {Array<string>}
  41. */
  42. extraConfigTypes: Array<string>;
  43. /**
  44. * Returns the `files` globs from every config object in the array.
  45. * This can be used to determine which files will be matched by a
  46. * config array or to use as a glob pattern when no patterns are provided
  47. * for a command line interface.
  48. * @returns {Array<string|Function>} An array of matchers.
  49. */
  50. get files(): (string | Function)[];
  51. /**
  52. * Returns ignore matchers that should always be ignored regardless of
  53. * the matching `files` fields in any configs. This is necessary to mimic
  54. * the behavior of things like .gitignore and .eslintignore, allowing a
  55. * globbing operation to be faster.
  56. * @returns {string[]} An array of string patterns and functions to be ignored.
  57. */
  58. get ignores(): string[];
  59. /**
  60. * Indicates if the config array has been normalized.
  61. * @returns {boolean} True if the config array is normalized, false if not.
  62. */
  63. isNormalized(): boolean;
  64. /**
  65. * Normalizes a config array by flattening embedded arrays and executing
  66. * config functions.
  67. * @param {Object} [context] The context object for config functions.
  68. * @returns {Promise<ConfigArray>} The current ConfigArray instance.
  69. */
  70. normalize(context?: any): Promise<ConfigArray>;
  71. /**
  72. * Normalizes a config array by flattening embedded arrays and executing
  73. * config functions.
  74. * @param {Object} [context] The context object for config functions.
  75. * @returns {ConfigArray} The current ConfigArray instance.
  76. */
  77. normalizeSync(context?: any): ConfigArray;
  78. /**
  79. * Returns the config object for a given file path and a status that can be used to determine why a file has no config.
  80. * @param {string} filePath The complete path of a file to get a config for.
  81. * @returns {{ config?: Object, status: "ignored"|"external"|"unconfigured"|"matched" }}
  82. * An object with an optional property `config` and property `status`.
  83. * `config` is the config object for the specified file as returned by {@linkcode ConfigArray.getConfig},
  84. * `status` a is one of the constants returned by {@linkcode ConfigArray.getConfigStatus}.
  85. */
  86. getConfigWithStatus(filePath: string): {
  87. config?: any;
  88. status: "ignored" | "external" | "unconfigured" | "matched";
  89. };
  90. /**
  91. * Returns the config object for a given file path.
  92. * @param {string} filePath The complete path of a file to get a config for.
  93. * @returns {Object|undefined} The config object for this file or `undefined`.
  94. */
  95. getConfig(filePath: string): any | undefined;
  96. /**
  97. * Determines whether a file has a config or why it doesn't.
  98. * @param {string} filePath The complete path of the file to check.
  99. * @returns {"ignored"|"external"|"unconfigured"|"matched"} One of the following values:
  100. * * `"ignored"`: the file is ignored
  101. * * `"external"`: the file is outside the base path
  102. * * `"unconfigured"`: the file is not matched by any config
  103. * * `"matched"`: the file has a matching config
  104. */
  105. getConfigStatus(filePath: string): "ignored" | "external" | "unconfigured" | "matched";
  106. /**
  107. * Determines if the given filepath is ignored based on the configs.
  108. * @param {string} filePath The complete path of a file to check.
  109. * @returns {boolean} True if the path is ignored, false if not.
  110. * @deprecated Use `isFileIgnored` instead.
  111. */
  112. isIgnored(filePath: string): boolean;
  113. /**
  114. * Determines if the given filepath is ignored based on the configs.
  115. * @param {string} filePath The complete path of a file to check.
  116. * @returns {boolean} True if the path is ignored, false if not.
  117. */
  118. isFileIgnored(filePath: string): boolean;
  119. /**
  120. * Determines if the given directory is ignored based on the configs.
  121. * This checks only default `ignores` that don't have `files` in the
  122. * same config. A pattern such as `/foo` be considered to ignore the directory
  123. * while a pattern such as `/foo/**` is not considered to ignore the
  124. * directory because it is matching files.
  125. * @param {string} directoryPath The complete path of a directory to check.
  126. * @returns {boolean} True if the directory is ignored, false if not. Will
  127. * return true for any directory that is not inside of `basePath`.
  128. * @throws {Error} When the `ConfigArray` is not normalized.
  129. */
  130. isDirectoryIgnored(directoryPath: string): boolean;
  131. }
  132. export namespace ConfigArraySymbol {
  133. let isNormalized: symbol;
  134. let configCache: symbol;
  135. let schema: symbol;
  136. let finalizeConfig: symbol;
  137. let preprocessConfig: symbol;
  138. }