3 * Copyright 2013 Palantir Technologies, Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 import { IOptions, RuleSeverity } from "./language/rule/rule";
18 export interface IConfigurationFile {
20 * @deprecated property is never set
22 * The severity that is applied to rules in this config file as well as rules
23 * in any inherited config files which have their severity set to "default".
26 defaultSeverity?: RuleSeverity;
28 * An array of config files whose rules are inherited by this config file.
32 * Rules that are used to lint to JavaScript files.
34 jsRules: Map<string, Partial<IOptions>>;
36 * A subset of the CLI options.
38 linterOptions?: Partial<{
43 * Directories containing custom rules. Resolved using node module semantics.
45 rulesDirectory: string[];
47 * Rules that are used to lint TypeScript files.
49 rules: Map<string, Partial<IOptions>>;
51 export interface IConfigurationLoadResult {
53 results?: IConfigurationFile;
55 export declare const JSON_CONFIG_FILENAME = "tslint.json";
56 /** @deprecated use `JSON_CONFIG_FILENAME` or `CONFIG_FILENAMES` instead. */
57 export declare const CONFIG_FILENAME = "tslint.json";
58 export declare const CONFIG_FILENAMES: string[];
59 export declare const DEFAULT_CONFIG: IConfigurationFile;
60 export declare const EMPTY_CONFIG: IConfigurationFile;
62 * Searches for a TSLint configuration and returns the data from the config.
63 * @param configFile A path to a config file, this can be null if the location of a config is not known
64 * @param inputFilePath A path containing the current file being linted. This is the starting location
65 * of the search for a configuration.
66 * @returns Load status for a TSLint configuration object
68 export declare function findConfiguration(configFile: string | null, inputFilePath: string): IConfigurationLoadResult;
69 export declare function findConfiguration(configFile: string, inputFilePath?: string): IConfigurationLoadResult;
71 * Searches for a TSLint configuration and returns the path to it.
72 * Could return undefined if not configuration is found.
73 * @param suppliedConfigFilePath A path to an known config file supplied by a user. Pass null here if
74 * the location of the config file is not known and you want to search for one.
75 * @param inputFilePath A path to the current file being linted. This is the starting location
76 * of the search for a configuration.
77 * @returns An absolute path to a tslint.json or tslint.yml or tslint.yaml file
78 * or undefined if neither can be found.
80 export declare function findConfigurationPath(suppliedConfigFilePath: string | null, inputFilePath: string): string | undefined;
81 export declare function findConfigurationPath(suppliedConfigFilePath: string, inputFilePath?: string): string | undefined;
83 * Used Node semantics to load a configuration file given configFilePath.
85 * '/path/to/config' will be treated as an absolute path
86 * './path/to/config' will be treated as a relative path
87 * 'path/to/config' will attempt to load a to/config file inside a node module named path
88 * @param configFilePath The configuration to load
89 * @param originalFilePath (deprecated) The entry point configuration file
90 * @returns a configuration object for TSLint loaded from the file at configFilePath
92 export declare function loadConfigurationFromPath(configFilePath?: string, _originalFilePath?: string): IConfigurationFile;
93 /** Reads the configuration file from disk and parses it as raw JSON, YAML or JS depending on the extension. */
94 export declare function readConfigurationFile(filepath: string): RawConfigFile;
95 export declare function extendConfigurationFile(targetConfig: IConfigurationFile, nextConfigSource: IConfigurationFile): IConfigurationFile;
97 * returns the absolute path (contrary to what the name implies)
99 * @deprecated use `path.resolve` instead
101 export declare function getRelativePath(directory?: string | null, relativeTo?: string): string | undefined;
102 export declare function useAsPath(directory: string): boolean;
104 * @param directories A path(s) to a directory of custom rules
105 * @param relativeTo A path that directories provided are relative to.
106 * For example, if the directories come from a tslint.json file, this path
107 * should be the path to the tslint.json file.
108 * @return An array of absolute paths to directories potentially containing rules
110 export declare function getRulesDirectories(directories?: string | string[], relativeTo?: string): string[];
111 export interface RawConfigFile {
112 extends?: string | string[];
113 linterOptions?: IConfigurationFile["linterOptions"];
114 rulesDirectory?: string | string[];
115 defaultSeverity?: string;
116 rules?: RawRulesConfig;
117 jsRules?: RawRulesConfig | boolean;
119 export interface RawRulesConfig {
120 [key: string]: RawRuleConfig;
122 export declare type RawRuleConfig = null | undefined | boolean | any[] | {
123 severity?: RuleSeverity | "warn" | "none" | "default";
127 * Parses a config file and normalizes legacy config settings.
128 * If `configFileDir` and `readConfig` are provided, this function will load all base configs and reduce them to the final configuration.
130 * @param configFile The raw object read from the JSON of a config file
131 * @param configFileDir The directory of the config file
132 * @param readConfig Will be used to load all base configurations while parsing. The function is called with the resolved path.
134 export declare function parseConfigFile(configFile: RawConfigFile, configFileDir?: string, readConfig?: (path: string) => RawConfigFile): IConfigurationFile;
136 * Fills in default values for `IOption` properties and outputs an array of `IOption`
138 export declare function convertRuleOptions(ruleConfiguration: Map<string, Partial<IOptions>>): IOptions[];
139 export declare function isFileExcluded(filepath: string, configFile?: IConfigurationFile): boolean;
140 export declare function stringifyConfiguration(configFile: IConfigurationFile): string;