How to use babel-eslint - 10 common examples

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 mysticatea / vue-eslint-demo / webpack.config.js View on Github external
},
    eslint: {
        repo: "eslint/eslint",
        version: require("eslint/package.json").version,
    },
    "eslint-plugin-vue": {
        repo: "vuejs/eslint-plugin-vue",
        version: require("eslint-plugin-vue/package.json").version,
    },
    "vue-eslint-parser": {
        repo: "mysticatea/vue-eslint-parser",
        version: require("vue-eslint-parser/package.json").version,
    },
    "babel-eslint": {
        repo: "babel/babel-eslint",
        version: require("babel-eslint/package.json").version,
    },
    "typescript-eslint-parser": {
        repo: "eslint/typescript-eslint-parser",
        version: require("typescript-eslint-parser/package.json").version,
    },
    typescript: {
        repo: "Microsoft/typescript",
        version: require("typescript/package.json").version,
    },
})}`

// Shim for vue-eslint-parser.
const IMPORT_PARSER = `(
    parserOptions.parser === "babel-eslint" ? require("babel-eslint") :
    parserOptions.parser === "typescript-eslint-parser" ? require("typescript-eslint-parser") :
    /* otherwise */ require("espree")
github fkling / astexplorer / website / src / parsers / js / utils / eslintUtils.js View on Github external
export function runRule(code, eslint, sourceCode) {
  // Run the ESLint rule on the AST of the provided code.
  // Reference: http://eslint.org/docs/developer-guide/nodejs-api
  const ast = parseNoPatch(code, {
    sourceType: 'module',
  });
  const results = eslint.verify(new sourceCode(code, ast), {
    env: {es6: true},
    parserOptions: {
      ecmaVersion: 8,
      sourceType: 'module',
      ecmaFeatures: {experimentalObjectRestSpread: true},
    },
    rules: {
      astExplorerRule: 2,
    },
  });
  return formatResults(results);
}
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 ember-cli / eslint-plugin-ember / tests / helpers / faux-context.js View on Github external
constructor(code, filename = '', report = () => {}) {
    const { ast } = babelEslint.parseForESLint(code);

    this.ast = ast;
    this.filename = filename;
    this.report = report;
  }
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);
          });
        });
github mysticatea / vue-eslint-demo / scripts / make-versions.js View on Github external
"use strict"

const fs = require("fs")

fs.writeFileSync(
    "dist/versions.json",
    JSON.stringify({
        "babel-eslint": require("babel-eslint/package.json").version,
        eslint: require("eslint/package.json").version,
        "eslint-plugin-vue": require("eslint-plugin-vue/package.json").version,
        typescript: require("typescript/package.json").version,
        "typescript-eslint-parser": require("typescript-eslint-parser/package.json")
            .version,
        "vue-eslint-demo": require("../package.json").version,
        "vue-eslint-parser": require("vue-eslint-parser/package.json").version,
    }),
)
github fkling / astexplorer / website / src / parsers / js / babel-eslint.js View on Github external
import defaultParserInterface from './utils/defaultESTreeParserInterface';
import pkg from 'babel-eslint/package.json';

const ID = 'babel-eslint';

export default {
  ...defaultParserInterface,

  id: ID,
  displayName: ID,
  version: pkg.version,
  homepage: pkg.homepage,
  locationProps: new Set(['loc', 'start', 'end', 'range']),

  loadParser(callback) {
    require(['babel-eslint'], callback);
  },

  parse(parser, code) {
    const opts = {
      sourceType: 'module',
    };

    const ast = parser.parseNoPatch(code, opts);
    delete ast.tokens;
    return ast;
  },