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

ota-meshi / svelte-eslint-parser / 4581268530

01 Apr 2023 04:18AM UTC 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

80.0
/src/parser/espree.ts
1
import Module from "module";
4,526✔
2
import path from "path";
1✔
3
import type { BasicParserObject } from "./parser-object";
4

5
const createRequire: (filename: string) => (modName: string) => any =
6
  // Added in v12.2.0
7
  Module.createRequire ||
1!
8
  // Added in v10.12.0, but deprecated in v12.2.0.
9
  // @ts-expect-error -- old type
10
  Module.createRequireFromPath ||
11
  // Polyfill - This is not executed on the tests on node@>=10.
12
  /* istanbul ignore next */
13
  ((modName) => {
14
    const mod = new Module(modName);
15

16
    mod.filename = modName;
17
    mod.paths = (Module as any)._nodeModulePaths(path.dirname(modName));
18
    (mod as any)._compile("module.exports = require;", modName);
19
    return mod.exports;
20
  });
21

22
let espreeCache: BasicParserObject | null = null;
1✔
23

24
/** Checks if given path is linter path */
25
function isLinterPath(p: string): boolean {
26
  return (
359✔
27
    // ESLint 6 and above
28
    p.includes(`eslint${path.sep}lib${path.sep}linter${path.sep}linter.js`) ||
717✔
29
    // ESLint 5
30
    p.includes(`eslint${path.sep}lib${path.sep}linter.js`)
31
  );
32
}
33

34
/**
35
 * Load `espree` from the loaded ESLint.
36
 * If the loaded ESLint was not found, just returns `require("espree")`.
37
 */
38
export function getEspree(): BasicParserObject {
39
  if (!espreeCache) {
4,523✔
40
    // Lookup the loaded eslint
41
    const linterPath = Object.keys(require.cache || {}).find(isLinterPath);
1!
42
    if (linterPath) {
1!
43
      try {
1✔
44
        espreeCache = createRequire(linterPath)("espree");
1✔
45
      } catch {
46
        // ignore
47
      }
48
    }
49
    if (!espreeCache) {
1!
50
      // eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
51
      espreeCache = require("espree");
×
52
    }
53
  }
54

55
  return espreeCache!;
4,523✔
56
}
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