index.d.ts 6.5 KB

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