configuration.d.ts 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { IOptions, RuleSeverity } from "./language/rule/rule";
  2. export interface IConfigurationFile {
  3. /**
  4. * @deprecated property is never set
  5. *
  6. * The severity that is applied to rules in this config file as well as rules
  7. * in any inherited config files which have their severity set to "default".
  8. * Not inherited.
  9. */
  10. defaultSeverity?: RuleSeverity;
  11. /**
  12. * An array of config files whose rules are inherited by this config file.
  13. */
  14. extends: string[];
  15. /**
  16. * Rules that are used to lint to JavaScript files.
  17. */
  18. jsRules: Map<string, Partial<IOptions>>;
  19. /**
  20. * A subset of the CLI options.
  21. */
  22. linterOptions?: Partial<{
  23. exclude: string[];
  24. }>;
  25. /**
  26. * Directories containing custom rules. Resolved using node module semantics.
  27. */
  28. rulesDirectory: string[];
  29. /**
  30. * Rules that are used to lint TypeScript files.
  31. */
  32. rules: Map<string, Partial<IOptions>>;
  33. }
  34. export interface IConfigurationLoadResult {
  35. path?: string;
  36. results?: IConfigurationFile;
  37. }
  38. export declare const JSON_CONFIG_FILENAME = "tslint.json";
  39. /** @deprecated use `JSON_CONFIG_FILENAME` or `CONFIG_FILENAMES` instead. */
  40. export declare const CONFIG_FILENAME = "tslint.json";
  41. export declare const CONFIG_FILENAMES: string[];
  42. export declare const DEFAULT_CONFIG: IConfigurationFile;
  43. export declare const EMPTY_CONFIG: IConfigurationFile;
  44. /**
  45. * Searches for a TSLint configuration and returns the data from the config.
  46. * @param configFile A path to a config file, this can be null if the location of a config is not known
  47. * @param inputFilePath A path containing the current file being linted. This is the starting location
  48. * of the search for a configuration.
  49. * @returns Load status for a TSLint configuration object
  50. */
  51. export declare function findConfiguration(configFile: string | null, inputFilePath: string): IConfigurationLoadResult;
  52. export declare function findConfiguration(configFile: string, inputFilePath?: string): IConfigurationLoadResult;
  53. /**
  54. * Searches for a TSLint configuration and returns the path to it.
  55. * Could return undefined if not configuration is found.
  56. * @param suppliedConfigFilePath A path to an known config file supplied by a user. Pass null here if
  57. * the location of the config file is not known and you want to search for one.
  58. * @param inputFilePath A path to the current file being linted. This is the starting location
  59. * of the search for a configuration.
  60. * @returns An absolute path to a tslint.json or tslint.yml or tslint.yaml file
  61. * or undefined if neither can be found.
  62. */
  63. export declare function findConfigurationPath(suppliedConfigFilePath: string | null, inputFilePath: string): string | undefined;
  64. export declare function findConfigurationPath(suppliedConfigFilePath: string, inputFilePath?: string): string | undefined;
  65. /**
  66. * Used Node semantics to load a configuration file given configFilePath.
  67. * For example:
  68. * '/path/to/config' will be treated as an absolute path
  69. * './path/to/config' will be treated as a relative path
  70. * 'path/to/config' will attempt to load a to/config file inside a node module named path
  71. * @param configFilePath The configuration to load
  72. * @param originalFilePath (deprecated) The entry point configuration file
  73. * @returns a configuration object for TSLint loaded from the file at configFilePath
  74. */
  75. export declare function loadConfigurationFromPath(configFilePath?: string, _originalFilePath?: string): IConfigurationFile;
  76. /** Reads the configuration file from disk and parses it as raw JSON, YAML or JS depending on the extension. */
  77. export declare function readConfigurationFile(filepath: string): RawConfigFile;
  78. export declare function extendConfigurationFile(targetConfig: IConfigurationFile, nextConfigSource: IConfigurationFile): IConfigurationFile;
  79. /**
  80. * returns the absolute path (contrary to what the name implies)
  81. *
  82. * @deprecated use `path.resolve` instead
  83. */
  84. export declare function getRelativePath(directory?: string | null, relativeTo?: string): string | undefined;
  85. export declare function useAsPath(directory: string): boolean;
  86. /**
  87. * @param directories A path(s) to a directory of custom rules
  88. * @param relativeTo A path that directories provided are relative to.
  89. * For example, if the directories come from a tslint.json file, this path
  90. * should be the path to the tslint.json file.
  91. * @return An array of absolute paths to directories potentially containing rules
  92. */
  93. export declare function getRulesDirectories(directories?: string | string[], relativeTo?: string): string[];
  94. export interface RawConfigFile {
  95. extends?: string | string[];
  96. linterOptions?: IConfigurationFile["linterOptions"];
  97. rulesDirectory?: string | string[];
  98. defaultSeverity?: string;
  99. rules?: RawRulesConfig;
  100. jsRules?: RawRulesConfig;
  101. }
  102. export interface RawRulesConfig {
  103. [key: string]: RawRuleConfig;
  104. }
  105. export declare type RawRuleConfig = null | undefined | boolean | any[] | {
  106. severity?: RuleSeverity | "warn" | "none" | "default";
  107. options?: any;
  108. };
  109. /**
  110. * Parses a config file and normalizes legacy config settings.
  111. * If `configFileDir` and `readConfig` are provided, this function will load all base configs and reduce them to the final configuration.
  112. *
  113. * @param configFile The raw object read from the JSON of a config file
  114. * @param configFileDir The directory of the config file
  115. * @param readConfig Will be used to load all base configurations while parsing. The function is called with the resolved path.
  116. */
  117. export declare function parseConfigFile(configFile: RawConfigFile, configFileDir?: string, readConfig?: (path: string) => RawConfigFile): IConfigurationFile;
  118. /**
  119. * Fills in default values for `IOption` properties and outputs an array of `IOption`
  120. */
  121. export declare function convertRuleOptions(ruleConfiguration: Map<string, Partial<IOptions>>): IOptions[];