repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
eslint-stylistic
github_2023
eslint-stylistic
typescript
hasCommentsInParensOfParams
function hasCommentsInParensOfParams(node: Tree.ArrowFunctionExpression, openingParen: Token) { return sourceCode.commentsExistBetween(openingParen, getClosingParenOfParams(node)!) }
/** * Determines whether the given arrow function has comments inside parens of parameters. * It is assumed that the given arrow function has parens of parameters. * @param node `ArrowFunctionExpression` node. * @param openingParen Opening paren of parameters. * @returns `true` if the function ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-parens/arrow-parens._js_.ts#L101-L103
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
hasUnexpectedTokensBeforeOpeningParen
function hasUnexpectedTokensBeforeOpeningParen(node: Tree.ArrowFunctionExpression, openingParen: Token) { const expectedCount = node.async ? 1 : 0 return sourceCode.getFirstToken(node, { skip: expectedCount }) !== openingParen }
/** * Determines whether the given arrow function has unexpected tokens before opening paren of parameters, * in which case it will be assumed that the existing parens of parameters are necessary. * Only tokens within the range of the arrow function (tokens that are part of the arrow function) are taken ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-parens/arrow-parens._js_.ts#L114-L118
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getTokens
function getTokens(node: Tree.ArrowFunctionExpression) { const arrow = sourceCode.getTokenBefore(node.body, isArrowToken)! return { before: sourceCode.getTokenBefore(arrow)!, arrow, after: sourceCode.getTokenAfter(arrow)!, } }
/** * Get tokens of arrow(`=>`) and before/after arrow. * @param node The arrow function node. * @returns Tokens of arrow and before/after arrow. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-spacing/arrow-spacing._js_.ts#L63-L71
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
countSpaces
function countSpaces(tokens: { before: Token, arrow: Token, after: Token }) { const before = tokens.arrow.range[0] - tokens.before.range[1] const after = tokens.after.range[0] - tokens.arrow.range[1] return { before, after } }
/** * Count spaces before/after arrow(`=>`) token. * @param tokens Tokens before/after arrow. * @returns count of space before/after arrow. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-spacing/arrow-spacing._js_.ts#L78-L83
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
spaces
function spaces(node: Tree.ArrowFunctionExpression) { const tokens = getTokens(node) const countSpace = countSpaces(tokens) if (rule.before) { // should be space(s) before arrow if (countSpace.before === 0) { context.report({ node: tokens.before, mess...
/** * Determines whether space(s) before after arrow(`=>`) is satisfy rule. * if before/after value is `true`, there should be space(s). * if before/after value is `false`, there should be no space. * @param node The arrow function node. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/arrow-spacing/arrow-spacing._js_.ts#L91-L144
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getOpenBrace
function getOpenBrace(node: Tree.BlockStatement | Tree.StaticBlock | Tree.SwitchStatement): Token { if (node.type === 'SwitchStatement') { if (node.cases.length > 0) return sourceCode.getTokenBefore(node.cases[0])! return sourceCode.getLastToken(node, 1)! } if (node.type ==...
/** * Gets the open brace token from a given node. * @param node A BlockStatement/StaticBlock/SwitchStatement node to get. * @returns The token of the open brace. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/block-spacing/block-spacing._js_.ts#L43-L56
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isValid
function isValid(left: Token, right: Token): boolean { return ( !isTokenOnSameLine(left, right) || sourceCode.isSpaceBetween(left, right) === always ) }
/** * Checks whether or not: * - given tokens are on same line. * - there is/isn't a space between given tokens. * @param left A token to check. * @param right The token which is next to `left`. * When the option is `"always"`, `true` if there are one or more spaces between given to...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/block-spacing/block-spacing._js_.ts#L68-L73
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingInsideBraces
function checkSpacingInsideBraces(node: Tree.BlockStatement | Tree.StaticBlock | Tree.SwitchStatement): void { // Gets braces and the first/last token of content. const openBrace = getOpenBrace(node) const closeBrace = sourceCode.getLastToken(node)! const firstToken = sourceCode.getTokenAfter(op...
/** * Checks and reports invalid spacing style inside braces. * @param node A BlockStatement/StaticBlock/SwitchStatement node to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/block-spacing/block-spacing._js_.ts#L79-L152
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getOpenBrace
function getOpenBrace( node: Tree.TSEnumDeclaration, ): Tree.PunctuatorToken { // guaranteed for enums // This is the only change made here from the base rule return sourceCode.getFirstToken(node, { filter: token => token.type === AST_TOKEN_TYPES.Punctuator && token.value =...
/** * Gets the open brace token from a given node. * @returns The token of the open brace. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/block-spacing/block-spacing._ts_.ts#L35-L44
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isValid
function isValid(left: Tree.Token, right: Tree.Token): boolean { return ( !isTokenOnSameLine(left, right) || sourceCode.isSpaceBetween!(left, right) === always ) }
/** * Checks whether or not: * - given tokens are on same line. * - there is/isn't a space between given tokens. * @param left A token to check. * @param right The token which is next to `left`. * @returns * When the option is `"always"`, `true` if there are one or more spaces ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/block-spacing/block-spacing._ts_.ts#L57-L62
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingInsideBraces
function checkSpacingInsideBraces(node: Tree.TSEnumDeclaration): void { // Gets braces and the first/last token of content. const openBrace = getOpenBrace(node) const closeBrace = sourceCode.getLastToken(node)! const firstToken = sourceCode.getTokenAfter(openBrace, { includeComments: tru...
/** * Checks and reports invalid spacing style inside braces. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/block-spacing/block-spacing._ts_.ts#L67-L144
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
removeNewlineBetween
function removeNewlineBetween(firstToken: Token, secondToken: Token): ReportFixFunction | null { const textRange = [firstToken.range[1], secondToken.range[0]] as const const textBetween = sourceCode.text.slice(textRange[0], textRange[1]) // Don't do a fix if there is a comment between the tokens ...
/** * Fixes a place where a newline unexpectedly appears * @param firstToken The token before the unexpected newline * @param secondToken The token after the unexpected newline * @returns A fixer function to remove the newlines between the tokens */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/brace-style/brace-style._js_.ts#L64-L73
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCurlyPair
function validateCurlyPair(openingCurly: Token, closingCurly: Token): void { const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(openingCurly)! const tokenAfterOpeningCurly = sourceCode.getTokenAfter(openingCurly)! const tokenBeforeClosingCurly = sourceCode.getTokenBefore(closingCurly)! co...
/** * Validates a pair of curly brackets based on the user's config * @param openingCurly The opening curly bracket * @param closingCurly The closing curly bracket */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/brace-style/brace-style._js_.ts#L80-L120
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCurlyBeforeKeyword
function validateCurlyBeforeKeyword(curlyToken: Token): void { const keywordToken = sourceCode.getTokenAfter(curlyToken)! if (style === '1tbs' && !isTokenOnSameLine(curlyToken, keywordToken)) { context.report({ node: curlyToken, messageId: 'nextLineClose', fix: removeN...
/** * Validates the location of a token that appears before a keyword (e.g. a newline before `else`) * @param curlyToken The closing curly token. This is assumed to precede a keyword token (such as `else` or `finally`). */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/brace-style/brace-style._js_.ts#L126-L144
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCurlyPair
function validateCurlyPair( openingCurlyToken: Tree.Token, closingCurlyToken: Tree.Token, ): void { if ( allowSingleLine && isTokenOnSameLine(openingCurlyToken, closingCurlyToken) ) { return } const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(open...
/** * Checks a pair of curly brackets based on the user's config */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/brace-style/brace-style._ts_.ts#L36-L108
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isTrailingCommaAllowed
function isTrailingCommaAllowed(lastItem: ItemASTNode) { return lastItem.type !== 'RestElement' }
/** * Checks whether or not a trailing comma is allowed in a given node. * If the `lastItem` is `RestElement` or `RestProperty`, it disallows trailing commas. * @param lastItem The node of the last element in the given node. * @returns `true` if a trailing comma is allowed. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L54-L56
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
normalizeOptions
function normalizeOptions(optionValue: RuleOptions[0], ecmaVersion: EcmaVersion | 'latest' | undefined) { if (typeof optionValue === 'string') { return { arrays: optionValue, objects: optionValue, imports: optionValue, exports: optionValue, functions: !ecmaVersion || ecmaVersion === ...
/** * Normalize option value. * @param optionValue The 1st option value to normalize. * @param ecmaVersion The normalized ECMAScript version. * @returns The normalized option value. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L64-L89
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
last
function last<T>(array: T[] | undefined): T | null { if (!array) return null return array[array.length - 1] ?? null }
/** * Returns the last element of an array * @param array The input array * @returns The last element */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L168-L172
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getTrailingToken
function getTrailingToken(info: VerifyInfo) { switch (info.node.type) { case 'ObjectExpression': case 'ArrayExpression': case 'CallExpression': case 'NewExpression': case 'ImportExpression': return sourceCode.getLastToken(info.node, 1) default: { ...
/** * Gets the trailing comma token of the given node. * If the trailing comma does not exist, this returns the token which is * the insertion point of the trailing comma token. * @param info The information to verify. * @returns The trailing comma token or the insertion point. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L181-L201
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isMultiline
function isMultiline(info: VerifyInfo) { const lastItem = info.lastItem if (!lastItem) return false const penultimateToken = getTrailingToken(info) if (!penultimateToken) return false const lastToken = sourceCode.getTokenAfter(penultimateToken) if (!lastToken) ...
/** * Checks whether or not a given node is multiline. * This rule handles a given node as multiline when the closing parenthesis * and the last element are not on the same line. * @param info The information to verify. * @returns `true` if the node is multiline. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L210-L223
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
forbidTrailingComma
function forbidTrailingComma(info: VerifyInfo) { const lastItem = info.lastItem if (!lastItem) return const trailingToken = getTrailingToken(info) if (trailingToken && isCommaToken(trailingToken)) { context.report({ node: lastItem, loc: trailingToken.loc, ...
/** * Reports a trailing comma if it exists. * @param info The information to verify. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L229-L257
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
forceTrailingComma
function forceTrailingComma(info: VerifyInfo) { const lastItem = info.lastItem if (!lastItem) return if (!isTrailingCommaAllowed(lastItem)) { forbidTrailingComma(info) return } const trailingToken = getTrailingToken(info) if (!trailingToken || trailingToke...
/** * Reports the last element of a given node if it does not have a trailing * comma. * * If a given node is `ArrayPattern` which has `RestElement`, the trailing * comma is disallowed, so report if it exists. * @param info The information to verify. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L267-L308
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
forceTrailingCommaIfMultiline
function forceTrailingCommaIfMultiline(info: VerifyInfo) { if (isMultiline(info)) forceTrailingComma(info) else forbidTrailingComma(info) }
/** * If a given node is multiline, reports the last element of a given node * when it does not have a trailing comma. * Otherwise, reports a trailing comma if it exists. * @param info The information to verify. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L316-L321
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
allowTrailingCommaIfMultiline
function allowTrailingCommaIfMultiline(info: VerifyInfo) { if (!isMultiline(info)) forbidTrailingComma(info) }
/** * Only if a given node is not multiline, reports the last element of a given node * when it does not have a trailing comma. * Otherwise, reports a trailing comma if it exists. * @param info The information to verify. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-dangle/comma-dangle._js_.ts#L329-L332
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
report
function report(node: ASTNode | Token, loc: 'before' | 'after', otherNode: ASTNode | Token) { context.report({ node, fix(fixer) { if (options[loc]) { if (loc === 'before') return fixer.insertTextBefore(node, ' ') return fixer.insertTextAfter(node, '...
/** * Reports a spacing error with an appropriate message. * @param node The binary expression node to report. * @param loc Is the error "before" or "after" the comma? * @param otherNode The node at the left or right of `node` * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-spacing/comma-spacing._js_.ts#L65-L94
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addNullElementsToIgnoreList
function addNullElementsToIgnoreList(node: Tree.ArrayExpression | Tree.ArrayPattern) { let previousToken = sourceCode.getFirstToken(node)! node.elements.forEach((element) => { let token: Token if (element === null) { token = sourceCode.getTokenAfter(previousToken)! if ...
/** * Adds null elements of the given ArrayExpression or ArrayPattern node to the ignore list. * @param node An ArrayExpression or ArrayPattern node. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-spacing/comma-spacing._js_.ts#L100-L118
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addNullElementsToIgnoreList
function addNullElementsToIgnoreList( node: Tree.ArrayExpression | Tree.ArrayPattern, ): void { let previousToken = sourceCode.getFirstToken(node) for (const element of node.elements) { let token: Tree.Token | null if (element == null) { token = sourceCode.getTokenAfter(p...
/** * Adds null elements of the ArrayExpression or ArrayPattern node to the ignore list * @param node node to evaluate */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-spacing/comma-spacing._ts_.ts#L60-L77
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addTypeParametersTrailingCommaToIgnoreList
function addTypeParametersTrailingCommaToIgnoreList( node: Tree.TSTypeParameterDeclaration, ): void { const paramLength = node.params.length if (paramLength) { const param = node.params[paramLength - 1] const afterToken = sourceCode.getTokenAfter(param) if (afterToken && is...
/** * Adds type parameters trailing comma token to the ignore list * @param node node to evaluate */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-spacing/comma-spacing._ts_.ts#L83-L93
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCommaSpacing
function validateCommaSpacing( commaToken: Tree.PunctuatorToken, prevToken: Tree.Token | null, nextToken: Tree.Token | null, ): void { if ( prevToken && isTokenOnSameLine(prevToken, commaToken) && spaceBefore !== sourceCode.isSpaceBetween(prevToken, commaToken) ...
/** * Validates the spacing around a comma token. * @param commaToken The token representing the comma * @param prevToken The last token before the comma * @param nextToken The first token after the comma */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-spacing/comma-spacing._ts_.ts#L101-L151
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getReplacedText
function getReplacedText(styleType: string, text: string): string { switch (styleType) { case 'between': return `,${text.replace(LINEBREAK_MATCHER, '')}` case 'first': return `${text},` case 'last': return `,${text}` default: return '' ...
/** * Modified text based on the style * @param styleType Style type * @param text Source code text * @returns modified text * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L78-L92
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getFixerFunction
function getFixerFunction(styleType: string, tokenBeforeComma: Token, commaToken: Token, tokenAfterComma: Tree.Token) { const text = sourceCode.text.slice(tokenBeforeComma.range[1], commaToken.range[0]) + sourceCode.text.slice(commaToken.range[1], tokenAfterComma.range[0]) ...
/** * Determines the fixer function for a given style. * @param styleType comma style * @param tokenBeforeComma The token before the comma token. * @param commaToken The token representing the comma. * @param tokenAfterComma The token after the comma token. * @returns Fixer function *...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L103-L112
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCommaItemSpacing
function validateCommaItemSpacing(tokenBeforeComma: Token, commaToken: Token, tokenAfterComma: Tree.Token): void { // if single line if (isTokenOnSameLine(commaToken, tokenAfterComma) && isTokenOnSameLine(tokenBeforeComma, commaToken)) { // do nothing. } else if (!isTokenOnSame...
/** * Validates the spacing around single items in lists. * @param tokenBeforeComma The token before the comma token. * @param commaToken The token representing the comma. * @param tokenAfterComma The token after the comma token. * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L121-L157
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
extractCommaTokens
function extractCommaTokens(node: NodeType, items: (ASTNode | null)[]): Token[] { if (items.length === 0) { // If there are no items, return an empty array. return [] } const definedItems = items.filter((item): item is ASTNode => Boolean(item)) if (definedItems.length === 0) { ...
/** * Extracts the comma tokens from the node and its items. * @param node The node to extract the comma tokens from. * @param items The child nodes. * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L165-L224
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateComma
function validateComma(node: NodeType, items: (ASTNode | null)[]): void { const commaTokens = extractCommaTokens(node, items) commaTokens.forEach((commaToken) => { const tokenBeforeComma = sourceCode.getTokenBefore(commaToken)! const tokenAfterComma = sourceCode.getTokenAfter(commaToken)! ...
/** * Checks the comma placement with regards to a declaration/property/element * @param node The binary expression node to check * @param items The child nodes. * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L232-L262
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateObjectProperties
function validateObjectProperties(node: Tree.ObjectExpression | Tree.ObjectPattern) { validateComma(node, node.properties) }
/** Checks the comma placement in object properties. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L414-L416
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateArrayElements
function validateArrayElements(node: Tree.ArrayExpression | Tree.ArrayPattern) { validateComma(node, node.elements) }
/** Checks the comma placement in array elements. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L418-L420
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateFunctionParams
function validateFunctionParams( node: Tree.FunctionDeclaration | Tree.FunctionExpression | Tree.ArrowFunctionExpression | Tree.TSDeclareFunction | Tree.TSFunctionType | Tree.TSConstructorType | Tree.TSEmptyBodyFunctionExpression | Tree.TSMethodSignature ...
/** Checks the comma placement in function parameters. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L422-L435
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCallArguments
function validateCallArguments(node: Tree.CallExpression | Tree.NewExpression) { validateComma(node, node.arguments) }
/** Checks the comma placement in call arguments. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L437-L439
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
visitImportAttributes
function visitImportAttributes(node: Tree.ImportDeclaration | Tree.ExportAllDeclaration | Tree.ExportNamedDeclaration) { if (!node.attributes) // The old parser's AST does not have attributes. return validateComma(node, node.attributes) }
/** Checks the comma placement in import attributes. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L441-L446
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
visitClassImplements
function visitClassImplements(node: Tree.ClassDeclaration | Tree.ClassExpression) { if (!node.implements) // The js parser's AST does not have implements. return validateComma(node, node.implements) }
/** Checks the comma placement in TypeScript class implements. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L449-L454
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
visitMembers
function visitMembers(node: Tree.TSEnumBody | Tree.TSTypeLiteral) { validateComma(node, node.members) }
/** Checks the comma placement in TypeScript enum/literal members. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L456-L458
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateTypeParams
function validateTypeParams( node: Tree.TSTypeParameterDeclaration | Tree.TSTypeParameterInstantiation, ) { validateComma(node, node.params) }
/** Checks the comma placement in type parameters. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/comma-style/comma-style._js_.ts#L460-L465
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNoBeginningSpace
function reportNoBeginningSpace(node: ASTNode, token: Tree.Token, tokenAfter: Tree.Token): void { context.report({ node, loc: { start: token.loc.end, end: tokenAfter.loc.start }, messageId: 'unexpectedSpaceAfter', data: { tokenValue: token.value, }, fix(fi...
/** * Reports that there shouldn't be a space after the first token * @param node The node to report in the event of an error. * @param token The token to use for the report. * @param tokenAfter The token after `token`. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/computed-property-spacing/computed-property-spacing._js_.ts#L60-L72
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNoEndingSpace
function reportNoEndingSpace(node: ASTNode, token: Tree.Token, tokenBefore: Tree.Token): void { context.report({ node, loc: { start: tokenBefore.loc.end, end: token.loc.start }, messageId: 'unexpectedSpaceBefore', data: { tokenValue: token.value, }, fix(fi...
/** * Reports that there shouldn't be a space before the last token * @param node The node to report in the event of an error. * @param token The token to use for the report. * @param tokenBefore The token before `token`. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/computed-property-spacing/computed-property-spacing._js_.ts#L80-L92
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportRequiredBeginningSpace
function reportRequiredBeginningSpace(node: ASTNode, token: Tree.Token): void { context.report({ node, loc: token.loc, messageId: 'missingSpaceAfter', data: { tokenValue: token.value, }, fix(fixer) { return fixer.insertTextAfter(token, ' ') ...
/** * Reports that there should be a space after the first token * @param node The node to report in the event of an error. * @param token The token to use for the report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/computed-property-spacing/computed-property-spacing._js_.ts#L99-L111
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportRequiredEndingSpace
function reportRequiredEndingSpace(node: ASTNode, token: Tree.Token): void { context.report({ node, loc: token.loc, messageId: 'missingSpaceBefore', data: { tokenValue: token.value, }, fix(fixer) { return fixer.insertTextBefore(token, ' ') ...
/** * Reports that there should be a space before the last token * @param node The node to report in the event of an error. * @param token The token to use for the report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/computed-property-spacing/computed-property-spacing._js_.ts#L118-L130
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacing
function checkSpacing<T extends NodeType, K = ExtractNodeKeys<T>>(propertyName: K) { return function (node: NodeType) { if (!node.computed) return const property = node[propertyName as ExtractNodeKeys<typeof node>] as ASTNode const before = sourceCode.getTokenBefore(property, i...
/** * Returns a function that checks the spacing of a node on the property name * that was passed in. * @param propertyName The property on the node to check for spacing * @returns A function that will check spacing on a node */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/computed-property-spacing/computed-property-spacing._js_.ts#L142-L176
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
check
function check( node: | Tree.BlockStatement | Tree.ClassBody | Tree.StaticBlock | Tree.SwitchStatement | Tree.TSEnumBody | Tree.TSInterfaceBody | Tree.TSModuleBlock, specialization: keyof typeof Specialization, ) { const options = normalizedO...
/** * Reports a given node if it violated this rule. * @param node A node to check. This is an ObjectExpression, ObjectPattern, ImportDeclaration, ExportNamedDeclaration, TSTypeLiteral or TSInterfaceBody node. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/curly-newline/curly-newline._plus_.ts#L158-L289
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkDotLocation
function checkDotLocation(node: Tree.MemberExpression) { const property = node.property const dotToken = sourceCode.getTokenBefore(property) if (onObject && dotToken) { // `obj` expression can be parenthesized, but those paren tokens are not a part of the `obj` node. const tokenBefore...
/** * Reports if the dot between object and property is on the correct location. * @param node The `MemberExpression` node. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/dot-location/dot-location._js_.ts#L48-L83
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkNode
function checkNode(node: Tree.MemberExpression) { if (node.type === 'MemberExpression' && !node.computed) checkDotLocation(node) }
/** * Checks the spacing of the dot within a member expression. * @param node The node to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/dot-location/dot-location._js_.ts#L89-L92
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkArguments
function checkArguments(argumentNodes: Tree.CallExpressionArgument[], checker: Checker) { for (let i = 1; i < argumentNodes.length; i++) { const argumentNode = argumentNodes[i - 1] const prevArgToken = sourceCode.getLastToken(argumentNode)! const currentArgToken = sourceCode.getFirstToken(...
/** * Check all arguments for line breaks in the CallExpression * @param argumentNodes arguments to evaluate * @param checker selected checker * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-call-argument-newline/function-call-argument-newline._js_.ts#L65-L90
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
check
function check(argumentNodes: Tree.CallExpressionArgument[]) { if (argumentNodes.length < 2) return const option = context.options[0] || 'always' if (option === 'never') { checkArguments(argumentNodes, checkers.unexpected) } else if (option === 'always') { checkAr...
/** * Check if open space is present in a function name * @param argumentNodes arguments to evaluate * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-call-argument-newline/function-call-argument-newline._js_.ts#L97-L118
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacing
function checkSpacing(node: Tree.CallExpression | Tree.NewExpression | Tree.ImportExpression, leftToken: Token, rightToken: Token) { const textBetweenTokens = text.slice(leftToken.range[1], rightToken.range[0]).replace(/\/\*.*?\*\//gu, '') const hasWhitespace = /\s/u.test(textBetweenTokens) const hasN...
/** * Check if open space is present in a function name * @param node node to evaluate * @param leftToken The last token of the callee. This may be the closing parenthesis that encloses the callee. * @param rightToken Tha first token of the arguments. this is the opening parenthesis that encloses th...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-call-spacing/function-call-spacing._js_.ts#L79-L192
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacing
function checkSpacing( node: Tree.CallExpression | Tree.NewExpression | Tree.ImportExpression, leftToken: Tree.Token, rightToken: Tree.Token, ): void { const isOptionalCall = isOptionalCallExpression(node) const textBetweenTokens = text .slice(leftToken.range[1], rightToken.ra...
/** * Check if open space is present in a function name * @param node node to evaluate * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-call-spacing/function-call-spacing._ts_.ts#L88-L211
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
shouldHaveNewlines
function shouldHaveNewlines(elements: Tree.CallExpressionArgument[] | Tree.Parameter[], hasLeftNewline: boolean) { if (multilineArgumentsOption && elements.length === 1) return hasLeftNewline if (multilineOption || multilineArgumentsOption) return elements.some((element, index) => index !==...
/** * Determines whether there should be newlines inside function parens * @param elements The arguments or parameters in the list * @param hasLeftNewline `true` if the left paren has a newline in the current code. * @returns `true` if there should be newlines inside the function parens */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-paren-newline/function-paren-newline._js_.ts#L79-L90
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateParens
function validateParens(parens: ParensPair, elements: Tree.CallExpressionArgument[] | Tree.Parameter[]) { const leftParen = parens.leftParen const rightParen = parens.rightParen const tokenAfterLeftParen = sourceCode.getTokenAfter(leftParen)! const tokenBeforeRightParen = sourceCode.getTokenBefo...
/** * Validates parens * @param parens An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token * @param elements The arguments or parameters in the list */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-paren-newline/function-paren-newline._js_.ts#L97-L147
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateArguments
function validateArguments(parens: ParensPair, elements: Tree.CallExpressionArgument[] | Tree.Parameter[]) { const leftParen = parens.leftParen const tokenAfterLeftParen = sourceCode.getTokenAfter(leftParen) const hasLeftNewline = !isTokenOnSameLine(leftParen, tokenAfterLeftParen) const needsNew...
/** * Validates a list of arguments or parameters * @param parens An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token * @param elements The arguments or parameters in the list */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-paren-newline/function-paren-newline._js_.ts#L154-L173
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getParenTokens
function getParenTokens( node: | Tree.ArrowFunctionExpression | Tree.CallExpression | Tree.FunctionDeclaration | Tree.FunctionExpression | Tree.ImportExpression | Tree.NewExpression, ): ParensPair | null { const isOpeningParenTokenOutsideTypeParameter = ()...
/** * Gets the left paren and right paren tokens of a node. * @param node The node with parens * @throws {TypeError} Unexpected node type. * @returns An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token. * Can also return `null` if an expression h...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/function-paren-newline/function-paren-newline._js_.ts#L183-L265
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
optionToDefinition
function optionToDefinition(option: NonNullable<RuleOptions[0]> | undefined, defaults: { before: boolean, after: boolean }) { if (!option) return defaults return typeof option === 'string' ? optionDefinitions[option as keyof typeof optionDefinitions] : Object.assign({}, defaults, op...
/** * Returns resolved option definitions based on an option and defaults * @param option The option object or string value * @param defaults The defaults to use if options are not present * @returns the resolved object definition */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/generator-star-spacing/generator-star-spacing._js_.ts#L85-L92
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isStarToken
function isStarToken(token: Token) { return token.value === '*' && token.type === 'Punctuator' }
/** * Checks if the given token is a star token or not. * @param token The token to check. * @returns `true` if the token is a star token. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/generator-star-spacing/generator-star-spacing._js_.ts#L111-L113
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getStarToken
function getStarToken(node: Tree.FunctionDeclaration | Tree.FunctionExpression) { return sourceCode.getFirstToken( (('method' in node.parent && node.parent.method) || node.parent.type === 'MethodDefinition') ? node.parent : node, isStarToken, ) }
/** * Gets the generator star token of the given function node. * @param node The function node to get. * @returns Found star token. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/generator-star-spacing/generator-star-spacing._js_.ts#L120-L125
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
capitalize
function capitalize(str: string) { return str[0].toUpperCase() + str.slice(1) }
/** * capitalize a given string. * @param str the given string. * @returns the capitalized string. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/generator-star-spacing/generator-star-spacing._js_.ts#L132-L134
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacing
function checkSpacing(kind: keyof typeof modes, side: 'before' | 'after', leftToken: Token, rightToken: Token) { if (!!(rightToken.range[0] - leftToken.range[1]) !== modes[kind][side]) { const after = leftToken.value === '*' const spaceRequired = modes[kind][side] const node = after ? left...
/** * Checks the spacing between two tokens before or after the star token. * @param kind Either "named", "anonymous", or "method" * @param side Either "before" or "after". * @param leftToken `function` keyword token if side is "before", or * star token if side is "after". * @param rig...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/generator-star-spacing/generator-star-spacing._js_.ts#L145-L166
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkFunction
function checkFunction(node: Tree.FunctionDeclaration | Tree.FunctionExpression) { if (!node.generator) return const starToken = getStarToken(node)! const prevToken = sourceCode.getTokenBefore(starToken)! const nextToken = sourceCode.getTokenAfter(starToken)! let kind: keyof type...
/** * Enforces the spacing around the star if node is a generator function. * @param node A function expression or declaration node. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/generator-star-spacing/generator-star-spacing._js_.ts#L172-L192
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateExpression
function validateExpression(node: Tree.ArrowFunctionExpression) { if (node.body.type === 'BlockStatement') return const arrowToken = sourceCode.getTokenBefore(node.body, isNotOpeningParenToken)! const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken)! if (arrowToken.loc.end.line ...
/** * Validates the location of an arrow function body * @param node The arrow function body */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/implicit-arrow-linebreak/implicit-arrow-linebreak._js_.ts#L43-L69
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isTypeKeywordOfNode
function isTypeKeywordOfNode(typeToken: Tree.IdentifierToken, node: ASTNode): boolean { while (node.parent) { node = node.parent if ( node.type === 'TSTypeAliasDeclaration' && context.sourceCode.getTokenBefore(node.id) === typeToken ) { return true } ...
/** * Determines if a given type token is the keyword for a node's type alias declaration. * @param typeToken The identifier token representing the type keyword. * @param node The AST node to check, typically a descendant of the type alias declaration. * @returns `true` if the type token is the keyw...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent-binary-ops/indent-binary-ops._plus_.ts#L93-L104
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
IndexMap.constructor
constructor(maxKey: number) { // Initializing the array with the maximum expected size avoids dynamic reallocations that could degrade performance. this._values = new Array(maxKey + 1) }
/** * Creates an empty map * @param maxKey The maximum key */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L130-L133
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
IndexMap.insert
insert(key: number, value: T) { this._values[key] = value }
/** * Inserts an entry into the map. * @param key The entry's key * @param value The entry's value */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L140-L142
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
IndexMap.findLastNotAfter
findLastNotAfter(key: number): T | undefined { const values = this._values for (let index = key; index >= 0; index--) { const value = values[index] if (value) return value } }
/** * Finds the value of the entry with the largest key less than or equal to the provided key * @param key The provided key * @returns The value of the found entry, or undefined if no such entry exists. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L149-L158
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
IndexMap.deleteRange
deleteRange(start: number, end: number) { this._values.fill(undefined, start, end) }
/** * Deletes all of the keys in the interval [start, end) * @param start The start of the range * @param end The end of the range */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L165-L167
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
TokenInfo.constructor
constructor(sourceCode: SourceCode) { this.sourceCode = sourceCode this.firstTokensByLineNumber = new Map() const tokens = sourceCode.tokensAndComments for (let i = 0; i < tokens.length; i++) { const token = tokens[i] if (!this.firstTokensByLineNumber.has(token.loc.start.line)) thi...
/** * @param sourceCode A SourceCode object */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L180-L194
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
TokenInfo.getFirstTokenOfLine
getFirstTokenOfLine(token: Token | ASTNode) { return this.firstTokensByLineNumber.get(token.loc.start.line) }
/** * Gets the first token on a given token's line * @param token a node or token * @returns The first token on the given line */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L201-L203
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
TokenInfo.isFirstTokenOfLine
isFirstTokenOfLine(token: Token | ASTNode) { return this.getFirstTokenOfLine(token) === token }
/** * Determines whether a token is the first token in its line * @param token The token * @returns `true` if the token is the first on its line */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L210-L212
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
TokenInfo.getTokenIndent
getTokenIndent(token: Token) { return this.sourceCode.text.slice(token.range[0] - token.loc.start.column, token.range[0]) }
/** * Get the actual indent of a token * @param token Token to examine. This should be the first token on its line. * @returns The indentation characters that precede the token */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L219-L221
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.constructor
constructor(tokenInfo: TokenInfo, indentSize: number, indentType: string, maxIndex: number) { this._tokenInfo = tokenInfo this._indentSize = indentSize this._indentType = indentType this._indexMap = new IndexMap(maxIndex) this._indexMap.insert(0, { offset: 0, from: null, force: false }) }
/** * @param tokenInfo a TokenInfo instance * @param indentSize The desired size of each indentation level * @param indentType The indentation character * @param maxIndex The maximum end index of any token */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L242-L249
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.matchOffsetOf
matchOffsetOf(baseToken: Token, offsetToken: Token) { /** * lockedFirstTokens is a map from a token whose indentation is controlled by the "first" option to * the token that it depends on. For example, with the `ArrayExpression: first` option, the first * token of each element in the array after the ...
/** * Sets the offset column of token B to match the offset column of token A. * - **WARNING**: This matches a *column*, even if baseToken is not the first token on its line. In * most cases, `setDesiredOffset` should be used instead. * @param baseToken The first token * @param offsetToken The second tok...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L262-L271
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.setDesiredOffset
setDesiredOffset(token: Token | undefined | null, fromToken: Token | undefined | null, offset: Offset): void { if (token) this.setDesiredOffsets(token.range, fromToken, offset) }
/** * Sets the desired offset of a token. * * This uses a line-based offset collapsing behavior to handle tokens on the same line. * For example, consider the following two cases: * * ( * [ * bar * ] * ) * * ([ * bar * ]) * * Based on the first case, i...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L328-L331
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.setDesiredOffsets
setDesiredOffsets(range: [number, number], fromToken: Token | null | undefined, offset: Offset, force = false) { /** * Offset ranges are stored as a collection of nodes, where each node maps a numeric key to an offset * descriptor. The tree for the example above would have the following nodes: * ...
/** * Sets the desired offset of all tokens in a range * It's common for node listeners in this file to need to apply the same offset to a large, contiguous range of tokens. * Moreover, the offset of any given token is usually updated multiple times (roughly once for each node that contains * it). This mean...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L357-L399
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.getDesiredIndent
getDesiredIndent(token: Token) { if (!this._desiredIndentCache.has(token)) { if (this._ignoredTokens.has(token)) { /** * If the token is ignored, use the actual indent of the token as the desired indent. * This ensures that no errors are reported for this token. */ t...
/** * Gets the desired indent of a token * @param token The token * @returns The desired indent of the token */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L406-L445
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.ignoreToken
ignoreToken(token: Token) { if (this._tokenInfo.isFirstTokenOfLine(token)) this._ignoredTokens.add(token) }
/** * Ignores a token, preventing it from being reported. * @param token The token */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L451-L454
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
OffsetStorage.getFirstDependency
getFirstDependency(token: Token) { return this._getOffsetDescriptor(token).from }
/** * Gets the first token that the given token's indentation is dependent on * @param token The token * @returns The token that the given token depends on, or `null` if the given token is at the top level */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L461-L463
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
createErrorMessageData
function createErrorMessageData(expectedAmount: number, actualSpaces: number, actualTabs: number) { const expectedStatement = `${expectedAmount} ${indentType}${expectedAmount === 1 ? '' : 's'}` // e.g. "2 tabs" const foundSpacesWord = `space${actualSpaces === 1 ? '' : 's'}` // e.g. "space" const found...
/** * Creates an error message for a line, given the expected/actual indentation. * @param expectedAmount The expected amount of indentation characters for this line * @param actualSpaces The actual number of indentation spaces that were found on this line * @param actualTabs The actual number of in...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L708-L731
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
report
function report(token: Token, neededIndent: string) { const actualIndent = Array.from(tokenInfo.getTokenIndent(token)) const numSpaces = actualIndent.filter(char => char === ' ').length const numTabs = actualIndent.filter(char => char === '\t').length context.report({ node: token, ...
/** * Reports a given indent violation * @param token Token violating the indent rule * @param neededIndent Expected indentation string */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L738-L758
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateTokenIndent
function validateTokenIndent(token: Token, desiredIndent: string): boolean { const indentation = tokenInfo.getTokenIndent(token) return indentation === desiredIndent }
/** * Checks if a token's indentation is correct * @param token Token to examine * @param desiredIndent Desired indentation of the string * @returns `true` if the token's indentation is correct */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L766-L770
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isOuterIIFE
function isOuterIIFE(node: ASTNode) { /** * Verify that the node is an IIFE */ if (!node.parent || node.parent.type !== 'CallExpression' || node.parent.callee !== node) return false /** * Navigate legal ancestors to determine whether this IIFE is outer. * A "legal ...
/** * Check to see if the node is a file level IIFE * @param node The function node to check. * @returns True if the node is the outer IIFE */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L777-L802
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
countTrailingLinebreaks
function countTrailingLinebreaks(string: string) { const trailingWhitespace = string.match(/\s*$/u)![0] const linebreakMatches = trailingWhitespace.match(createGlobalLinebreakMatcher()) return linebreakMatches === null ? 0 : linebreakMatches.length }
/** * Counts the number of linebreaks that follow the last non-whitespace character in a string * @param string The string to check * @returns The number of JavaScript linebreaks that follow the last non-whitespace character, * or the total number of linebreaks if the string is all whitespace. ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L810-L815
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addElementListIndent
function addElementListIndent(elements: (ASTNode | null)[], startToken: Token, endToken: Token, offset: number | string) { /** * Gets the first token of a given element, including surrounding parentheses. * @param element A node in the `elements` list * @returns The first token of this elemen...
/** * Check indentation for lists of elements (arrays, objects, function params) * @param elements List of elements that should be offset * @param startToken The start token of the list that element should be aligned against, e.g. '[' * @param endToken The end token of the list, e.g. ']' * @par...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L824-L885
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getFirstToken
function getFirstToken(element: ASTNode) { let token: Token = sourceCode.getTokenBefore(element)! while (isOpeningParenToken(token) && token !== startToken) token = sourceCode.getTokenBefore(token)! return sourceCode.getTokenAfter(token)! }
/** * Gets the first token of a given element, including surrounding parentheses. * @param element A node in the `elements` list * @returns The first token of this element */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L830-L837
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addBlocklessNodeIndent
function addBlocklessNodeIndent(node: ASTNode) { if (node.type !== 'BlockStatement') { const lastParentToken = sourceCode.getTokenBefore(node, isNotOpeningParenToken)! let firstBodyToken = sourceCode.getFirstToken(node)! let lastBodyToken = sourceCode.getLastToken(node)! while ( ...
/** * Check and decide whether to check for indentation for blockless nodes * Scenarios are for or while statements without braces around them * @param node node to examine */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L892-L909
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addFunctionCallIndent
function addFunctionCallIndent(node: Tree.CallExpression | Tree.NewExpression) { let openingParen if (node.arguments.length) openingParen = sourceCode.getFirstTokenBetween(node.callee, node.arguments[0], isOpeningParenToken)! else openingParen = sourceCode.getLastToken(node, 1)! ...
/** * Checks the indentation for nodes that are like function calls (`CallExpression` and `NewExpression`) * @param node A CallExpression or NewExpression node */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L915-L954
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addParensIndent
function addParensIndent(tokens: Token[]) { const parenStack = [] const parenPairs = [] for (let i = 0; i < tokens.length; i++) { const nextToken = tokens[i] if (isOpeningParenToken(nextToken)) parenStack.push(nextToken) else if (isClosingParenToken(nextToken)) ...
/** * Checks the indentation of parenthesized values, given a list of tokens in a program * @param tokens A list of tokens */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L960-L989
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
ignoreNode
function ignoreNode(node: ASTNode) { const unknownNodeTokens = new Set(sourceCode.getTokens(node, { includeComments: true })) unknownNodeTokens.forEach((token) => { if (!unknownNodeTokens.has(offsets.getFirstDependency(token))) { const firstTokenOfLine = tokenInfo.getFirstTokenOfLine(toke...
/** * Ignore all tokens within an unknown node whose offset do not depend * on another token's offset within the unknown node * @param node Unknown Node */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L996-L1009
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isOnFirstLineOfStatement
function isOnFirstLineOfStatement(token: Token, leafNode: ASTNode): boolean { let node = leafNode while (node.parent && !node.parent.type.endsWith('Statement') && !node.parent.type.endsWith('Declaration')) node = node.parent node = node.parent! return !node || node.loc.start.line === ...
/** * Check whether the given token is on the first line of a statement. * @param token The token to check. * @param leafNode The expression node that the token belongs directly. * @returns `true` if the token is on the first line of a statement. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L1017-L1026
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
hasBlankLinesBetween
function hasBlankLinesBetween(firstToken: Token, secondToken: Token): boolean { const firstTokenLine = firstToken.loc.end.line const secondTokenLine = secondToken.loc.start.line if (firstTokenLine === secondTokenLine || firstTokenLine === secondTokenLine - 1) return false for (let line...
/** * Check whether there are any blank (whitespace-only) lines between * two tokens on separate lines. * @param firstToken The first token. * @param secondToken The second token. * @returns `true` if the tokens are on separate lines and * there exists a blank line between them, `false` ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L1036-L1049
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
addToIgnoredNodes
function addToIgnoredNodes(node: ASTNode): void { ignoredNodes.add(node) ignoredNodeFirstTokens.add(sourceCode.getFirstToken(node)!) }
/** * Ignores a node * @param node The node to ignore */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L1788-L1791
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getNodeIndent
function getNodeIndent(node: ASTNode | Token, byLastLine = false, excludeCommas = false) { let src = context.sourceCode.getText(node, node.loc.start.column) const lines = src.split('\n') if (byLastLine) src = lines[lines.length - 1] else src = lines[0] const skip = exclude...
// JSXText
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._js_.ts#L1799-L1817
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
nonTsTestCase
function nonTsTestCase(example: TemplateStringsArray): string { return ['// Non-TS Test Case', example].join('\n') }
/** * Marks a test case as a plain javascript case which should be indented the same */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._ts_.test.ts#L11-L13
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
TSPropertySignatureToProperty
function TSPropertySignatureToProperty( node: | Tree.TSEnumMember | Tree.TSPropertySignature | Tree.TypeElement, type: | AST_NODE_TYPES.Property | AST_NODE_TYPES.PropertyDefinition = AST_NODE_TYPES.Property, ): ASTNode | null { const base = { // inde...
/** * Converts from a TSPropertySignature to a Property * @param node a TSPropertySignature node * @param [type] the type to give the new node * @returns a Property node */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/indent/indent._ts_.ts#L129-L174
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getExpectedLocation
function getExpectedLocation(tokens: Tokens) { let location // Is always after the opening tag if there is no props if (typeof tokens.lastProp === 'undefined') location = 'after-tag' // Is always after the last prop if this one is on the same line as the opening bracket else if (to...
/** * Get expected location for the closing bracket * @param tokens Locations of the opening bracket, closing bracket and last prop * @return Expected location for the closing bracket */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-closing-bracket-location/jsx-closing-bracket-location._jsx_.ts#L120-L133
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getCorrectColumn
function getCorrectColumn(tokens: Tokens, expectedLocation: string | false | undefined): number | null { switch (expectedLocation) { case 'props-aligned': return (tokens.lastProp as LastPropLocation).column case 'tag-aligned': return tokens.opening.column case 'line-ali...
/** * Get the correct 0-indexed column for the closing bracket, given the * expected location. * @param tokens Locations of the opening bracket, closing bracket and last prop * @param expectedLocation Expected location for the closing bracket * @return The correct column for the closing bracket...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-closing-bracket-location/jsx-closing-bracket-location._jsx_.ts#L142-L153
481d54b6521b8705570132424c78d320dec57610