• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / bslint / #1041

03 Oct 2024 07:42PM UTC coverage: 91.278% (-0.5%) from 91.746%
#1041

Pull #96

TwitchBronBron
1.0.0-alpha.39
Pull Request #96: v1

927 of 1061 branches covered (87.37%)

Branch coverage included in aggregate %.

231 of 240 new or added lines in 12 files covered. (96.25%)

11 existing lines in 3 files now uncovered.

1009 of 1060 relevant lines covered (95.19%)

68.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.96
/src/index.ts
1
import { BsConfig, Program, DiagnosticSeverity, CompilerPlugin, AfterProgramCreateEvent, AfterProgramValidateEvent } from 'brighterscript';
2
import Linter from './Linter';
1✔
3
import CheckUsage from './plugins/checkUsage';
1✔
4
import CodeStyle from './plugins/codeStyle';
1✔
5
import TrackCodeFlow from './plugins/trackCodeFlow';
1✔
6
import { PluginWrapperContext, createContext } from './util';
1✔
7

8
export type RuleSeverity = 'error' | 'warn' | 'info' | 'off';
9
export type RuleInlineIf = 'never' | 'no-then' | 'then' | 'off';
10
export type RuleBlockIf = 'no-then' | 'then' | 'off';
11
export type RuleCondition = 'no-group' | 'group' | 'off';
12
export type RuleFunction = 'no-function' | 'no-sub' | 'auto' | 'off';
13
export type RuleAAComma = 'always' | 'no-dangling' | 'never' | 'off';
14
export type RuleTypeAnnotations = 'all' | 'return' | 'args' | 'off';
15
export type RuleEolLast = 'always' | 'never' | 'off';
16
export type RuleColorFormat = 'hash-hex' | 'quoted-numeric-hex' | 'never' | 'off';
17
export type RuleColorCase = 'upper' | 'lower' | 'off';
18
export type RuleColorAlpha = 'always' | 'allowed' | 'never' | 'off';
19
export type RuleColorAlphaDefaults = 'allowed' | 'only-hidden' | 'never' | 'off';
20
export type RuleColorCertCompliant = 'always' | 'off'; // Roku cert requirement for broadcast safe colors. 6.4
21

22
export type BsLintConfig = Pick<BsConfig, 'project' | 'rootDir' | 'files' | 'cwd' | 'watch'> & {
23
    lintConfig?: string;
24
    rules?: {
25
        'assign-all-paths'?: RuleSeverity;
26
        'unsafe-path-loop'?: RuleSeverity;
27
        'unsafe-iterators'?: RuleSeverity;
28
        'unreachable-code'?: RuleSeverity;
29
        'case-sensitivity'?: RuleSeverity;
30
        'unused-variable'?: RuleSeverity;
31
        'consistent-return'?: RuleSeverity;
32
        'no-stop'?: RuleSeverity;
33
        // 'only-function'?: RuleSeverity,
34
        // 'only-sub'?: RuleSeverity,
35
        'inline-if-style'?: RuleInlineIf;
36
        'block-if-style'?: RuleBlockIf;
37
        'condition-style'?: RuleCondition;
38
        'named-function-style'?: RuleFunction;
39
        'anon-function-style'?: RuleFunction;
40
        'aa-comma-style'?: RuleAAComma;
41
        'type-annotations'?: RuleTypeAnnotations;
42
        'no-print'?: RuleSeverity;
43
        'no-todo'?: RuleSeverity;
44
        // Will be transformed to RegExp type when program context is created.
45
        'todo-pattern'?: string;
46
        'eol-last'?: RuleEolLast;
47
        'color-format'?: RuleColorFormat;
48
        'color-case'?: RuleColorCase;
49
        'color-alpha'?: RuleColorAlpha;
50
        'color-alpha-defaults'?: RuleColorAlphaDefaults;
51
        'color-cert'?: RuleColorCertCompliant;
52
        'no-assocarray-component-field-type'?: RuleSeverity;
53
        'no-array-component-field-type'?: RuleSeverity;
54
        'name-shadowing'?: RuleSeverity;
55
    };
56
    globals?: string[];
57
    ignores?: string[];
58
    fix?: boolean;
59
    checkUsage?: boolean;
60
};
61

62
export type BsLintSeverity = DiagnosticSeverity;
63

64
export interface BsLintRules {
65
    assignAllPath: BsLintSeverity;
66
    unsafePathLoop: BsLintSeverity;
67
    unsafeIterators: BsLintSeverity;
68
    unreachableCode: BsLintSeverity;
69
    caseSensitivity: BsLintSeverity;
70
    unusedVariable: BsLintSeverity;
71
    consistentReturn: BsLintSeverity;
72
    inlineIfStyle: RuleInlineIf;
73
    blockIfStyle: RuleBlockIf;
74
    conditionStyle: RuleCondition;
75
    namedFunctionStyle: RuleFunction;
76
    anonFunctionStyle: RuleFunction;
77
    aaCommaStyle: RuleAAComma;
78
    typeAnnotations: RuleTypeAnnotations;
79
    noPrint: BsLintSeverity;
80
    noTodo: BsLintSeverity;
81
    noStop: BsLintSeverity;
82
    eolLast: RuleEolLast;
83
    colorFormat: RuleColorFormat;
84
    colorCase: RuleColorCase;
85
    colorAlpha: RuleColorAlpha;
86
    colorAlphaDefaults: RuleColorAlphaDefaults;
87
    colorCertCompliant: RuleColorCertCompliant;
88
    noAssocarrayComponentFieldType: BsLintSeverity;
89
    noArrayComponentFieldType: BsLintSeverity;
90
    nameShadowing: BsLintSeverity;
91
}
92

93
export { Linter };
1✔
94

95
export default function factory(): CompilerPlugin {
1✔
96
    const contextMap = new WeakMap<Program, PluginWrapperContext>();
100✔
97
    return {
100✔
98
        name: 'bslint',
99
        afterProgramCreate: (event: AfterProgramCreateEvent) => {
100
            const { program } = event;
100✔
101
            const context = createContext(program);
100✔
102
            contextMap.set(program, context);
100✔
103

104
            const trackCodeFlow = new TrackCodeFlow(context);
100✔
105
            program.plugins.add(trackCodeFlow);
100✔
106

107
            const codeStyle = new CodeStyle(context);
100✔
108
            program.plugins.add(codeStyle);
100✔
109

110
            if (context.checkUsage) {
100!
UNCOV
111
                const checkUsage = new CheckUsage(context);
×
UNCOV
112
                program.plugins.add(checkUsage);
×
113
            }
114
        },
115
        afterProgramValidate: async (event: AfterProgramValidateEvent) => {
116
            const context = contextMap.get(event.program);
18✔
117
            await context.applyFixes();
18✔
118
        }
119
    };
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc