routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
import { TSESTree } from '@typescript-eslint/types'
|
||||
import { SortingNodeWithOverloadSignatureImplementation } from './overload-signature-group.js'
|
||||
import { NewlinesBetweenValueGetter } from '../get-newlines-between-errors.js'
|
||||
import { NewlinesBetweenOption } from '../../types/common-groups-options.js'
|
||||
/**
|
||||
* Newlines between value getter for overload signatures.
|
||||
*
|
||||
* @param newlinesBetweenOverloadSignatures - Newlines between overload
|
||||
* signatures option value.
|
||||
* @returns NewlinesBetween option value.
|
||||
*/
|
||||
export declare function buildOverloadSignatureNewlinesBetweenValueGetter<
|
||||
T extends TSESTree.Node,
|
||||
>(
|
||||
newlinesBetweenOverloadSignatures: NewlinesBetweenOption,
|
||||
): NewlinesBetweenValueGetter<SortingNodeWithOverloadSignatureImplementation<T>>
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Newlines between value getter for overload signatures.
|
||||
*
|
||||
* @param newlinesBetweenOverloadSignatures - Newlines between overload
|
||||
* signatures option value.
|
||||
* @returns NewlinesBetween option value.
|
||||
*/
|
||||
function buildOverloadSignatureNewlinesBetweenValueGetter(
|
||||
newlinesBetweenOverloadSignatures,
|
||||
) {
|
||||
return ({ computedNewlinesBetween, right, left }) => {
|
||||
if (
|
||||
left.overloadSignatureImplementation &&
|
||||
left.overloadSignatureImplementation ===
|
||||
right.overloadSignatureImplementation
|
||||
) {
|
||||
return newlinesBetweenOverloadSignatures
|
||||
}
|
||||
return computedNewlinesBetween
|
||||
}
|
||||
}
|
||||
export { buildOverloadSignatureNewlinesBetweenValueGetter }
|
||||
Generated
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
import { TSESTree } from '@typescript-eslint/utils'
|
||||
import { SortingNode } from '../../types/sorting-node.js'
|
||||
export type SortingNodeWithOverloadSignatureImplementation<
|
||||
T extends TSESTree.Node,
|
||||
> = OverloadSignatureImplementation<T> & SortingNode
|
||||
export interface OverloadSignatureImplementation<T extends TSESTree.Node> {
|
||||
overloadSignatureImplementation: null | T
|
||||
}
|
||||
/**
|
||||
* Represents a group of overload signatures along with their implementation.
|
||||
*/
|
||||
export declare class OverloadSignatureGroup<T extends TSESTree.Node> {
|
||||
readonly implementation: T
|
||||
private readonly _overloadSignatures
|
||||
constructor({
|
||||
overloadSignatures,
|
||||
implementation,
|
||||
}: {
|
||||
overloadSignatures: T[]
|
||||
implementation: T
|
||||
})
|
||||
doesNodeBelongToGroup(node: TSESTree.Node): boolean
|
||||
}
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Represents a group of overload signatures along with their implementation.
|
||||
*/
|
||||
var OverloadSignatureGroup = class {
|
||||
implementation
|
||||
_overloadSignatures
|
||||
constructor({ overloadSignatures, implementation }) {
|
||||
this._overloadSignatures = new Set(overloadSignatures)
|
||||
this.implementation = implementation
|
||||
}
|
||||
doesNodeBelongToGroup(node) {
|
||||
return this._overloadSignatures.has(node) || this.implementation === node
|
||||
}
|
||||
}
|
||||
export { OverloadSignatureGroup }
|
||||
Generated
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
import { TSESTree } from '@typescript-eslint/types'
|
||||
import {
|
||||
OverloadSignatureImplementation,
|
||||
OverloadSignatureGroup,
|
||||
} from './overload-signature-group.js'
|
||||
import { SortingNode } from '../../types/sorting-node.js'
|
||||
/**
|
||||
* Populate sorting node groups with their corresponding overload signature
|
||||
* implementations fields if they exist.
|
||||
*
|
||||
* @param params - The parameters.
|
||||
* @param params.overloadSignatureGroups - List of overload signature groups.
|
||||
* @param params.sortingNodeGroups - List of sorting node groups.
|
||||
* @returns The populated sorting node groups.
|
||||
*/
|
||||
export declare function populateSortingNodeGroupsWithOverloadSignature<
|
||||
OverloadSignatureNode extends TSESTree.Node,
|
||||
T extends SortingNode,
|
||||
>({
|
||||
overloadSignatureGroups,
|
||||
sortingNodeGroups,
|
||||
}: {
|
||||
overloadSignatureGroups: OverloadSignatureGroup<OverloadSignatureNode>[]
|
||||
sortingNodeGroups: T[][]
|
||||
}): (OverloadSignatureImplementation<OverloadSignatureNode> & T)[][]
|
||||
Generated
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
import { buildSortingNodeByNodeMap } from '../build-sorting-node-by-node-map.js'
|
||||
/**
|
||||
* Populate sorting node groups with their corresponding overload signature
|
||||
* implementations fields if they exist.
|
||||
*
|
||||
* @param params - The parameters.
|
||||
* @param params.overloadSignatureGroups - List of overload signature groups.
|
||||
* @param params.sortingNodeGroups - List of sorting node groups.
|
||||
* @returns The populated sorting node groups.
|
||||
*/
|
||||
function populateSortingNodeGroupsWithOverloadSignature({
|
||||
overloadSignatureGroups,
|
||||
sortingNodeGroups,
|
||||
}) {
|
||||
return sortingNodeGroups.map(sortingNodes =>
|
||||
populateSortingNodeGroupWithOverloadSignature({
|
||||
overloadSignatureGroups,
|
||||
sortingNodes,
|
||||
}),
|
||||
)
|
||||
}
|
||||
function buildUpdatedSortingNode({
|
||||
overloadSignatureGroups,
|
||||
sortingNodeByNode,
|
||||
sortingNode,
|
||||
}) {
|
||||
let overloadSignatureImplementation = computeOverloadSignatureImplementation({
|
||||
overloadSignatureGroups,
|
||||
node: sortingNode.node,
|
||||
})
|
||||
if (!overloadSignatureImplementation) {
|
||||
return {
|
||||
...sortingNode,
|
||||
overloadSignatureImplementation: null,
|
||||
}
|
||||
}
|
||||
let implementationSortingNode = sortingNodeByNode.get(
|
||||
overloadSignatureImplementation,
|
||||
)
|
||||
/* v8 ignore if -- @preserve Unsure how we can reach that case */
|
||||
if (!implementationSortingNode) {
|
||||
return {
|
||||
...sortingNode,
|
||||
overloadSignatureImplementation: null,
|
||||
}
|
||||
}
|
||||
let {
|
||||
addSafetySemicolonWhenInline,
|
||||
isEslintDisabled,
|
||||
node,
|
||||
...relevantImplementationSortingNodeFields
|
||||
} = implementationSortingNode
|
||||
return {
|
||||
...sortingNode,
|
||||
...relevantImplementationSortingNodeFields,
|
||||
overloadSignatureImplementation,
|
||||
}
|
||||
}
|
||||
function populateSortingNodeGroupWithOverloadSignature({
|
||||
overloadSignatureGroups,
|
||||
sortingNodes,
|
||||
}) {
|
||||
let sortingNodeByNode = buildSortingNodeByNodeMap(sortingNodes)
|
||||
return sortingNodes.map(sortingNode =>
|
||||
buildUpdatedSortingNode({
|
||||
overloadSignatureGroups,
|
||||
sortingNodeByNode,
|
||||
sortingNode,
|
||||
}),
|
||||
)
|
||||
}
|
||||
function computeOverloadSignatureImplementation({
|
||||
overloadSignatureGroups,
|
||||
node,
|
||||
}) {
|
||||
let matchingOverloadSignature = overloadSignatureGroups.find(
|
||||
overloadSignatureGroup =>
|
||||
overloadSignatureGroup.doesNodeBelongToGroup(node),
|
||||
)
|
||||
if (!matchingOverloadSignature) {
|
||||
return null
|
||||
}
|
||||
return matchingOverloadSignature.implementation
|
||||
}
|
||||
export { populateSortingNodeGroupsWithOverloadSignature }
|
||||
Reference in New Issue
Block a user