UNPKG

5.89 kBTypeScriptView Raw
1import { IOptions, RuleSeverity } from "./language/rule/rule";
2export 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}
34export interface IConfigurationLoadResult {
35 path?: string;
36 results?: IConfigurationFile;
37}
38export declare const JSON_CONFIG_FILENAME = "tslint.json";
39/** @deprecated use `JSON_CONFIG_FILENAME` or `CONFIG_FILENAMES` instead. */
40export declare const CONFIG_FILENAME = "tslint.json";
41export declare const CONFIG_FILENAMES: string[];
42export declare const DEFAULT_CONFIG: IConfigurationFile;
43export 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 */
51export declare function findConfiguration(configFile: string | null, inputFilePath: string): IConfigurationLoadResult;
52export 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 */
63export declare function findConfigurationPath(suppliedConfigFilePath: string | null, inputFilePath: string): string | undefined;
64export 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 */
75export 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. */
77export declare function readConfigurationFile(filepath: string): RawConfigFile;
78export 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 */
84export declare function getRelativePath(directory?: string | null, relativeTo?: string): string | undefined;
85export 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 */
93export declare function getRulesDirectories(directories?: string | string[], relativeTo?: string): string[];
94export interface RawConfigFile {
95 extends?: string | string[];
96 linterOptions?: IConfigurationFile["linterOptions"];
97 rulesDirectory?: string | string[];
98 defaultSeverity?: string;
99 rules?: RawRulesConfig;
100 jsRules?: RawRulesConfig;
101}
102export interface RawRulesConfig {
103 [key: string]: RawRuleConfig;
104}
105export 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 */
117export 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 */
121export declare function convertRuleOptions(ruleConfiguration: Map<string, Partial<IOptions>>): IOptions[];