How to use the eslint-module-utils/unambiguous.isModule function in eslint-module-utils

To help you get started, we’ve selected a few eslint-module-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benmosher / eslint-plugin-import / src / ExportMap.js View on Github external
ExportMap.parse = function (path, content, context) {
  var m = new ExportMap(path)

  try {
    var ast = parse(path, content, context)
  } catch (err) {
    log('parse error:', path, err)
    m.errors.push(err)
    return m // can't continue
  }

  if (!unambiguous.isModule(ast)) return null

  const docstyle = (context.settings && context.settings['import/docstyle']) || ['jsdoc']
  const docStyleParsers = {}
  docstyle.forEach(style => {
    docStyleParsers[style] = availableDocStyleParsers[style]
  })

  // attempt to collect module doc
  if (ast.comments) {
    ast.comments.some(c => {
      if (c.type !== 'Block') return false
      try {
        const doc = doctrine.parse(c.value, { unwrap: true })
        if (doc.tags.some(t => t.title === 'module')) {
          m.doc = doc
          return true
github benmosher / eslint-plugin-import / src / rules / unambiguous.js View on Github external
Program: function (ast) {
        if (!isModule(ast)) {
          context.report({
            node: ast,
            message: 'This module could be parsed as a valid script.',
          })
        }
      },
    }