UNPKG

6.65 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2013 Palantir Technologies, Inc.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17import { IOptions, RuleSeverity } from "./language/rule/rule";
18export interface IConfigurationFile {
19 /**
20 * @deprecated property is never set
21 *
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".
24 * Not inherited.
25 */
26 defaultSeverity?: RuleSeverity;
27 /**
28 * An array of config files whose rules are inherited by this config file.
29 */
30 extends: string[];
31 /**
32 * Rules that are used to lint to JavaScript files.
33 */
34 jsRules: Map<string, Partial<IOptions>>;
35 /**
36 * A subset of the CLI options.
37 */
38 linterOptions?: Partial<{
39 exclude: string[];
40 format: string;
41 }>;
42 /**
43 * Directories containing custom rules. Resolved using node module semantics.
44 */
45 rulesDirectory: string[];
46 /**
47 * Rules that are used to lint TypeScript files.
48 */
49 rules: Map<string, Partial<IOptions>>;
50}
51export interface IConfigurationLoadResult {
52 path?: string;
53 results?: IConfigurationFile;
54}
55export declare const JSON_CONFIG_FILENAME = "tslint.json";
56/** @deprecated use `JSON_CONFIG_FILENAME` or `CONFIG_FILENAMES` instead. */
57export declare const CONFIG_FILENAME = "tslint.json";
58export declare const CONFIG_FILENAMES: string[];
59export declare const DEFAULT_CONFIG: IConfigurationFile;
60export declare const EMPTY_CONFIG: IConfigurationFile;
61/**
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
67 */
68export declare function findConfiguration(configFile: string | null, inputFilePath: string): IConfigurationLoadResult;
69export declare function findConfiguration(configFile: string, inputFilePath?: string): IConfigurationLoadResult;
70/**
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.
79 */
80export declare function findConfigurationPath(suppliedConfigFilePath: string | null, inputFilePath: string): string | undefined;
81export declare function findConfigurationPath(suppliedConfigFilePath: string, inputFilePath?: string): string | undefined;
82/**
83 * Used Node semantics to load a configuration file given configFilePath.
84 * For example:
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
91 */
92export 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. */
94export declare function readConfigurationFile(filepath: string): RawConfigFile;
95export declare function extendConfigurationFile(targetConfig: IConfigurationFile, nextConfigSource: IConfigurationFile): IConfigurationFile;
96/**
97 * returns the absolute path (contrary to what the name implies)
98 *
99 * @deprecated use `path.resolve` instead
100 */
101export declare function getRelativePath(directory?: string | null, relativeTo?: string): string | undefined;
102export declare function useAsPath(directory: string): boolean;
103/**
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
109 */
110export declare function getRulesDirectories(directories?: string | string[], relativeTo?: string): string[];
111export interface RawConfigFile {
112 extends?: string | string[];
113 linterOptions?: IConfigurationFile["linterOptions"];
114 rulesDirectory?: string | string[];
115 defaultSeverity?: string;
116 rules?: RawRulesConfig;
117 jsRules?: RawRulesConfig | boolean;
118}
119export interface RawRulesConfig {
120 [key: string]: RawRuleConfig;
121}
122export declare type RawRuleConfig = null | undefined | boolean | any[] | {
123 severity?: RuleSeverity | "warn" | "none" | "default";
124 options?: any;
125};
126/**
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.
129 *
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.
133 */
134export declare function parseConfigFile(configFile: RawConfigFile, configFileDir?: string, readConfig?: (path: string) => RawConfigFile): IConfigurationFile;
135/**
136 * Fills in default values for `IOption` properties and outputs an array of `IOption`
137 */
138export declare function convertRuleOptions(ruleConfiguration: Map<string, Partial<IOptions>>): IOptions[];
139export declare function isFileExcluded(filepath: string, configFile?: IConfigurationFile): boolean;