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

nightlycommit / twing / 307

02 Jun 2025 09:53AM CUT coverage: 100.0%. Remained the same
307

push

gitlab-ci

Eric MORAND
Replace useless https protocol with http.

2541 of 2541 branches covered (100.0%)

Branch coverage included in aggregate %.

5851 of 5851 relevant lines covered (100.0%)

2499.09 hits per line

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

100.0
/src/main/lib/error/parsing.ts
1
import {createBaseError, TwingErrorLocation, TwingBaseError} from "./base";
2
import type {TwingSource} from "../source";
3

4
const Levenshtein = require('levenshtein');
1✔
5

6
export const parsingErrorName = 'TwingParsingError';
1✔
7

8
export interface TwingParsingError extends TwingBaseError<typeof parsingErrorName> {
9
    /**
10
     * Tweaks the error message to include suggestions.
11
     *
12
     * @param {string} name The original name of the item that does not exist
13
     * @param {Array<string>} items An array of possible items
14
     */
15
    addSuggestions(name: string, items: Array<string>): void;
16
}
17

18
export const createParsingError = (
1✔
19
    message: string, location: TwingErrorLocation, source: TwingSource, previous?: Error
20
): TwingParsingError => {
21
    const baseError = createBaseError(parsingErrorName, message, location, source, previous);
124✔
22

23
    Error.captureStackTrace(baseError, createParsingError);
124✔
24

25
    return Object.create(baseError, {
124✔
26
        addSuggestions: {
27
            value: (name: string, items: Array<string>) => {
28
                const alternatives: string[] = [];
28✔
29

30
                let levenshtein;
28✔
31

32
                for (const item of items) {
28✔
33
                    levenshtein = new Levenshtein(name, item);
577✔
34

35
                    if (levenshtein.distance <= (name.length / 3) || item.indexOf(name) > -1) {
577✔
36
                        alternatives.push(item);
5✔
37
                    }
38
                }
39

40
                if (alternatives.length < 1) {
28✔
41
                    return;
23✔
42
                }
43

44
                alternatives.sort();
5✔
45

46
                baseError.appendMessage(` Did you mean "${alternatives.join(', ')}"?`);
5✔
47
            }
48
        }
49
    });
50
};
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