📄 flat-config-schema¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 10 |
| 🧱 Classes | 4 |
| 📦 Imports | 3 |
| 📊 Variables & Constants | 12 |
| 📐 Interfaces | 1 |
| 📑 Type Aliases | 3 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/rule-tester/src/utils/flat-config-schema.ts
📦 Imports¶
| Name | Source |
|---|---|
Processor |
@typescript-eslint/utils/ts-eslint |
SharedConfig |
@typescript-eslint/utils/ts-eslint |
normalizeSeverityToNumber |
./severity |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
ruleSeverities |
Map<SharedConfig.RuleLevel, SharedCon... |
const | new Map<SharedConfig.RuleLevel, SharedConfig.Severity>([ ['error', 2], ['off'... |
✗ |
booleanSchema |
{ merge: string; validate: string; } |
const | { merge: 'replace', validate: 'boolean', } satisfies ObjectPropertySchema |
✗ |
ALLOWED_SEVERITIES |
Set<string \| number> |
const | new Set([0, 1, 2, 'error', 'off', 'warn']) |
✗ |
disableDirectiveSeveritySchema |
ObjectPropertySchema<SharedConfig.Rul... |
const | { merge( first: boolean \| SharedConfig.RuleLevel \| undefined, second: boole... |
✗ |
deepObjectAssignSchema |
{ merge<First extends ObjectLike, Sec... |
const | { merge<First extends ObjectLike, Second extends ObjectLike>( first = {} as F... |
✗ |
languageOptionsSchema |
{ merge(first?: ObjectLike, second?: ... |
const | { merge(first: ObjectLike = {}, second: ObjectLike = {}): object { const resu... |
✗ |
languageSchema |
ObjectPropertySchema<PluginMemberName> |
const | { merge: 'replace', validate: assertIsPluginMemberName, } |
✗ |
pluginsSchema |
{ merge(first?: ObjectLike, second?: ... |
const | { merge(first: ObjectLike = {}, second: ObjectLike = {}): object { const keys... |
✗ |
processorSchema |
ObjectPropertySchema<Processor.LooseP... |
const | { merge: 'replace', validate(value: unknown) { if (typeof value === 'string')... |
✗ |
rulesSchema |
{ merge(first?: ConfigRules, second?:... |
const | { merge(first: ConfigRules = {}, second: ConfigRules = {}): ConfigRules { con... |
✗ |
eslintrcKeys |
string[] |
const | [ 'env', 'extends', 'globals', 'ignorePatterns', 'noInlineConfig', 'overrides... |
✗ |
flatConfigSchema |
{ language: ObjectPropertySchema<${s...| const |, // Original ESLint schemas from flat-config-sc...` |
✓ |
Functions¶
isNonNullObject(value: unknown): boolean¶
Check if a value is a non-null object.
Parameters:
valueany: The value to check.
Returns: undefined
true if the value is a non-null object.
Raw JSDoc
Internal Comments:
Code
isNonArrayObject(value: unknown): boolean¶
Check if a value is a non-null non-array object.
Parameters:
valueany: The value to check.
Returns: undefined
true if the value is a non-null non-array object.
Raw JSDoc
Calls:
isNonNullObjectArray.isArray
Code
deepMerge(first: First, second: Second, mergeMap: Map<First | Second, Map<First | Second,…): First & Second¶
Deeply merges two non-array objects.
Parameters:
firstany: The base object.secondany: The overrides object.mergeMapany: Maps the combination of first and second arguments to a merged result.
Returns: undefined
An object with properties from both first and second.
Raw JSDoc
Calls:
mergeMap.getsecondMergeMap.getmergeMap.setsecondMergeMap.setObject.keysObject.prototype.propertyIsEnumerable.callisNonArrayObjectdeepMerge
Internal Comments:
// If this combination of first and second arguments has been already visited, return the previously created result.
/*
* First create a result object where properties from the second object
* overwrite properties from the first. This sets up a baseline to use
* later rather than needing to inspect and change every property
* individually.
*/ (x2)
// Store the pending result for this combination of first and second arguments. (x4)
// avoid hairy edge case
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion (x4)
Code
function deepMerge<First extends object, Second extends object>(
first: First,
second: Second,
mergeMap = new Map<First | Second, Map<First | Second, First & Second>>(),
): First & Second {
let secondMergeMap = mergeMap.get(first);
if (secondMergeMap) {
const result = secondMergeMap.get(second);
if (result) {
// If this combination of first and second arguments has been already visited, return the previously created result.
return result;
}
} else {
secondMergeMap = new Map();
mergeMap.set(first, secondMergeMap);
}
/*
* First create a result object where properties from the second object
* overwrite properties from the first. This sets up a baseline to use
* later rather than needing to inspect and change every property
* individually.
*/
const result = {
...first,
...second,
} as First & ObjectLike & Second;
delete (result as ObjectLike).__proto__; // don't merge own property "__proto__"
// Store the pending result for this combination of first and second arguments.
secondMergeMap.set(second, result);
for (const key of Object.keys(second)) {
// avoid hairy edge case
if (
key === '__proto__' ||
!Object.prototype.propertyIsEnumerable.call(first, key)
) {
continue;
}
const firstValue = (first as ObjectLike)[key] as object | undefined;
const secondValue = (second as ObjectLike)[key] as object | undefined;
if (isNonArrayObject(firstValue) && isNonArrayObject(secondValue)) {
(result as ObjectLike)[key] = deepMerge(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
firstValue!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
secondValue!,
mergeMap,
);
// eslint-disable-next-line @typescript-eslint/internal/eqeq-nullish
} else if (secondValue === undefined) {
(result as ObjectLike)[key] = firstValue;
}
}
return result;
}
normalizeRuleOptions(ruleOptions: SharedConfig.RuleLevel | SharedConfig.R…): SharedConfig.RuleLevelAndOptions¶
Normalizes the rule options config for a given rule by ensuring that it is an array and that the first item is 0, 1, or 2.
Parameters:
ruleOptionsany: The rule options config.
Returns: undefined
An array of rule options.
Raw JSDoc
Calls:
Array.isArrayruleSeverities.getstructuredClone
Code
function normalizeRuleOptions(
ruleOptions: SharedConfig.RuleLevel | SharedConfig.RuleLevelAndOptions,
): SharedConfig.RuleLevelAndOptions {
const finalOptions = Array.isArray(ruleOptions)
? [...ruleOptions]
: [ruleOptions];
finalOptions[0] = ruleSeverities.get(
finalOptions[0] as SharedConfig.RuleLevel,
);
return structuredClone(finalOptions as SharedConfig.RuleLevelAndOptions);
}
hasMethod(object: Record<string, unknown>): boolean¶
Determines if an object has any methods.
Parameters:
objectany: The object to check.
Returns: undefined
true if the object has any methods.
Raw JSDoc
Calls:
Object.keys
Code
assertIsRuleOptions(ruleId: string, value: unknown): void¶
Validates that a value is a valid rule options entry.
Parameters:
ruleIdany: Rule name being configured.valueany: The value to check.
Throws:
InvalidRuleOptionsError: If the value isn't a valid rule options.
Raw JSDoc
Calls:
Array.isArray
Code
assertIsRuleSeverity(ruleId: string, value: unknown): void¶
Validates that a value is valid rule severity.
Parameters:
ruleIdany: Rule name being configured.valueany: The value to check.
Throws:
InvalidRuleSeverityError: If the value isn't a valid rule severity.
Raw JSDoc
Calls:
ruleSeverities.get
Code
assertIsPluginMemberName(value: unknown): asserts value is PluginMemberName¶
Validates that a given string is the form pluginName/objectName.
Parameters:
valueany: The string to check.
Raw JSDoc
Calls:
/[@\w$-]+(?:\/[\w$-]+)+$/iu.test
Internal Comments:
Code
function assertIsPluginMemberName(
value: unknown,
): asserts value is PluginMemberName {
if (typeof value !== 'string' || !/[@\w$-]+(?:\/[\w$-]+)+$/iu.test(value)) {
throw new TypeError(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Expected string in the form "pluginName/objectName" but found "${value}".`,
);
}
}
assertIsObject(value: unknown): void¶
Validates that a value is an object.
Parameters:
valueany: The value to check.
Calls:
isNonNullObject
Code
createEslintrcErrorSchema(key: string): ObjectPropertySchema¶
Creates a schema that always throws an error. Useful for warning about eslintrc-style keys.
Parameters:
keyany: The eslintrc key to create a schema for.
Raw JSDoc
Code
Classes¶
InvalidRuleOptionsError¶
The error type when a rule's options are configured with an invalid type.
Extends: Error
Class Code
class InvalidRuleOptionsError extends Error {
readonly messageData: { ruleId: string; value: unknown };
readonly messageTemplate: string;
constructor(ruleId: string, value: unknown) {
super(
`Key "${ruleId}": Expected severity of "off", 0, "warn", 1, "error", or 2.`,
);
this.messageTemplate = 'invalid-rule-options';
this.messageData = { ruleId, value };
}
}
InvalidRuleSeverityError¶
The error type when a rule's severity is invalid.
Extends: Error
Class Code
class InvalidRuleSeverityError extends Error {
readonly messageData: { ruleId: string; value: unknown };
readonly messageTemplate: string;
constructor(ruleId: string, value: unknown) {
super(
`Key "${ruleId}": Expected severity of "off", 0, "warn", 1, "error", or 2.`,
);
this.messageTemplate = 'invalid-rule-severity';
this.messageData = { ruleId, value };
}
}
IncompatibleKeyError¶
The error type when there's an eslintrc-style options in a flat config.
Extends: Error
Class Code
class IncompatibleKeyError extends Error {
readonly messageData: { key: string };
readonly messageTemplate: string;
/**
* @param key The invalid key.
*/
constructor(key: string) {
super(
'This appears to be in eslintrc format rather than flat config format.',
);
this.messageTemplate = 'eslintrc-incompat';
this.messageData = { key };
}
}
IncompatiblePluginsError¶
The error type when there's an eslintrc-style plugins array found.
Extends: Error
Class Code
class IncompatiblePluginsError extends Error {
readonly messageData: { plugins: string[] };
readonly messageTemplate: string;
constructor(plugins: string[]) {
super(
'This appears to be in eslintrc format (array of strings) rather than flat config format (object).',
);
this.messageTemplate = 'eslintrc-plugins';
this.messageData = { plugins };
}
}
Interfaces¶
ObjectPropertySchema<T = unknown>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
merge |
string \| ((a: T, b: T) => T) |
✗ | not shown |
validate |
string \| ((value: unknown) => asserts value is T) |
✗ | not shown |
Type Aliases¶
PluginMemberName¶
ObjectLike¶
ConfigRules¶
Generated by Syntax Scribe