How to use the eslint/package.json.version function in eslint

To help you get started, we’ve selected a few 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 benmosher / eslint-plugin-import / tests / src / rules / no-amd.js View on Github external
'require("x", "y")',
    // random other function
    'setTimeout(foo, 100)',
    // non-identifier callee
    '(a || b)(1, 2, 3)',

    // nested scope is fine
    'function x() { define(["a"], function (a) {}) }',
    'function x() { require(["a"], function (a) {}) }',

    // unmatched arg types/number
    'define(0, 1, 2)',
    'define("a")',
	],

	invalid: semver.satisfies(eslintPkg.version, '< 4.0.0') ? [] : [
      { code: 'define([], function() {})', errors: [ { message: 'Expected imports instead of AMD define().' }] },
      { code: 'define(["a"], function(a) { console.log(a); })', errors: [ { message: 'Expected imports instead of AMD define().' }] },

      { code: 'require([], function() {})', errors: [ { message: 'Expected imports instead of AMD require().' }] },
      { code: 'require(["a"], function(a) { console.log(a); })', errors: [ { message: 'Expected imports instead of AMD require().' }] },
	],
})
github benmosher / eslint-plugin-import / tests / src / rules / no-commonjs.js View on Github external
{ code: 'module.exports = function () {}', options: [{ allowPrimitiveModules: true }] },
    { code: 'module.exports = "foo"', options: ['allow-primitive-modules'] },
    { code: 'module.exports = "foo"', options: [{ allowPrimitiveModules: true }] },

    { code: 'if (typeof window !== "undefined") require("x")', options: [{ allowRequire: true }] },
    { code: 'if (typeof window !== "undefined") require("x")', options: [{ allowRequire: false }] },
    { code: 'if (typeof window !== "undefined") { require("x") }', options: [{ allowRequire: true }] },
    { code: 'if (typeof window !== "undefined") { require("x") }', options: [{ allowRequire: false }] },
  
    { code: 'try { require("x") } catch (error) {}' },
  ],

  invalid: [

    // imports
    ...(semver.satisfies(eslintPkg.version, '< 4.0.0') ? [] : [
      { code: 'var x = require("x")', errors: [ { message: IMPORT_MESSAGE }] },
      { code: 'x = require("x")', errors: [ { message: IMPORT_MESSAGE }] },
      { code: 'require("x")', errors: [ { message: IMPORT_MESSAGE }] },

      { code: 'if (typeof window !== "undefined") require("x")',
        options: [{ allowConditionalRequire: false }],
        errors: [ { message: IMPORT_MESSAGE }],
      },
      { code: 'if (typeof window !== "undefined") { require("x") }',
        options: [{ allowConditionalRequire: false }],
        errors: [ { message: IMPORT_MESSAGE }],
      },
      { code: 'try { require("x") } catch (error) {}',
        options: [{ allowConditionalRequire: false }],
        errors: [ { message: IMPORT_MESSAGE }],
      },
github benmosher / eslint-plugin-import / tests / src / core / getExports.js View on Github external
context('alternate parsers', function () {

    const configs = [
      // ['string form', { 'typescript-eslint-parser': '.ts' }],
    ]

    if (semver.satisfies(eslintPkg.version, '>5.0.0')) {
      configs.push(['array form', { '@typescript-eslint/parser': ['.ts', '.tsx'] }])
    }

    if (semver.satisfies(eslintPkg.version, '<6.0.0')) {
      configs.push(['array form', { 'typescript-eslint-parser': ['.ts', '.tsx'] }])
    }

    configs.forEach(([description, parserConfig]) => {

      describe(description, function () {
        const context = Object.assign({}, fakeContext,
          { settings: {
            'import/extensions': ['.js'],
            'import/parsers': parserConfig,
          } })

        let imports
        before('load imports', function () {
          this.timeout(20000)  // takes a long time :shrug:
          imports = ExportMap.get('./typescript.ts', context)
github ecomfe / fecs / test / lib / cli.spec.js View on Github external
expect(console.log).toHaveBeenCalled();
        expect(console.log).toHaveBeenCalledWith('%s %s', pkg.name, pkg.version);

        process.argv = ['node', 'fecs', '-v'];
        cli.parse();

        expect(console.log.calls.count()).toEqual(2);
        expect(console.log.calls.mostRecent().args).toEqual(['%s %s', pkg.name, pkg.version]);

        process.argv = ['node', 'fecs', '-v', 'eslint'];
        cli.parse();

        var eslint = require('eslint/package.json');
        expect(console.log.calls.count()).toEqual(4);
        expect(console.log.calls.mostRecent().args).toEqual(['    %s@%s', eslint.name, eslint.version]);

        console.log = log;
    });
github benmosher / eslint-plugin-import / tests / src / utils.js View on Github external
export function getTSParsers() {
  const parsers = []
  if (semver.satisfies(eslintPkg.version, '>=4.0.0 <6.0.0')) {
    parsers.push(require.resolve('typescript-eslint-parser'))
  }

  if (semver.satisfies(eslintPkg.version, '>5.0.0')) {
    parsers.push(require.resolve('@typescript-eslint/parser'))
  }
  return parsers
}
github BenoitZugmeyer / eslint-plugin-html / src / __tests__ / plugin.js View on Github external
"use strict"

const path = require("path")
const CLIEngine = require("eslint").CLIEngine
const semver = require("semver")
const eslintVersion = require("eslint/package.json").version
const plugin = require("..")

function matchVersion(versionSpec) {
  return semver.satisfies(eslintVersion, versionSpec)
}

function ifVersion(versionSpec, fn, ...args) {
  const execFn = matchVersion(versionSpec) ? fn : fn.skip
  execFn(...args)
}

function execute(file, baseConfig) {
  if (!baseConfig) baseConfig = {}

  const cli = new CLIEngine({
    extensions: ["html"],
github benmosher / eslint-plugin-import / tests / src / utils.js View on Github external
export function getTSParsers() {
  const parsers = []
  if (semver.satisfies(eslintPkg.version, '>=4.0.0 <6.0.0')) {
    parsers.push(require.resolve('typescript-eslint-parser'))
  }

  if (semver.satisfies(eslintPkg.version, '>5.0.0')) {
    parsers.push(require.resolve('@typescript-eslint/parser'))
  }
  return parsers
}
github mantoni / eslint_d.js / bin / eslint_d.js View on Github external
#!/usr/bin/env node
'use strict';

const cmd = process.argv[2];

if (cmd === '-v' || cmd === '--version') {
  console.log('v%s (eslint_d v%s)',
    require('eslint/package.json').version,
    require('../package.json').version);
  return;
}

if (cmd === '-h' || cmd === '--help') {
  const options = require('../lib/options');
  console.log(options.generateHelp());
  return;
}

process.env.CORE_D_TITLE = 'eslint_d';
process.env.CORE_D_DOTFILE = '.eslint_d';
process.env.CORE_D_SERVICE = require.resolve('../lib/linter');

const core_d = require('core_d');
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 BenoitZugmeyer / eslint-plugin-html / src / index.js View on Github external
const Linter = getModuleFromCache(key)
    if (Linter) {
      fn(Linter)
      found = true
    }
  }

  if (!found) {
    let eslintPath, eslintVersion
    try {
      eslintPath = require.resolve("eslint")
    } catch (e) {
      eslintPath = "(not found)"
    }
    try {
      eslintVersion = require("eslint/package.json").version
    } catch (e) {
      eslintVersion = "n/a"
    }

    const parentPaths = module =>
      module ? [module.filename].concat(parentPaths(module.parent)) : []

    throw new Error(
      `eslint-plugin-html error: It seems that eslint is not loaded.
If you think this is a bug, please file a report at https://github.com/BenoitZugmeyer/eslint-plugin-html/issues

In the report, please include *all* those informations:

* ESLint version: ${eslintVersion}
* ESLint path: ${eslintPath}
* Plugin version: ${require("../package.json").version}