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

ota-meshi / jsonc-eslint-parser / 17888386344

21 Sep 2025 03:28AM UTC coverage: 88.63%. Remained the same
17888386344

push

github

web-flow
chore: release jsonc-eslint-parser (#242)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

308 of 366 branches covered (84.15%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

604 of 663 relevant lines covered (91.1%)

63.98 hits per line

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

90.63
/src/parser/token-store.ts
1
import type { AST } from "eslint";
2
import type { SourceLocation } from "./ast";
3

4
export type MaybeNodeOrToken = {
5
  range?: [number, number];
6
  loc?: SourceLocation | null;
7
};
8

9
// type TokenType = AST.TokenType | "Template"
10

11
export class TokenStore {
1✔
12
  public readonly tokens: AST.Token[];
13

14
  public constructor(tokens: AST.Token[]) {
15
    this.tokens = tokens;
176✔
16
  }
17

18
  public add(token: AST.Token): void {
19
    this.tokens.push(token);
812✔
20
  }
21

22
  private findIndexByOffset(offset: number): number {
23
    return this.tokens.findIndex(
23✔
24
      (token) => token.range[0] <= offset && offset < token.range[1],
77✔
25
    );
26
  }
27

28
  public findTokenByOffset(offset: number): AST.Token | null {
29
    return this.tokens[this.findIndexByOffset(offset)];
14✔
30
  }
31

32
  /**
33
   * Get the first token representing the given node.
34
   *
35
   */
36
  public getFirstToken(nodeOrToken: MaybeNodeOrToken): AST.Token {
37
    return this.findTokenByOffset(nodeOrToken.range![0])!;
4✔
38
  }
39

40
  /**
41
   * Get the last token representing the given node.
42
   *
43
   */
44
  public getLastToken(nodeOrToken: MaybeNodeOrToken): AST.Token {
45
    return this.findTokenByOffset(nodeOrToken.range![1] - 1)!;
6✔
46
  }
47

48
  /**
49
   * Get the first token before the given node or token.
50
   */
51
  public getTokenBefore(
52
    nodeOrToken: MaybeNodeOrToken,
53
    filter?: (token: AST.Token) => boolean,
54
  ): AST.Token | null {
55
    const tokenIndex = this.findIndexByOffset(nodeOrToken.range![0]);
4✔
56

57
    for (let index = tokenIndex - 1; index >= 0; index--) {
4✔
58
      const token = this.tokens[index];
4✔
59
      if (!filter || filter(token)) {
4!
60
        return token;
4✔
61
      }
62
    }
63
    return null;
×
64
  }
65

66
  /**
67
   * Get the first token after the given node or token.
68
   */
69
  public getTokenAfter(
70
    nodeOrToken: MaybeNodeOrToken,
71
    filter?: (token: AST.Token) => boolean,
72
  ): AST.Token | null {
73
    const tokenIndex = this.findIndexByOffset(nodeOrToken.range![0]);
5✔
74

75
    for (let index = tokenIndex + 1; index < this.tokens.length; index++) {
5✔
76
      const token = this.tokens[index];
5✔
77
      if (!filter || filter(token)) {
5✔
78
        return token;
5✔
79
      }
80
    }
81
    return null;
×
82
  }
83
}
84

85
/**
86
 * Checks if given token is comma
87
 */
88
export function isComma(
1✔
89
  token: AST.Token,
90
): token is AST.Token & { type: "Punctuator"; value: "," } {
91
  return token.type === "Punctuator" && token.value === ",";
7✔
92
}
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