-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmapped-imports-rule-utils.ts
66 lines (53 loc) · 1.52 KB
/
mapped-imports-rule-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as ts from 'typescript';
import {
PreferMappedImportsRule,
RuleArgs,
parseCompilerOptions,
} from '@nativescript/tslint-rules';
const RULE_NAME = 'prefer-mapped-imports';
export function getMappedImportsRule(compilerOptions: ts.CompilerOptions):
PreferMappedImportsRule | undefined {
const tslintRuleArguments = getMappedImportsArguments(compilerOptions);
if (!tslintRuleArguments) {
return;
}
const rule = new PreferMappedImportsRule({
ruleArguments: [tslintRuleArguments],
ruleName: RULE_NAME,
ruleSeverity: 'error',
disabledIntervals: [],
});
return rule;
}
export interface RuleConfig {
name: string;
options: object;
}
export function getMappedImportsRuleConfig(compilerOptions: ts.CompilerOptions): RuleConfig | undefined {
const tslintRuleArguments = getMappedImportsArguments(compilerOptions);
if (!tslintRuleArguments) {
return;
}
const ruleOptions = [
true,
tslintRuleArguments,
];
return {
name: RULE_NAME,
options: ruleOptions,
};
}
function getMappedImportsArguments(compilerOptions: ts.CompilerOptions)
: RuleArgs | undefined {
const remapOptions = parseCompilerOptions(compilerOptions);
if (!remapOptions) {
return;
}
const { prefix, prefixMappedTo, baseUrl } = remapOptions;
const tslintRuleArguments = {
prefix,
'prefix-mapped-to': prefixMappedTo,
'base-url': baseUrl,
};
return tslintRuleArguments;
}