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

benmosher / eslint-plugin-import / #28399472

pending completion
#28399472

push

GitHub
<a href="https://github.com/benmosher/eslint-plugin-import/commit/<a class=hub.com/benmosher/eslint-plugin-import/commit/79ad37dfbf90869a29029b2bc556bd6108018c99">79ad37dfb<a href="https://github.com/benmosher/eslint-plugin-import/commit/79ad37dfbf90869a29029b2bc556bd6108018c99">">Merge </a><a class="double-link" href="https://github.com/benmosher/eslint-plugin-import/commit/<a class="double-link" href="https://github.com/benmosher/eslint-plugin-import/commit/44e85782da066487a4a5f5a62ae9b8d0c1d55aff">44e85782d</a>">44e85782d</a><a href="https://github.com/benmosher/eslint-plugin-import/commit/79ad37dfbf90869a29029b2bc556bd6108018c99"> into 4a9be6384">4a9be6384</a>

1363 of 1848 branches covered (73.76%)

1677 of 2595 relevant lines covered (64.62%)

38.84 hits per line

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

0.0
/utils/parse.js
1
'use strict';
2
exports.__esModule = true;
×
3

4
const moduleRequire = require('./module-require').default;
×
5
const extname = require('path').extname;
×
6

7
const log = require('debug')('eslint-plugin-import:parse');
×
8

9
exports.default = function parse(path, content, context) {
×
10

11
  if (context == null) throw new Error('need context to parse properly');
×
12

13
  let parserOptions = context.parserOptions;
×
14
  const parserPath = getParserPath(path, context);
×
15

16
  if (!parserPath) throw new Error('parserPath is required!');
×
17

18
  // hack: espree blows up with frozen options
19
  parserOptions = Object.assign({}, parserOptions);
×
20
  parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures);
×
21

22
  // always include comments and tokens (for doc parsing)
23
  parserOptions.comment = true;
×
24
  parserOptions.attachComment = true;  // keeping this for backward-compat with  older parsers
×
25
  parserOptions.tokens = true;
×
26

27
  // attach node locations
28
  parserOptions.loc = true;
×
29
  parserOptions.range = true;
×
30

31
  // provide the `filePath` like eslint itself does, in `parserOptions`
32
  // https://github.com/eslint/eslint/blob/3ec436ee/lib/linter.js#L637
33
  parserOptions.filePath = path;
×
34

35
  // @typescript-eslint/parser will parse the entire project with typechecking if you provide
36
  // "project" or "projects" in parserOptions. Removing these options means the parser will
37
  // only parse one file in isolate mode, which is much, much faster.
38
  // https://github.com/import-js/eslint-plugin-import/issues/1408#issuecomment-509298962
39
  delete parserOptions.project;
×
40
  delete parserOptions.projects;
×
41

42
  // require the parser relative to the main module (i.e., ESLint)
43
  const parser = moduleRequire(parserPath);
×
44

45
  if (typeof parser.parseForESLint === 'function') {
×
46
    let ast;
47
    try {
×
48
      ast = parser.parseForESLint(content, parserOptions).ast;
×
49
    } catch (e) {
50
      console.warn();
×
51
      console.warn('Error while parsing ' + parserOptions.filePath);
×
52
      console.warn('Line ' + e.lineNumber + ', column ' + e.column + ': ' + e.message);
×
53
    }
54
    if (!ast || typeof ast !== 'object') {
×
55
      console.warn('`parseForESLint` from parser `' + parserPath + '` is invalid and will just be ignored');
×
56
    } else {
57
      return ast;
×
58
    }
59
  }
60

61
  return parser.parse(content, parserOptions);
×
62
};
63

64
function getParserPath(path, context) {
65
  const parsers = context.settings['import/parsers'];
×
66
  if (parsers != null) {
×
67
    const extension = extname(path);
×
68
    for (const parserPath in parsers) {
×
69
      if (parsers[parserPath].indexOf(extension) > -1) {
×
70
        // use this alternate parser
71
        log('using alt parser:', parserPath);
×
72
        return parserPath;
×
73
      }
74
    }
75
  }
76
  // default to use ESLint parser
77
  return context.parserPath;
×
78
}
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

© 2026 Coveralls, Inc