How to use the babel-eslint.parse function in babel-eslint

To help you get started, we’ve selected a few babel-eslint 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 vuejs / eslint-plugin-vue / tests / lib / utils / index.js View on Github external
const parse = function (code) {
    return babelEslint.parse(code).body[0].expression
  }
github vuejs / eslint-plugin-vue / tests / lib / utils / index.js View on Github external
const parse = function (code) {
    return babelEslint.parse(code).body[0].declarations[0].init
  }
github elastic / kibana / packages / kbn-eslint-plugin-license-header / rules / require_license_header.js View on Github external
const license = init(context, program, function () {
          const options = context.options[0] || {};
          const license = options.license;

          assert(!!license, '"license" option is required');

          const parsed = babelEslint.parse(license);
          assert(!parsed.body.length, '"license" option must only include a single comment');
          assert(parsed.comments.length === 1, '"license" option must only include a single comment');

          return {
            source: license,
            nodeValue: normalizeWhitespace(parsed.comments[0].value)
          };
        });
github elastic / apm-agent-rum-js / scripts / eslint-rules / require-license-header.js View on Github external
Program() {
        const options = context.options[0] || {}
        const licenseToBeAdded = options.license
        assert(!!licenseToBeAdded, '"license" option is required')

        const parsed = parse(licenseToBeAdded)

        assert(
          !parsed.body.length,
          '"license" option must only include a single comment'
        )
        assert(
          parsed.comments.length === 1,
          '"license" option must only include a single comment'
        )

        const license = {
          source: licenseToBeAdded,
          nodeValue: normalizeWhitespace(parsed.comments[0].value)
        }
        const sourceCode = context.getSourceCode()
        const comment = sourceCode
github elastic / kibana / packages / kbn-eslint-plugin-license-header / rules / disallow_license_headers.js View on Github external
return licenses.map((license, i) => {
            const parsed = babelEslint.parse(license);

            assert(!parsed.body.length, `"licenses[${i}]" option must only include a single comment`);
            assert(parsed.comments.length === 1, `"licenses[${i}]" option must only include a single comment`);

            return normalizeWhitespace(parsed.comments[0].value);
          });
        });