Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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().' }] },
],
})
{ 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 }],
},
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)
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;
});
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
}
"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"],
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
}
#!/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');
"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,
}),
)
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}