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

ota-meshi / svelte-eslint-parser / 4581268530

01 Apr 2023 04:18AM CUT coverage: 90.693%. Remained the same
4581268530

push

github

GitHub
chore: release svelte-eslint-parser (#308)

880 of 1041 branches covered (84.53%)

Branch coverage included in aggregate %.

2053 of 2193 relevant lines covered (93.62%)

27060.16 hits per line

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

57.14
/src/parser/parser-object.ts
1
import type { ESLintExtendedProgram, ESLintProgram } from ".";
21,172✔
2
import type * as tsESLintParser from "@typescript-eslint/parser";
3
type TSESLintParser = typeof tsESLintParser;
4
/**
5
 * The type of basic ESLint custom parser.
6
 * e.g. espree
7
 */
8
export type BasicParserObject = {
9
  parse(code: string, options: any): ESLintProgram;
10
  parseForESLint: undefined;
11
};
12
/**
13
 * The type of ESLint custom parser enhanced for ESLint.
14
 * e.g. @babel/eslint-parser, @typescript-eslint/parser
15
 */
16
export type EnhancedParserObject = {
17
  parseForESLint(code: string, options: any): ESLintExtendedProgram;
18
  parse: undefined;
19
};
20

21
/**
22
 * The type of ESLint (custom) parsers.
23
 */
24
export type ParserObject = EnhancedParserObject | BasicParserObject;
25

26
/** Checks whether given object is ParserObject */
27
export function isParserObject(value: unknown): value is ParserObject {
28
  return isEnhancedParserObject(value) || isBasicParserObject(value);
15,753✔
29
}
30
/** Checks whether given object is EnhancedParserObject */
31
export function isEnhancedParserObject(
32
  value: unknown
33
): value is EnhancedParserObject {
34
  return Boolean(value && typeof (value as any).parseForESLint === "function");
21,169✔
35
}
36
/** Checks whether given object is BasicParserObject */
37
export function isBasicParserObject(
38
  value: unknown
39
): value is BasicParserObject {
40
  return Boolean(value && typeof (value as any).parse === "function");
15,745✔
41
}
42

43
/** Checks whether given object maybe "@typescript-eslint/parser" */
44
export function maybeTSESLintParserObject(
45
  value: unknown
46
): value is TSESLintParser {
47
  return (
2✔
48
    isEnhancedParserObject(value) &&
10✔
49
    isBasicParserObject(value) &&
50
    typeof (value as any).createProgram === "function" &&
51
    typeof (value as any).clearCaches === "function" &&
52
    typeof (value as any).version === "string"
53
  );
54
}
55

56
/** Checks whether given object is "@typescript-eslint/parser" */
57
export function isTSESLintParserObject(
58
  value: unknown
59
): value is TSESLintParser {
60
  if (!isEnhancedParserObject(value)) return false;
×
61
  try {
×
62
    const result = (value as unknown as TSESLintParser).parseForESLint("", {});
×
63
    const services = result.services;
×
64
    return Boolean(
×
65
      services &&
×
66
        services.esTreeNodeToTSNodeMap &&
67
        services.tsNodeToESTreeNodeMap &&
68
        services.program
69
    );
70
  } catch {
71
    return false;
×
72
  }
73
}
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