This commit is contained in:
Lilith 2025-02-27 02:26:55 +01:00
parent a71a3b5593
commit cb52890889
Signed by: lilith
GPG key ID: 8712A0F317C37175
16657 changed files with 1483086 additions and 1 deletions

View file

@ -0,0 +1,178 @@
'use strict';
const eslint = require('eslint');
const semver = require('semver');
const convertConfig = require('./shared/eslint-compat-utils.503aeaae.cjs');
const getUnsupported = require('./shared/eslint-compat-utils.cb53cf36.cjs');
require('module');
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
const n = Object.create(null);
if (e) {
for (const k in e) {
n[k] = e[k];
}
}
n.default = e;
return n;
}
const eslint__namespace = /*#__PURE__*/_interopNamespaceCompat(eslint);
const semver__namespace = /*#__PURE__*/_interopNamespaceCompat(semver);
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
let cacheESLint, cacheLegacyESLint;
function getESLint() {
return cacheESLint != null ? cacheESLint : cacheESLint = getESLintInternal();
function getESLintInternal() {
if (semver__namespace.gte(eslint__namespace.Linter.version, "9.0.0-0")) {
return eslint__namespace.ESLint;
}
return getUnsupported.getUnsupported().FlatESLint || (eslint__namespace.ESLint ? getESLintClassFromLegacyESLint(eslint__namespace.ESLint) : getESLintClassFromLegacyESLint(getLegacyESLintClassFromCLIEngine()));
}
}
function getLegacyESLint() {
return cacheLegacyESLint != null ? cacheLegacyESLint : cacheLegacyESLint = getLegacyESLintInternal();
function getLegacyESLintInternal() {
return getUnsupported.getUnsupported().LegacyESLint || eslint__namespace.ESLint || getLegacyESLintClassFromCLIEngine();
}
}
function getESLintClassFromLegacyESLint(legacyESLintClass) {
return class ESLintFromLegacyESLint extends legacyESLintClass {
static get version() {
return legacyESLintClass.version;
}
constructor(options) {
super(adjustOptions(options));
}
};
function adjustOptions(options) {
const {
baseConfig: originalBaseConfig,
overrideConfig: originalOverrideConfig,
overrideConfigFile,
...newOptions
} = options || {};
if (originalBaseConfig) {
const [baseConfig, plugins] = convertConfig$1(originalBaseConfig);
newOptions.baseConfig = baseConfig;
if (plugins) {
newOptions.plugins = plugins;
}
}
if (originalOverrideConfig) {
const [overrideConfig, plugins] = convertConfig$1(originalOverrideConfig);
newOptions.overrideConfig = overrideConfig;
if (plugins) {
newOptions.plugins = plugins;
}
}
if (overrideConfigFile) {
if (overrideConfigFile === true) {
newOptions.useEslintrc = false;
} else {
newOptions.overrideConfigFile = overrideConfigFile;
}
}
return newOptions;
}
function convertConfig$1(config) {
const pluginDefs = {};
const newConfigs = [];
for (const configItem of Array.isArray(config) ? config : [config]) {
const { plugins, ...otherConfig } = configItem;
if (typeof otherConfig.processor !== "string")
delete otherConfig.processor;
const newConfig = {
files: ["**/*.*", "*.*", "**/*", "*"],
...convertConfig.convertConfigToRc(otherConfig)
};
if (plugins) {
newConfig.plugins = Object.keys(plugins);
}
Object.assign(pluginDefs, plugins);
newConfigs.push(newConfig);
}
return [{ overrides: newConfigs }, pluginDefs];
}
}
function getLegacyESLintClassFromCLIEngine() {
const CLIEngine = eslint__namespace.CLIEngine;
class LegacyESLintFromCLIEngine {
constructor(options) {
__publicField(this, "engine");
const {
overrideConfig: {
plugins,
globals,
rules,
overrides,
...overrideConfig
} = {
plugins: [],
globals: {},
rules: {},
overrides: []
},
fix,
reportUnusedDisableDirectives,
plugins: pluginsMap,
...otherOptions
} = options || {};
const cliEngineOptions = {
baseConfig: {
...overrides ? {
overrides
} : {}
},
fix: Boolean(fix),
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? reportUnusedDisableDirectives !== "off" : void 0,
...otherOptions,
globals: globals ? Object.keys(globals).filter((n) => globals[n]) : void 0,
plugins: plugins || [],
rules: rules ? Object.fromEntries(
Object.entries(rules).flatMap(
([ruleId, opt]) => opt ? [[ruleId, opt]] : []
)
) : void 0,
...overrideConfig
};
this.engine = new CLIEngine(cliEngineOptions);
for (const [name, plugin] of Object.entries(pluginsMap || {})) {
this.engine.addPlugin(name, plugin);
}
}
static get version() {
return CLIEngine.version;
}
// eslint-disable-next-line @typescript-eslint/require-await -- ignore
async lintText(...params) {
var _a;
const result = this.engine.executeOnText(params[0], (_a = params[1]) == null ? void 0 : _a.filePath);
return result.results;
}
// eslint-disable-next-line @typescript-eslint/require-await -- ignore
async lintFiles(...params) {
const result = this.engine.executeOnFiles(
Array.isArray(params[0]) ? params[0] : [params[0]]
);
return result.results;
}
// eslint-disable-next-line @typescript-eslint/require-await -- ignore
static async outputFixes(...params) {
return CLIEngine.outputFixes({
results: params[0]
});
}
}
return LegacyESLintFromCLIEngine;
}
exports.getESLint = getESLint;
exports.getLegacyESLint = getLegacyESLint;

View file

@ -0,0 +1,12 @@
import * as eslint from 'eslint';
/**
* Get ESLint class
*/
declare function getESLint(): typeof eslint.ESLint;
/**
* Get LegacyESLint class
*/
declare function getLegacyESLint(): typeof eslint.ESLint;
export { getESLint, getLegacyESLint };

View file

@ -0,0 +1,12 @@
import * as eslint from 'eslint';
/**
* Get ESLint class
*/
declare function getESLint(): typeof eslint.ESLint;
/**
* Get LegacyESLint class
*/
declare function getLegacyESLint(): typeof eslint.ESLint;
export { getESLint, getLegacyESLint };

View file

@ -0,0 +1,12 @@
import * as eslint from 'eslint';
/**
* Get ESLint class
*/
declare function getESLint(): typeof eslint.ESLint;
/**
* Get LegacyESLint class
*/
declare function getLegacyESLint(): typeof eslint.ESLint;
export { getESLint, getLegacyESLint };

View file

@ -0,0 +1,160 @@
import * as eslint from 'eslint';
import * as semver from 'semver';
import { c as convertConfigToRc } from './shared/eslint-compat-utils.1a5060cf.mjs';
import { g as getUnsupported } from './shared/eslint-compat-utils.3ecba7ac.mjs';
import 'module';
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
let cacheESLint, cacheLegacyESLint;
function getESLint() {
return cacheESLint != null ? cacheESLint : cacheESLint = getESLintInternal();
function getESLintInternal() {
if (semver.gte(eslint.Linter.version, "9.0.0-0")) {
return eslint.ESLint;
}
return getUnsupported().FlatESLint || (eslint.ESLint ? getESLintClassFromLegacyESLint(eslint.ESLint) : getESLintClassFromLegacyESLint(getLegacyESLintClassFromCLIEngine()));
}
}
function getLegacyESLint() {
return cacheLegacyESLint != null ? cacheLegacyESLint : cacheLegacyESLint = getLegacyESLintInternal();
function getLegacyESLintInternal() {
return getUnsupported().LegacyESLint || eslint.ESLint || getLegacyESLintClassFromCLIEngine();
}
}
function getESLintClassFromLegacyESLint(legacyESLintClass) {
return class ESLintFromLegacyESLint extends legacyESLintClass {
static get version() {
return legacyESLintClass.version;
}
constructor(options) {
super(adjustOptions(options));
}
};
function adjustOptions(options) {
const {
baseConfig: originalBaseConfig,
overrideConfig: originalOverrideConfig,
overrideConfigFile,
...newOptions
} = options || {};
if (originalBaseConfig) {
const [baseConfig, plugins] = convertConfig(originalBaseConfig);
newOptions.baseConfig = baseConfig;
if (plugins) {
newOptions.plugins = plugins;
}
}
if (originalOverrideConfig) {
const [overrideConfig, plugins] = convertConfig(originalOverrideConfig);
newOptions.overrideConfig = overrideConfig;
if (plugins) {
newOptions.plugins = plugins;
}
}
if (overrideConfigFile) {
if (overrideConfigFile === true) {
newOptions.useEslintrc = false;
} else {
newOptions.overrideConfigFile = overrideConfigFile;
}
}
return newOptions;
}
function convertConfig(config) {
const pluginDefs = {};
const newConfigs = [];
for (const configItem of Array.isArray(config) ? config : [config]) {
const { plugins, ...otherConfig } = configItem;
if (typeof otherConfig.processor !== "string")
delete otherConfig.processor;
const newConfig = {
files: ["**/*.*", "*.*", "**/*", "*"],
...convertConfigToRc(otherConfig)
};
if (plugins) {
newConfig.plugins = Object.keys(plugins);
}
Object.assign(pluginDefs, plugins);
newConfigs.push(newConfig);
}
return [{ overrides: newConfigs }, pluginDefs];
}
}
function getLegacyESLintClassFromCLIEngine() {
const CLIEngine = eslint.CLIEngine;
class LegacyESLintFromCLIEngine {
constructor(options) {
__publicField(this, "engine");
const {
overrideConfig: {
plugins,
globals,
rules,
overrides,
...overrideConfig
} = {
plugins: [],
globals: {},
rules: {},
overrides: []
},
fix,
reportUnusedDisableDirectives,
plugins: pluginsMap,
...otherOptions
} = options || {};
const cliEngineOptions = {
baseConfig: {
...overrides ? {
overrides
} : {}
},
fix: Boolean(fix),
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? reportUnusedDisableDirectives !== "off" : void 0,
...otherOptions,
globals: globals ? Object.keys(globals).filter((n) => globals[n]) : void 0,
plugins: plugins || [],
rules: rules ? Object.fromEntries(
Object.entries(rules).flatMap(
([ruleId, opt]) => opt ? [[ruleId, opt]] : []
)
) : void 0,
...overrideConfig
};
this.engine = new CLIEngine(cliEngineOptions);
for (const [name, plugin] of Object.entries(pluginsMap || {})) {
this.engine.addPlugin(name, plugin);
}
}
static get version() {
return CLIEngine.version;
}
// eslint-disable-next-line @typescript-eslint/require-await -- ignore
async lintText(...params) {
var _a;
const result = this.engine.executeOnText(params[0], (_a = params[1]) == null ? void 0 : _a.filePath);
return result.results;
}
// eslint-disable-next-line @typescript-eslint/require-await -- ignore
async lintFiles(...params) {
const result = this.engine.executeOnFiles(
Array.isArray(params[0]) ? params[0] : [params[0]]
);
return result.results;
}
// eslint-disable-next-line @typescript-eslint/require-await -- ignore
static async outputFixes(...params) {
return CLIEngine.outputFixes({
results: params[0]
});
}
}
return LegacyESLintFromCLIEngine;
}
export { getESLint, getLegacyESLint };

View file

@ -0,0 +1,126 @@
'use strict';
const path = require('path');
const fs = require('fs');
function applyPolyfills(object, polyfill) {
return new Proxy(object, {
get(_target, p) {
var _a;
return (_a = object[p]) != null ? _a : polyfill[p];
}
});
}
function getParent(node) {
return node.parent;
}
const cache = /* @__PURE__ */ new WeakMap();
function getSourceCode(context) {
const original = context.sourceCode || context.getSourceCode();
const cached = cache.get(original);
if (cached) {
return cached;
}
const sourceCode = applyPolyfills(original, {
getScope(node) {
const inner = node.type !== "Program";
for (let n = node; n; n = getParent(n)) {
const scope = original.scopeManager.acquire(n, inner);
if (scope) {
if (scope.type === "function-expression-name") {
return scope.childScopes[0];
}
return scope;
}
}
return original.scopeManager.scopes[0];
},
markVariableAsUsed(name, refNode = original.ast) {
const currentScope = sourceCode.getScope(refNode);
if (currentScope === context.getScope()) {
return context.markVariableAsUsed(name);
}
let initialScope = currentScope;
if (currentScope.type === "global" && currentScope.childScopes.length > 0 && currentScope.childScopes[0].block === original.ast) {
initialScope = currentScope.childScopes[0];
}
for (let scope = initialScope; scope; scope = scope.upper) {
const variable = scope.variables.find(
(scopeVar) => scopeVar.name === name
);
if (variable) {
variable.eslintUsed = true;
return true;
}
}
return false;
},
getAncestors(node) {
const result = [];
for (let ancestor = getParent(node); ancestor; ancestor = ancestor.parent) {
result.unshift(ancestor);
}
return result;
},
getDeclaredVariables(node) {
return original.scopeManager.getDeclaredVariables(node);
},
isSpaceBetween(first, second) {
if (first.range[0] <= second.range[1] && second.range[0] <= first.range[1]) {
return false;
}
const [startingNodeOrToken, endingNodeOrToken] = first.range[1] <= second.range[0] ? [first, second] : [second, first];
const tokens = sourceCode.getTokensBetween(first, second, {
includeComments: true
});
let startIndex = startingNodeOrToken.range[1];
for (const token of tokens) {
if (startIndex !== token.range[0]) {
return true;
}
startIndex = token.range[1];
}
return startIndex !== endingNodeOrToken.range[0];
}
});
cache.set(original, sourceCode);
return sourceCode;
}
function getCwd(context) {
var _a, _b, _c;
return (_c = (_b = context.cwd) != null ? _b : (_a = context.getCwd) == null ? void 0 : _a.call(context)) != null ? _c : (
// getCwd is added in v6.6.0
process.cwd()
);
}
function getFilename(context) {
var _a;
return (_a = context.filename) != null ? _a : context.getFilename();
}
function getPhysicalFilename(context) {
var _a, _b;
const physicalFilename = (_b = context.physicalFilename) != null ? _b : (_a = context.getPhysicalFilename) == null ? void 0 : _a.call(context);
if (physicalFilename != null) {
return physicalFilename;
}
const filename = getFilename(context);
let target = filename;
while (/^\d+_/u.test(path.basename(target)) && !fs.existsSync(target)) {
const next = path.dirname(target);
if (next === target || !path.extname(next)) {
break;
}
target = next;
}
return target;
}
exports.getCwd = getCwd;
exports.getFilename = getFilename;
exports.getPhysicalFilename = getPhysicalFilename;
exports.getSourceCode = getSourceCode;

View file

@ -0,0 +1,28 @@
import { Rule, SourceCode } from 'eslint';
/**
* Returns an extended instance of `context.sourceCode` or the result of `context.getSourceCode()`.
* Extended instances can use new APIs such as `getScope(node)` even with old ESLint.
*/
declare function getSourceCode(context: Rule.RuleContext): SourceCode;
/**
* Gets the value of `context.cwd`, but for older ESLint it returns the result of `context.getCwd()`.
* Versions older than v6.6.0 return a value from the result of `process.cwd()`.
*/
declare function getCwd(context: Rule.RuleContext): string;
/**
* Gets the value of `context.filename`, but for older ESLint it returns the result of `context.getFilename()`.
*/
declare function getFilename(context: Rule.RuleContext): string;
/**
* Gets the value of `context.physicalFilename`,
* but for older ESLint it returns the result of `context.getPhysicalFilename()`.
* Versions older than v7.28.0 return a value guessed from the result of `context.getFilename()`,
* but it may be incorrect.
*/
declare function getPhysicalFilename(context: Rule.RuleContext): string;
export { getCwd, getFilename, getPhysicalFilename, getSourceCode };

View file

@ -0,0 +1,28 @@
import { Rule, SourceCode } from 'eslint';
/**
* Returns an extended instance of `context.sourceCode` or the result of `context.getSourceCode()`.
* Extended instances can use new APIs such as `getScope(node)` even with old ESLint.
*/
declare function getSourceCode(context: Rule.RuleContext): SourceCode;
/**
* Gets the value of `context.cwd`, but for older ESLint it returns the result of `context.getCwd()`.
* Versions older than v6.6.0 return a value from the result of `process.cwd()`.
*/
declare function getCwd(context: Rule.RuleContext): string;
/**
* Gets the value of `context.filename`, but for older ESLint it returns the result of `context.getFilename()`.
*/
declare function getFilename(context: Rule.RuleContext): string;
/**
* Gets the value of `context.physicalFilename`,
* but for older ESLint it returns the result of `context.getPhysicalFilename()`.
* Versions older than v7.28.0 return a value guessed from the result of `context.getFilename()`,
* but it may be incorrect.
*/
declare function getPhysicalFilename(context: Rule.RuleContext): string;
export { getCwd, getFilename, getPhysicalFilename, getSourceCode };

View file

@ -0,0 +1,28 @@
import { Rule, SourceCode } from 'eslint';
/**
* Returns an extended instance of `context.sourceCode` or the result of `context.getSourceCode()`.
* Extended instances can use new APIs such as `getScope(node)` even with old ESLint.
*/
declare function getSourceCode(context: Rule.RuleContext): SourceCode;
/**
* Gets the value of `context.cwd`, but for older ESLint it returns the result of `context.getCwd()`.
* Versions older than v6.6.0 return a value from the result of `process.cwd()`.
*/
declare function getCwd(context: Rule.RuleContext): string;
/**
* Gets the value of `context.filename`, but for older ESLint it returns the result of `context.getFilename()`.
*/
declare function getFilename(context: Rule.RuleContext): string;
/**
* Gets the value of `context.physicalFilename`,
* but for older ESLint it returns the result of `context.getPhysicalFilename()`.
* Versions older than v7.28.0 return a value guessed from the result of `context.getFilename()`,
* but it may be incorrect.
*/
declare function getPhysicalFilename(context: Rule.RuleContext): string;
export { getCwd, getFilename, getPhysicalFilename, getSourceCode };

View file

@ -0,0 +1,121 @@
import { basename, dirname, extname } from 'path';
import { existsSync } from 'fs';
function applyPolyfills(object, polyfill) {
return new Proxy(object, {
get(_target, p) {
var _a;
return (_a = object[p]) != null ? _a : polyfill[p];
}
});
}
function getParent(node) {
return node.parent;
}
const cache = /* @__PURE__ */ new WeakMap();
function getSourceCode(context) {
const original = context.sourceCode || context.getSourceCode();
const cached = cache.get(original);
if (cached) {
return cached;
}
const sourceCode = applyPolyfills(original, {
getScope(node) {
const inner = node.type !== "Program";
for (let n = node; n; n = getParent(n)) {
const scope = original.scopeManager.acquire(n, inner);
if (scope) {
if (scope.type === "function-expression-name") {
return scope.childScopes[0];
}
return scope;
}
}
return original.scopeManager.scopes[0];
},
markVariableAsUsed(name, refNode = original.ast) {
const currentScope = sourceCode.getScope(refNode);
if (currentScope === context.getScope()) {
return context.markVariableAsUsed(name);
}
let initialScope = currentScope;
if (currentScope.type === "global" && currentScope.childScopes.length > 0 && currentScope.childScopes[0].block === original.ast) {
initialScope = currentScope.childScopes[0];
}
for (let scope = initialScope; scope; scope = scope.upper) {
const variable = scope.variables.find(
(scopeVar) => scopeVar.name === name
);
if (variable) {
variable.eslintUsed = true;
return true;
}
}
return false;
},
getAncestors(node) {
const result = [];
for (let ancestor = getParent(node); ancestor; ancestor = ancestor.parent) {
result.unshift(ancestor);
}
return result;
},
getDeclaredVariables(node) {
return original.scopeManager.getDeclaredVariables(node);
},
isSpaceBetween(first, second) {
if (first.range[0] <= second.range[1] && second.range[0] <= first.range[1]) {
return false;
}
const [startingNodeOrToken, endingNodeOrToken] = first.range[1] <= second.range[0] ? [first, second] : [second, first];
const tokens = sourceCode.getTokensBetween(first, second, {
includeComments: true
});
let startIndex = startingNodeOrToken.range[1];
for (const token of tokens) {
if (startIndex !== token.range[0]) {
return true;
}
startIndex = token.range[1];
}
return startIndex !== endingNodeOrToken.range[0];
}
});
cache.set(original, sourceCode);
return sourceCode;
}
function getCwd(context) {
var _a, _b, _c;
return (_c = (_b = context.cwd) != null ? _b : (_a = context.getCwd) == null ? void 0 : _a.call(context)) != null ? _c : (
// getCwd is added in v6.6.0
process.cwd()
);
}
function getFilename(context) {
var _a;
return (_a = context.filename) != null ? _a : context.getFilename();
}
function getPhysicalFilename(context) {
var _a, _b;
const physicalFilename = (_b = context.physicalFilename) != null ? _b : (_a = context.getPhysicalFilename) == null ? void 0 : _a.call(context);
if (physicalFilename != null) {
return physicalFilename;
}
const filename = getFilename(context);
let target = filename;
while (/^\d+_/u.test(basename(target)) && !existsSync(target)) {
const next = dirname(target);
if (next === target || !extname(next)) {
break;
}
target = next;
}
return target;
}
export { getCwd, getFilename, getPhysicalFilename, getSourceCode };

View file

@ -0,0 +1,48 @@
'use strict';
const eslint = require('eslint');
const semver = require('semver');
const convertConfig = require('./shared/eslint-compat-utils.503aeaae.cjs');
const convertOption = require('./shared/eslint-compat-utils.808b5669.cjs');
require('module');
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
const n = Object.create(null);
if (e) {
for (const k in e) {
n[k] = e[k];
}
}
n.default = e;
return n;
}
const eslint__namespace = /*#__PURE__*/_interopNamespaceCompat(eslint);
const semver__namespace = /*#__PURE__*/_interopNamespaceCompat(semver);
let cacheLinter;
function getLinter() {
return cacheLinter != null ? cacheLinter : cacheLinter = getLinterInternal();
function getLinterInternal() {
if (semver__namespace.gte(eslint__namespace.Linter.version, "9.0.0-0")) {
return eslint__namespace.Linter;
}
return getLinterClassFromLegacyLinter();
}
}
function getLinterClassFromLegacyLinter() {
return class LinterFromLegacyLinter extends eslint__namespace.Linter {
static get version() {
return eslint__namespace.Linter.version;
}
verify(code, config, option) {
const { processor, ...otherConfig } = config || {};
const newConfig = convertConfig.convertConfigToRc(otherConfig, this);
const newOption = convertOption.convertOptionToLegacy(processor, option, config || {});
return super.verify(code, newConfig, newOption);
}
};
}
exports.getLinter = getLinter;

View file

@ -0,0 +1,8 @@
import * as eslint from 'eslint';
/**
* Get Linter class
*/
declare function getLinter(): typeof eslint.Linter;
export { getLinter };

View file

@ -0,0 +1,8 @@
import * as eslint from 'eslint';
/**
* Get Linter class
*/
declare function getLinter(): typeof eslint.Linter;
export { getLinter };

View file

@ -0,0 +1,8 @@
import * as eslint from 'eslint';
/**
* Get Linter class
*/
declare function getLinter(): typeof eslint.Linter;
export { getLinter };

View file

@ -0,0 +1,31 @@
import * as eslint from 'eslint';
import * as semver from 'semver';
import { c as convertConfigToRc } from './shared/eslint-compat-utils.1a5060cf.mjs';
import { c as convertOptionToLegacy } from './shared/eslint-compat-utils.cb6790c2.mjs';
import 'module';
let cacheLinter;
function getLinter() {
return cacheLinter != null ? cacheLinter : cacheLinter = getLinterInternal();
function getLinterInternal() {
if (semver.gte(eslint.Linter.version, "9.0.0-0")) {
return eslint.Linter;
}
return getLinterClassFromLegacyLinter();
}
}
function getLinterClassFromLegacyLinter() {
return class LinterFromLegacyLinter extends eslint.Linter {
static get version() {
return eslint.Linter.version;
}
verify(code, config, option) {
const { processor, ...otherConfig } = config || {};
const newConfig = convertConfigToRc(otherConfig, this);
const newOption = convertOptionToLegacy(processor, option, config || {});
return super.verify(code, newConfig, newOption);
}
};
}
export { getLinter };

View file

@ -0,0 +1,110 @@
'use strict';
const eslint = require('eslint');
const semver = require('semver');
const convertConfig = require('./shared/eslint-compat-utils.503aeaae.cjs');
const getUnsupported = require('./shared/eslint-compat-utils.cb53cf36.cjs');
const convertOption = require('./shared/eslint-compat-utils.808b5669.cjs');
require('module');
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
const n = Object.create(null);
if (e) {
for (const k in e) {
n[k] = e[k];
}
}
n.default = e;
return n;
}
const eslint__namespace = /*#__PURE__*/_interopNamespaceCompat(eslint);
const semver__namespace = /*#__PURE__*/_interopNamespaceCompat(semver);
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
let cacheRuleTester;
let cachePrefix = "";
function getRuleTester() {
return cacheRuleTester != null ? cacheRuleTester : cacheRuleTester = getRuleTesterInternal();
function getRuleTesterInternal() {
if (semver__namespace.gte(eslint__namespace.Linter.version, "9.0.0-0")) {
cachePrefix = "rule-to-test/";
return eslint__namespace.RuleTester;
}
const flatRuleTester = getUnsupported.getUnsupported().FlatRuleTester;
if (flatRuleTester) {
cachePrefix = "rule-to-test/";
return patchForV8FlatRuleTester(flatRuleTester);
}
return getRuleTesterClassFromLegacyRuleTester();
}
}
function getRuleIdPrefix() {
getRuleTester();
return cachePrefix;
}
function patchForV8FlatRuleTester(flatRuleTester) {
return class RuleTesterWithPatch extends flatRuleTester {
constructor(options) {
super(patchConfig(options));
}
};
function patchConfig(config) {
return {
files: ["**/*.*"],
...config
};
}
}
function getRuleTesterClassFromLegacyRuleTester() {
return class RuleTesterForV8 extends eslint__namespace.RuleTester {
constructor(options) {
var _a;
const defineRules = [];
const { processor, ...others } = options;
super(
convertConfig.convertConfigToRc(others, {
defineRule(...args) {
defineRules.push(args);
}
})
);
__publicField(this, "defaultProcessor");
for (const args of defineRules) {
(_a = this.linter) == null ? void 0 : _a.defineRule(...args);
}
this.defaultProcessor = processor;
}
run(name, rule, tests) {
super.run(name, rule, {
valid: (tests.valid || []).map(
(test) => typeof test === "string" ? test : convert(test, this.defaultProcessor)
),
invalid: (tests.invalid || []).map(
(test) => convert(test, this.defaultProcessor)
)
});
}
};
function convert(config, defaultProcessor) {
const { processor: configProcessor, ...otherConfig } = config;
const processor = configProcessor || defaultProcessor;
const converted = convertConfig.convertConfigToRc(otherConfig);
if (!processor) {
return converted;
}
return {
...converted,
filename: convertOption.convertOptionToLegacy(processor, config.filename, config)
};
}
}
exports.getRuleIdPrefix = getRuleIdPrefix;
exports.getRuleTester = getRuleTester;

View file

@ -0,0 +1,12 @@
import * as eslint from 'eslint';
/**
* Get RuleTester class
*/
declare function getRuleTester(): typeof eslint.RuleTester;
/**
* Get the prefix of the ruleId used in the rule tester.
*/
declare function getRuleIdPrefix(): string;
export { getRuleIdPrefix, getRuleTester };

View file

@ -0,0 +1,12 @@
import * as eslint from 'eslint';
/**
* Get RuleTester class
*/
declare function getRuleTester(): typeof eslint.RuleTester;
/**
* Get the prefix of the ruleId used in the rule tester.
*/
declare function getRuleIdPrefix(): string;
export { getRuleIdPrefix, getRuleTester };

View file

@ -0,0 +1,12 @@
import * as eslint from 'eslint';
/**
* Get RuleTester class
*/
declare function getRuleTester(): typeof eslint.RuleTester;
/**
* Get the prefix of the ruleId used in the rule tester.
*/
declare function getRuleIdPrefix(): string;
export { getRuleIdPrefix, getRuleTester };

View file

@ -0,0 +1,92 @@
import * as eslint from 'eslint';
import * as semver from 'semver';
import { c as convertConfigToRc } from './shared/eslint-compat-utils.1a5060cf.mjs';
import { g as getUnsupported } from './shared/eslint-compat-utils.3ecba7ac.mjs';
import { c as convertOptionToLegacy } from './shared/eslint-compat-utils.cb6790c2.mjs';
import 'module';
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
let cacheRuleTester;
let cachePrefix = "";
function getRuleTester() {
return cacheRuleTester != null ? cacheRuleTester : cacheRuleTester = getRuleTesterInternal();
function getRuleTesterInternal() {
if (semver.gte(eslint.Linter.version, "9.0.0-0")) {
cachePrefix = "rule-to-test/";
return eslint.RuleTester;
}
const flatRuleTester = getUnsupported().FlatRuleTester;
if (flatRuleTester) {
cachePrefix = "rule-to-test/";
return patchForV8FlatRuleTester(flatRuleTester);
}
return getRuleTesterClassFromLegacyRuleTester();
}
}
function getRuleIdPrefix() {
getRuleTester();
return cachePrefix;
}
function patchForV8FlatRuleTester(flatRuleTester) {
return class RuleTesterWithPatch extends flatRuleTester {
constructor(options) {
super(patchConfig(options));
}
};
function patchConfig(config) {
return {
files: ["**/*.*"],
...config
};
}
}
function getRuleTesterClassFromLegacyRuleTester() {
return class RuleTesterForV8 extends eslint.RuleTester {
constructor(options) {
var _a;
const defineRules = [];
const { processor, ...others } = options;
super(
convertConfigToRc(others, {
defineRule(...args) {
defineRules.push(args);
}
})
);
__publicField(this, "defaultProcessor");
for (const args of defineRules) {
(_a = this.linter) == null ? void 0 : _a.defineRule(...args);
}
this.defaultProcessor = processor;
}
run(name, rule, tests) {
super.run(name, rule, {
valid: (tests.valid || []).map(
(test) => typeof test === "string" ? test : convert(test, this.defaultProcessor)
),
invalid: (tests.invalid || []).map(
(test) => convert(test, this.defaultProcessor)
)
});
}
};
function convert(config, defaultProcessor) {
const { processor: configProcessor, ...otherConfig } = config;
const processor = configProcessor || defaultProcessor;
const converted = convertConfigToRc(otherConfig);
if (!processor) {
return converted;
}
return {
...converted,
filename: convertOptionToLegacy(processor, config.filename, config)
};
}
}
export { getRuleIdPrefix, getRuleTester };

View file

@ -0,0 +1,193 @@
import * as eslint from 'eslint';
import * as semver from 'semver';
import { createRequire } from 'module';
function safeRequire(name) {
try {
return createRequire(`${process.cwd()}/__placeholder__.js`)(name);
} catch {
return void 0;
}
}
function safeRequireResolve(name) {
try {
return createRequire(`${process.cwd()}/__placeholder__.js`).resolve(name);
} catch {
return name;
}
}
const builtInGlobals = /* @__PURE__ */ new Map([
[
3,
Object.entries({
Array: false,
Boolean: false,
constructor: false,
Date: false,
decodeURI: false,
decodeURIComponent: false,
encodeURI: false,
encodeURIComponent: false,
Error: false,
escape: false,
eval: false,
EvalError: false,
Function: false,
hasOwnProperty: false,
Infinity: false,
isFinite: false,
isNaN: false,
isPrototypeOf: false,
Math: false,
NaN: false,
Number: false,
Object: false,
parseFloat: false,
parseInt: false,
propertyIsEnumerable: false,
RangeError: false,
ReferenceError: false,
RegExp: false,
String: false,
SyntaxError: false,
toLocaleString: false,
toString: false,
TypeError: false,
undefined: false,
unescape: false,
URIError: false,
valueOf: false
})
],
[
5,
Object.entries({
JSON: false
})
],
[
2015,
Object.entries({
ArrayBuffer: false,
DataView: false,
Float32Array: false,
Float64Array: false,
Int16Array: false,
Int32Array: false,
Int8Array: false,
Intl: false,
Map: false,
Promise: false,
Proxy: false,
Reflect: false,
Set: false,
Symbol: false,
Uint16Array: false,
Uint32Array: false,
Uint8Array: false,
Uint8ClampedArray: false,
WeakMap: false,
WeakSet: false
})
],
[
2017,
Object.entries({
Atomics: false,
SharedArrayBuffer: false
})
],
[
2020,
Object.entries({
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
globalThis: false
})
],
[
2021,
Object.entries({
AggregateError: false,
FinalizationRegistry: false,
WeakRef: false
})
]
]);
function convertConfigToRc(config, linter) {
var _a, _b;
if (Array.isArray(config)) {
throw new Error("Array config is not supported.");
}
const {
languageOptions: originalLanguageOptions,
plugins,
...newConfig
} = config;
if (originalLanguageOptions) {
const {
parser,
globals,
parserOptions,
ecmaVersion,
sourceType,
...languageOptions
} = originalLanguageOptions;
newConfig.parserOptions = {
...!ecmaVersion || ecmaVersion === "latest" ? { ecmaVersion: getLatestEcmaVersion() } : { ecmaVersion },
...sourceType ? { sourceType } : { sourceType: "module" },
...languageOptions,
...parserOptions,
...newConfig.parserOptions
};
const resolvedEcmaVersion = newConfig.parserOptions.ecmaVersion;
newConfig.globals = {
...Object.fromEntries(
[...builtInGlobals.entries()].flatMap(
([version, editionGlobals]) => resolvedEcmaVersion < version ? [] : editionGlobals
)
),
...newConfig.globals
};
if (globals) {
newConfig.globals = {
...globals,
...newConfig.globals
};
}
if (parser && !newConfig.parser) {
const parserName = getParserName(parser);
newConfig.parser = parserName;
(_a = linter == null ? void 0 : linter.defineParser) == null ? void 0 : _a.call(linter, parserName, parser);
}
}
if (plugins) {
for (const [pluginName, plugin] of Object.entries(plugins)) {
for (const [ruleName, rule] of Object.entries(plugin.rules || {})) {
(_b = linter == null ? void 0 : linter.defineRule) == null ? void 0 : _b.call(linter, `${pluginName}/${ruleName}`, rule);
}
}
}
newConfig.env = {
es6: true,
...newConfig.env
};
return newConfig;
}
function getParserName(parser) {
var _a;
const name = ((_a = parser.meta) == null ? void 0 : _a.name) || parser.name;
if (name === "typescript-eslint/parser") {
return safeRequireResolve("@typescript-eslint/parser");
} else if (name == null && parser === safeRequire("@typescript-eslint/parser"))
return safeRequireResolve("@typescript-eslint/parser");
return safeRequireResolve(name);
}
function getLatestEcmaVersion() {
const eslintVersion = eslint.Linter.version;
return semver.gte(eslintVersion, "8.0.0") ? "latest" : semver.gte(eslintVersion, "7.8.0") ? 2021 : semver.gte(eslintVersion, "6.2.0") ? 2020 : semver.gte(eslintVersion, "5.0.0") ? 2019 : 2018;
}
export { convertConfigToRc as c };

View file

@ -0,0 +1,9 @@
function getUnsupported() {
try {
return require("eslint/use-at-your-own-risk");
} catch {
return {};
}
}
export { getUnsupported as g };

View file

@ -0,0 +1,210 @@
'use strict';
const eslint = require('eslint');
const semver = require('semver');
const module$1 = require('module');
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
const n = Object.create(null);
if (e) {
for (const k in e) {
n[k] = e[k];
}
}
n.default = e;
return n;
}
const eslint__namespace = /*#__PURE__*/_interopNamespaceCompat(eslint);
const semver__namespace = /*#__PURE__*/_interopNamespaceCompat(semver);
function safeRequire(name) {
try {
return module$1.createRequire(`${process.cwd()}/__placeholder__.js`)(name);
} catch {
return void 0;
}
}
function safeRequireResolve(name) {
try {
return module$1.createRequire(`${process.cwd()}/__placeholder__.js`).resolve(name);
} catch {
return name;
}
}
const builtInGlobals = /* @__PURE__ */ new Map([
[
3,
Object.entries({
Array: false,
Boolean: false,
constructor: false,
Date: false,
decodeURI: false,
decodeURIComponent: false,
encodeURI: false,
encodeURIComponent: false,
Error: false,
escape: false,
eval: false,
EvalError: false,
Function: false,
hasOwnProperty: false,
Infinity: false,
isFinite: false,
isNaN: false,
isPrototypeOf: false,
Math: false,
NaN: false,
Number: false,
Object: false,
parseFloat: false,
parseInt: false,
propertyIsEnumerable: false,
RangeError: false,
ReferenceError: false,
RegExp: false,
String: false,
SyntaxError: false,
toLocaleString: false,
toString: false,
TypeError: false,
undefined: false,
unescape: false,
URIError: false,
valueOf: false
})
],
[
5,
Object.entries({
JSON: false
})
],
[
2015,
Object.entries({
ArrayBuffer: false,
DataView: false,
Float32Array: false,
Float64Array: false,
Int16Array: false,
Int32Array: false,
Int8Array: false,
Intl: false,
Map: false,
Promise: false,
Proxy: false,
Reflect: false,
Set: false,
Symbol: false,
Uint16Array: false,
Uint32Array: false,
Uint8Array: false,
Uint8ClampedArray: false,
WeakMap: false,
WeakSet: false
})
],
[
2017,
Object.entries({
Atomics: false,
SharedArrayBuffer: false
})
],
[
2020,
Object.entries({
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
globalThis: false
})
],
[
2021,
Object.entries({
AggregateError: false,
FinalizationRegistry: false,
WeakRef: false
})
]
]);
function convertConfigToRc(config, linter) {
var _a, _b;
if (Array.isArray(config)) {
throw new Error("Array config is not supported.");
}
const {
languageOptions: originalLanguageOptions,
plugins,
...newConfig
} = config;
if (originalLanguageOptions) {
const {
parser,
globals,
parserOptions,
ecmaVersion,
sourceType,
...languageOptions
} = originalLanguageOptions;
newConfig.parserOptions = {
...!ecmaVersion || ecmaVersion === "latest" ? { ecmaVersion: getLatestEcmaVersion() } : { ecmaVersion },
...sourceType ? { sourceType } : { sourceType: "module" },
...languageOptions,
...parserOptions,
...newConfig.parserOptions
};
const resolvedEcmaVersion = newConfig.parserOptions.ecmaVersion;
newConfig.globals = {
...Object.fromEntries(
[...builtInGlobals.entries()].flatMap(
([version, editionGlobals]) => resolvedEcmaVersion < version ? [] : editionGlobals
)
),
...newConfig.globals
};
if (globals) {
newConfig.globals = {
...globals,
...newConfig.globals
};
}
if (parser && !newConfig.parser) {
const parserName = getParserName(parser);
newConfig.parser = parserName;
(_a = linter == null ? void 0 : linter.defineParser) == null ? void 0 : _a.call(linter, parserName, parser);
}
}
if (plugins) {
for (const [pluginName, plugin] of Object.entries(plugins)) {
for (const [ruleName, rule] of Object.entries(plugin.rules || {})) {
(_b = linter == null ? void 0 : linter.defineRule) == null ? void 0 : _b.call(linter, `${pluginName}/${ruleName}`, rule);
}
}
}
newConfig.env = {
es6: true,
...newConfig.env
};
return newConfig;
}
function getParserName(parser) {
var _a;
const name = ((_a = parser.meta) == null ? void 0 : _a.name) || parser.name;
if (name === "typescript-eslint/parser") {
return safeRequireResolve("@typescript-eslint/parser");
} else if (name == null && parser === safeRequire("@typescript-eslint/parser"))
return safeRequireResolve("@typescript-eslint/parser");
return safeRequireResolve(name);
}
function getLatestEcmaVersion() {
const eslintVersion = eslint__namespace.Linter.version;
return semver__namespace.gte(eslintVersion, "8.0.0") ? "latest" : semver__namespace.gte(eslintVersion, "7.8.0") ? 2021 : semver__namespace.gte(eslintVersion, "6.2.0") ? 2020 : semver__namespace.gte(eslintVersion, "5.0.0") ? 2019 : 2018;
}
exports.convertConfigToRc = convertConfigToRc;

View file

@ -0,0 +1,54 @@
'use strict';
function convertOptionToLegacy(processor, verifyOption, config) {
var _a;
if (processor == null)
return verifyOption;
if (typeof processor === "string") {
return convertOptionToLegacy(
findProcessor(processor, config),
verifyOption,
config
);
}
const filename = (_a = typeof verifyOption === "string" ? verifyOption : verifyOption == null ? void 0 : verifyOption.filename) != null ? _a : "<input>";
const preprocess = function(code) {
var _a2;
const result = (_a2 = processor.preprocess) == null ? void 0 : _a2.call(processor, code, filename);
return result ? result : [code];
};
const postprocess = function(messages) {
var _a2;
const result = (_a2 = processor.postprocess) == null ? void 0 : _a2.call(processor, messages, filename);
return result ? result : messages[0];
};
if (verifyOption == null) {
return { preprocess, postprocess };
}
if (typeof verifyOption === "string") {
return { filename: verifyOption, preprocess, postprocess };
}
return { ...verifyOption, preprocess, postprocess };
}
function findProcessor(processor, config) {
var _a, _b;
let pluginName, processorName;
const splitted = processor.split("/")[0];
if (splitted.length === 2) {
pluginName = splitted[0];
processorName = splitted[1];
} else if (splitted.length === 3 && splitted[0].startsWith("@")) {
pluginName = `${splitted[0]}/${splitted[1]}`;
processorName = splitted[2];
} else {
throw new Error(`Could not resolve processor: ${processor}`);
}
const plugin = (_a = config.plugins) == null ? void 0 : _a[pluginName];
const resolved = (_b = plugin == null ? void 0 : plugin.processors) == null ? void 0 : _b[processorName];
if (!resolved) {
throw new Error(`Could not resolve processor: ${processor}`);
}
return resolved;
}
exports.convertOptionToLegacy = convertOptionToLegacy;

View file

@ -0,0 +1,11 @@
'use strict';
function getUnsupported() {
try {
return require("eslint/use-at-your-own-risk");
} catch {
return {};
}
}
exports.getUnsupported = getUnsupported;

View file

@ -0,0 +1,52 @@
function convertOptionToLegacy(processor, verifyOption, config) {
var _a;
if (processor == null)
return verifyOption;
if (typeof processor === "string") {
return convertOptionToLegacy(
findProcessor(processor, config),
verifyOption,
config
);
}
const filename = (_a = typeof verifyOption === "string" ? verifyOption : verifyOption == null ? void 0 : verifyOption.filename) != null ? _a : "<input>";
const preprocess = function(code) {
var _a2;
const result = (_a2 = processor.preprocess) == null ? void 0 : _a2.call(processor, code, filename);
return result ? result : [code];
};
const postprocess = function(messages) {
var _a2;
const result = (_a2 = processor.postprocess) == null ? void 0 : _a2.call(processor, messages, filename);
return result ? result : messages[0];
};
if (verifyOption == null) {
return { preprocess, postprocess };
}
if (typeof verifyOption === "string") {
return { filename: verifyOption, preprocess, postprocess };
}
return { ...verifyOption, preprocess, postprocess };
}
function findProcessor(processor, config) {
var _a, _b;
let pluginName, processorName;
const splitted = processor.split("/")[0];
if (splitted.length === 2) {
pluginName = splitted[0];
processorName = splitted[1];
} else if (splitted.length === 3 && splitted[0].startsWith("@")) {
pluginName = `${splitted[0]}/${splitted[1]}`;
processorName = splitted[2];
} else {
throw new Error(`Could not resolve processor: ${processor}`);
}
const plugin = (_a = config.plugins) == null ? void 0 : _a[pluginName];
const resolved = (_b = plugin == null ? void 0 : plugin.processors) == null ? void 0 : _b[processorName];
if (!resolved) {
throw new Error(`Could not resolve processor: ${processor}`);
}
return resolved;
}
export { convertOptionToLegacy as c };