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
hasCorrectLocation
function hasCorrectLocation(tokens: Tokens, expectedLocation: string | false | undefined): boolean { switch (expectedLocation) { case 'after-tag': return tokens.tag.line === tokens.closing.line case 'after-props': return (tokens.lastProp as LastPropLocation).lastLine === tokens...
/** * Check if the closing bracket is correctly located * @param tokens Locations of the opening bracket, closing bracket and last prop * @param expectedLocation Expected location for the closing bracket * @return True if the closing bracket is correctly located, false if not */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-closing-bracket-location/jsx-closing-bracket-location._jsx_.ts#L161-L176
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getIndentation
function getIndentation(tokens: Tokens, expectedLocation: string, correctColumn: number): string { const newColumn = correctColumn || 0 let indentation let spaces: string[] = [] switch (expectedLocation) { case 'props-aligned': indentation = /^\s*/.exec(context.sourceCode.lines...
/** * Get the characters used for indentation on the line to be matched * @param tokens Locations of the opening bracket, closing bracket and last prop * @param expectedLocation Expected location for the closing bracket * @param [correctColumn] Expected column for the closing bracket. Default to 0 ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-closing-bracket-location/jsx-closing-bracket-location._jsx_.ts#L185-L205
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getTokensLocations
function getTokensLocations(node: Tree.JSXOpeningElement) { const sourceCode = context.sourceCode const opening = sourceCode.getFirstToken(node)!.loc.start const closing = sourceCode.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start const tag = sourceCode.getFirstToken(node.name)!.loc.s...
/** * Get the locations of the opening bracket, closing bracket, last prop, and * start of opening line. * @param node The node to check * @return Locations of the opening bracket, closing bracket, last * prop and start of opening line. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-closing-bracket-location/jsx-closing-bracket-location._jsx_.ts#L224-L257
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportUnnecessaryCurly
function reportUnnecessaryCurly(JSXExpressionNode: Tree.JSXExpressionContainer) { context.report({ messageId: 'unnecessaryCurly', node: JSXExpressionNode, fix(fixer) { const expression = JSXExpressionNode.expression as Tree.TemplateLiteral | Tree.StringLiteral let text...
/** * Report and fix an unnecessary curly brace violation on a node * @param JSXExpressionNode - The AST node with an unnecessary JSX expression */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-brace-presence/jsx-curly-brace-presence._jsx_.ts#L159-L194
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
lintUnnecessaryCurly
function lintUnnecessaryCurly(JSXExpressionNode: Tree.JSXExpressionContainer) { const expression = (JSXExpressionNode as Tree.JSXExpression).expression as Tree.Literal | Tree.JSXText | Tree.TemplateLiteral const expressionType = expression.type const sourceCode = context.sourceCode // Curly bra...
// Bail out if there is any character that needs to be escaped in JSX
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-brace-presence/jsx-curly-brace-presence._jsx_.ts#L241-L280
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isTokenOnSameLine
function isTokenOnSameLine(left: ASTNode | Tree.Token, right: ASTNode | Tree.Token) { return left.loc.end.line === right.loc.start.line }
/** * Determines whether two adjacent tokens are on the same line. * @param left - The left token object. * @param right - The right token object. * @returns Whether or not the tokens are on the same line. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-newline/jsx-curly-newline._jsx_.ts#L89-L91
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
shouldHaveNewlines
function shouldHaveNewlines(expression: ASTNode, hasLeftNewline: boolean) { const isMultiline = expression.loc.start.line !== expression.loc.end.line switch (isMultiline ? option.multiline : option.singleline) { case 'forbid': return false case 'require': return true case 'consisten...
/** * Determines whether there should be newlines inside curlys * @param expression The expression contained in the curlys * @param hasLeftNewline `true` if the left curly has a newline in the current code. * @returns `true` if there should be newlines inside the function curlys */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-newline/jsx-curly-newline._jsx_.ts#L99-L108
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateCurlys
function validateCurlys(curlys: { leftCurly: Tree.Token, rightCurly: Tree.Token }, expression: ASTNode) { const leftCurly = curlys.leftCurly const rightCurly = curlys.rightCurly const tokenAfterLeftCurly = sourceCode.getTokenAfter(leftCurly) const tokenBeforeRightCurly = sourceCode.getTokenBefor...
/** * Validates curlys * @param curlys An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token * @param expression The expression inside the curly */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-newline/jsx-curly-newline._jsx_.ts#L115-L170
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isMultiline
function isMultiline(left: Tree.Token, right: Tree.Token) { return left.loc.end.line !== right.loc.start.line }
/** * Determines whether two adjacent tokens have a newline between them. * @param - The left token object. * @param right - The right token object. * @returns Whether or not there is a newline between the tokens. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L161-L163
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
fixByTrimmingWhitespace
function fixByTrimmingWhitespace(fixer: RuleFixer, fromLoc: number, toLoc: number, mode: string, spacing: string = '') { let replacementText = context.sourceCode.text.slice(fromLoc, toLoc) if (mode === 'start') replacementText = replacementText.replace(/^\s+/gm, '') else replacementTex...
/** * Trims text of whitespace between two ranges * @param fixer - the eslint fixer object * @param fromLoc - the start location * @param toLoc - the end location * @param mode - either 'start' or 'end' * @param spacing - a spacing value that will optionally add a space to the removed text...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L173-L187
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNoBeginningNewline
function reportNoBeginningNewline(node: ASTNode, token: Tree.Token, spacing: string) { context.report({ node, loc: token.loc.start, messageId: 'noNewlineAfter', data: { token: token.value, }, fix(fixer) { const nextToken = context.sourceCode.getT...
/** * Reports that there shouldn't be a newline 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 spacing */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L195-L208
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNoEndingNewline
function reportNoEndingNewline(node: ASTNode, token: Token, spacing: string) { context.report({ node, loc: token.loc.start, messageId: 'noNewlineBefore', data: { token: token.value, }, fix(fixer) { const previousToken = context.sourceCode.getToke...
/** * Reports that there shouldn't be a newline 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 spacing */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L216-L229
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNoBeginningSpace
function reportNoBeginningSpace(node: ASTNode, token: Token) { context.report({ node, loc: token.loc.start, messageId: 'noSpaceAfter', data: { token: token.value, }, fix(fixer) { const sourceCode = context.sourceCode const nextToken = s...
/** * 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. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L236-L256
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNoEndingSpace
function reportNoEndingSpace(node: ASTNode, token: Token) { context.report({ node, loc: token.loc.start, messageId: 'noSpaceBefore', data: { token: token.value, }, fix(fixer) { const sourceCode = context.sourceCode const previousToken =...
/** * 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. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L263-L283
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportRequiredBeginningSpace
function reportRequiredBeginningSpace(node: ASTNode, token: Token) { context.report({ node, loc: token.loc.start, messageId: 'spaceNeededAfter', data: { token: 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/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L290-L302
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportRequiredEndingSpace
function reportRequiredEndingSpace(node: ASTNode, token: Token) { context.report({ node, loc: token.loc.start, messageId: 'spaceNeededBefore', data: { token: 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/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L309-L321
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateBraceSpacing
function validateBraceSpacing(node: ASTNode) { let config switch (node.parent?.type) { case 'JSXAttribute': case 'JSXOpeningElement': config = attributesConfig break case 'JSXElement': case 'JSXFragment': config = childrenConfig break ...
/** * Determines if spacing in curly braces is valid. * @param node The AST node to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-curly-spacing/jsx-curly-spacing._jsx_.ts#L327-L392
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getNodeIndent
function getNodeIndent(node: ASTNode) { let src = context.sourceCode.getText(node, node.loc.start.column + extraColumnStart) const lines = src.split('\n') src = lines[0] let regExp if (indentType === 'space') regExp = /^ +/ else regExp = /^\t+/ const indent = ...
/** * Get node indent * @param node Node to examine * @return {number} Indent */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent-props/jsx-indent-props._jsx_.ts#L126-L151
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkNodesIndent
function checkNodesIndent(nodes: ASTNode[], indent: number) { let nestedIndent = indent nodes.forEach((node) => { const nodeIndent = getNodeIndent(node) if ( line.isUsingOperator && !line.currentOperator && indentSize !== 'first' && !ignoreTernaryOpera...
/** * Check indent for nodes list * @param nodes list of node objects * @param indent needed indent */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent-props/jsx-indent-props._jsx_.ts#L158-L196
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getFixerFunction
function getFixerFunction(node: ASTNode, needed: number): ReportFixFunction { const indent = new Array(needed + 1).join(indentChar) if (node.type === 'JSXText' || node.type === 'Literal') { return function fix(fixer) { const regExp = /\n[\t ]*(\S)/g const fixedText = node.raw.re...
/** * Responsible for fixing the indentation issue fix * @param node Node violating the indent rule * @param needed Expected indentation character count * @returns function to be executed by the fixer * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L113-L145
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
report
function report(node: ASTNode, needed: number, gotten: number, loc?: ASTNode['loc']) { const msgContext = { needed, type: indentType, characters: needed === 1 ? 'character' : 'characters', gotten, } context.report({ node, messageId: 'wrongIndent', ...
/** * Reports a given indent violation and properly pluralizes the message * @param node Node violating the indent rule * @param needed Expected indentation character count * @param gotten Indentation character count in the actual node/code * @param [loc] Error line and column location */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L154-L169
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 + extraColumnStart) const lines = src.split('\n') if (byLastLine) src = lines[lines.length - 1] else src = lines[0] c...
/** * Get node indent * @param node Node to examine * @param [byLastLine] get indent of node's last line * @param [excludeCommas] skip comma on start of line * @return {number} Indent */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L178-L196
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isRightInLogicalExp
function isRightInLogicalExp(node: ASTNode) { return ( node.parent && node.parent.parent && node.parent.parent.type === 'LogicalExpression' && node.parent.parent.right === node.parent && !indentLogicalExpressions ) }
/** * Check if the node is the right member of a logical expression * @param node The node to check * @return {boolean} true if its the case, false if not */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L203-L211
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isAlternateInConditionalExp
function isAlternateInConditionalExp(node: ASTNode) { return ( node.parent && node.parent.parent && node.parent.parent.type === 'ConditionalExpression' && node.parent.parent.alternate === node.parent && context.sourceCode.getTokenBefore(node)!.value !== '(' ) }
/** * Check if the node is the alternate member of a conditional expression * @param node The node to check * @return {boolean} true if its the case, false if not */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L218-L226
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isSecondOrSubsequentExpWithinDoExp
function isSecondOrSubsequentExpWithinDoExp(node: ASTNode) { /** * It returns true when node.parent.parent.parent.parent matches: * * DoExpression({ * ..., * body: BlockStatement({ * ..., * body: [ * ..., // 1-n times * Expres...
/** * Check if the node is within a DoExpression block but not the first expression (which need to be indented) * @param node The node to check * @return {boolean} true if its the case, false if not */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L233-L295
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkNodesIndent
function checkNodesIndent(node: ASTNode, indent: number, excludeCommas = false) { const nodeIndent = getNodeIndent(node, false, excludeCommas) const isCorrectRightInLogicalExp = isRightInLogicalExp(node) && (nodeIndent - indent) === indentSize const isCorrectAlternateInCondExp = isAlternateInCondition...
/** * Check indent for nodes list * @param node The node to check * @param indent needed indent * @param [excludeCommas] skip comma on start of line */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L303-L315
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkLiteralNodeIndent
function checkLiteralNodeIndent(node: Tree.Literal | Tree.JSXText, indent: number) { const value = node.value // eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/optimal-quantifier-concatenation const regExp = indentType === 'space' ? /\n( *)[\t ]*\S/g : /\n(\t*)[\t ]*\S/g co...
/** * Check indent for Literal Node or JSXText Node * @param node The node to check * @param indent needed indent */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-indent/jsx-indent._jsx_.ts#L322-L339
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
hasEmptyLines
function hasEmptyLines(first: NodeType, second: Tree.JSXAttribute | Tree.JSXSpreadAttribute) { const comments = sourceCode.getCommentsBefore ? sourceCode.getCommentsBefore(second) : [] const nodes = ([] as (NodeType | Tree.Comment)[]).concat(first, comments, second) for (let i = 1; i < nodes.length; ...
// First and second must be adjacent nodes
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-props-no-multi-spaces/jsx-props-no-multi-spaces._jsx_.ts#L50-L62
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
usesExpectedQuotes
function usesExpectedQuotes(node: Tree.StringLiteral) { return node.value.includes(setting.quote) || isSurroundedBy(node.raw, setting.quote) }
/** * Checks if the given string literal node uses the expected quotes * @param node A string literal node. * @returns Whether or not the string literal used the expected quotes. * @public */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-quotes/jsx-quotes._js_.ts#L67-L69
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
shouldSortToEnd
function shouldSortToEnd(node: Tree.JSXAttribute) { const attr = attributeMap.get(node) return !!attr && !!attr.hasComment }
// attributeMap = { end: endrange, hasComment: true||false if comment in between nodes exists, it needs to be sorted to end }
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-sort-props/jsx-sort-props._jsx_.ts#L57-L60
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getGroupsOfSortableAttributes
function getGroupsOfSortableAttributes(attributes: (Tree.JSXAttribute | Tree.JSXSpreadAttribute)[], context: Readonly<RuleContext<MessageIds, RuleOptions>>) { const sourceCode = context.sourceCode const sortableAttributeGroups: Tree.JSXAttribute[][] = [] let groupCount = 0 function addtoSortableAttributeGroups...
/** * Create an array of arrays where each subarray is composed of attributes * that are considered sortable. * @param attributes * @param context The context of the rule */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-sort-props/jsx-sort-props._jsx_.ts#L139-L215
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
validateReservedFirstConfig
function validateReservedFirstConfig(context: Readonly<RuleContext<MessageIds, RuleOptions>>, reservedFirst: unknown[] | boolean) { if (reservedFirst) { if (Array.isArray(reservedFirst)) { // Only allow a subset of reserved words in customized lists const nonReservedWords = reservedFirst.filter(word =...
/** * Checks if the `reservedFirst` option is valid * @param context The context of the rule * @param reservedFirst The `reservedFirst` option * @return {Function|undefined} If an error is detected, a function to generate the error message, otherwise, `undefined` */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-sort-props/jsx-sort-props._jsx_.ts#L286-L316
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
reportNodeAttribute
function reportNodeAttribute(nodeAttribute: Tree.JSXAttribute | Tree.JSXSpreadAttribute, errorType: MessageIds, node: Tree.JSXOpeningElement, context: Readonly<RuleContext<MessageIds, RuleOptions>>, reservedList: unknown[]) { const errors = reportedNodeAttributes.get(nodeAttribute) || [] if (errors.includes(errorT...
/** * Check if the current node attribute has already been reported with the same error type * if that's the case then we don't report a new error * otherwise we report the error * @param nodeAttribute The node attribute to be reported * @param errorType The error type to be reported * @param node The parent node...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-sort-props/jsx-sort-props._jsx_.ts#L329-L344
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
closingSlashOptions
function closingSlashOptions(option: Option['closingSlash']) { return [ { closingSlash: option, beforeSelfClosing: 'allow', afterOpening: 'allow', beforeClosing: 'allow', }, ] }
// -----------------------------------------------------------------------------
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/jsx-tag-spacing/jsx-tag-spacing._jsx_.test.ts#L19-L28
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
containsLineTerminator
function containsLineTerminator(str: string) { return LINEBREAK_MATCHER.test(str) }
/** * Checks whether a string contains a line terminator as defined in * http://www.ecma-international.org/ecma-262/5.1/#sec-7.3 * @param str String to test. * @returns True if str contains a line terminator. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L30-L32
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
last
function last<T>(arr: T[]): T { return arr[arr.length - 1] }
/** * Gets the last element of an array. * @param arr An array. * @returns Last element of arr. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L39-L41
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isSingleLine
function isSingleLine(node: ASTNode) { return (node.loc.end.line === node.loc.start.line) }
/** * Checks whether a node is contained on a single line. * @param node AST Node being evaluated. * @returns True if the node is a single line. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L48-L50
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isSingleLineImportAttributes
function isSingleLineImportAttributes( node: Tree.ImportDeclaration | Tree.ExportNamedDeclaration | Tree.ExportAllDeclaration | Tree.TSImportType, sourceCode: SourceCode, ) { const openingBrace = sourceCode.getTokenBefore(node.attributes[0], isOpeningBraceToken)! const closingBrace = sourceCode.getTokenAfter(no...
/** * Checks whether a node is contained on a single line. * @param node AST Node being evaluated. * @returns True if the node is a single line. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L57-L64
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isSingleLineProperties
function isSingleLineProperties(properties: ASTNode[]) { const [firstProp] = properties const lastProp = last(properties) return firstProp.loc.start.line === lastProp.loc.end.line }
/** * Checks whether the properties on a single line. * @param properties List of Property AST nodes. * @returns True if all properties is on a single line. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L71-L76
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
initOptionProperty
function initOptionProperty(toOptions: any, fromOptions: any) { toOptions.mode = fromOptions.mode || 'strict' // Set value of beforeColon if (typeof fromOptions.beforeColon !== 'undefined') toOptions.beforeColon = +fromOptions.beforeColon else toOptions.beforeColon = 0 // Set value of afterColon i...
/** * Initializes a single option property from the configuration with defaults for undefined values * @param toOptions Object to be initialized * @param fromOptions Object to be initialized from * @returns The object with correctly initialized options and values */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L84-L115
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
initOptions
function initOptions(toOptions: any, fromOptions: any) { if (typeof fromOptions.align === 'object') { // Initialize the alignment configuration toOptions.align = initOptionProperty({}, fromOptions.align) toOptions.align.on = fromOptions.align.on || 'colon' toOptions.align.mode = fromOptions.align.mode...
/** * Initializes all the option values (singleLine, multiLine and align) from the configuration with defaults for undefined values * @param toOptions Object to be initialized * @param fromOptions Object to be initialized from * @returns The object with correctly initialized options and values */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L123-L150
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isKeyValueProperty
function isKeyValueProperty<P extends Tree.ObjectLiteralElement | Tree.ImportAttribute>( property: P, ): property is (Tree.Property | Tree.ImportAttribute) & P { if (property.type === 'ImportAttribute') return true return !( (('method' in property && property.method) || (...
/** * Determines if the given property is key-value property. * @param property Property node to check. * @returns Whether the property is a key-value property. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L374-L384
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getNextColon
function getNextColon(node: ASTNode) { return sourceCode.getTokenAfter(node, isColonToken) }
/** * Starting from the given node (a property.key node here) looks forward * until it finds the colon punctuator and returns it. * @param node The node to start looking from. * @returns The colon punctuator. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L392-L394
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getLastTokenBeforeColon
function getLastTokenBeforeColon(node: ASTNode) { const colonToken = getNextColon(node)! return sourceCode.getTokenBefore(colonToken) }
/** * Starting from the given node (a property.key node here) looks forward * until it finds the last token before a colon punctuator and returns it. * @param node The node to start looking from. * @returns The last token before a colon punctuator. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L402-L406
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getFirstTokenAfterColon
function getFirstTokenAfterColon(node: ASTNode) { const colonToken = getNextColon(node)! return sourceCode.getTokenAfter(colonToken) }
/** * Starting from the given node (a property.key node here) looks forward * until it finds the first token after a colon punctuator and returns it. * @param node The node to start looking from. * @returns The first token after a colon punctuator. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L414-L418
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
continuesPropertyGroup
function continuesPropertyGroup( lastMember: Tree.ObjectLiteralElement | Tree.ImportAttribute, candidate: Tree.ObjectLiteralElement | Tree.ImportAttribute, ) { const groupEndLine = lastMember.loc.start.line const candidateValueStartLine = (isKeyValueProperty(candidate) ? getFirstTokenAfterCo...
/** * Checks whether a property is a member of the property group it follows. * @param lastMember The last Property known to be in the group. * @param candidate The next Property that might be in the group. * @returns True if the candidate property is part of the group. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L426-L456
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getKey
function getKey(property: Tree.Property | Tree.ImportAttribute) { const key = property.key if (property.type !== 'ImportAttribute' && property.computed) return sourceCode.getText().slice(key.range[0], key.range[1]) return getStaticPropertyName(property) }
/** * Gets an object literal property's key as the identifier name or string value. * @param property Property node whose key to retrieve. * @returns The property's key. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L463-L470
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
report
function report( property: Tree.Property | Tree.ImportAttribute, side: 'key' | 'value', whitespace: string, expected: number, mode: 'strict' | 'minimum', ) { const diff = whitespace.length - expected if (( diff && mode === 'strict' || diff < 0 && mode === '...
/** * Reports an appropriately-formatted error if spacing is incorrect on one * side of the colon. * @param property Key-value pair in an object literal. * @param side Side being verified - either "key" or "value". * @param whitespace Actual whitespace string. * @param expected Expected wh...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L481-L556
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getKeyWidth
function getKeyWidth(property: Tree.Property | Tree.ImportAttribute) { const startToken = sourceCode.getFirstToken(property)! const endToken = getLastTokenBeforeColon(property.key)! return getStringLength(sourceCode.getText().slice(startToken.range[0], endToken.range[1])) }
/** * Gets the number of characters in a key, including quotes around string * keys and braces around computed property keys. * @param property Property of on object literal. * @returns Width of the key. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L564-L569
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getPropertyWhitespace
function getPropertyWhitespace(property: Tree.Property | Tree.ImportAttribute) { const whitespace = /(\s*):(\s*)/u.exec(sourceCode.getText().slice( property.key.range[1], property.value.range[0], )) if (whitespace) { return { beforeColon: whitespace[1], aft...
/** * Gets the whitespace around the colon in an object literal property. * @param property Property node from an object literal. * @returns Whitespace before and after the property's colon. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L576-L589
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
createGroups
function createGroups(properties: (Tree.ObjectLiteralElement | Tree.ImportAttribute)[]) { if (properties.length === 1) return [properties] return properties.reduce<(Tree.ObjectLiteralElement | Tree.ImportAttribute)[][]>((groups, property) => { const currentGroup = last(groups) const...
/** * Creates groups of properties. * @param properties List of Property AST nodes being evaluated. * @returns Groups of property AST node lists. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L596-L613
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
verifyGroupAlignment
function verifyGroupAlignment(properties: (Tree.Property | Tree.ImportAttribute)[]) { const length = properties.length const widths = properties.map(getKeyWidth) // Width of keys, including quotes const align = alignmentOptions.on // "value" or "colon" let targetWidth = Math.max(...widths) ...
/** * Verifies correct vertical alignment of a group of properties. * @param properties List of Property AST nodes. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L619-L657
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
verifySpacing
function verifySpacing(node: Tree.Property | Tree.ImportAttribute, lineOptions: { beforeColon: number, afterColon: number, mode: 'strict' | 'minimum' }) { if (ignoredNodes.includes(node.parent.type)) return const actual = getPropertyWhitespace(node) if (actual) { // Object literal getters/set...
/** * Verifies spacing of property conforms to specified options. * @param node Property node being evaluated. * @param lineOptions Configured singleLine or multiLine options */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L664-L673
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
verifyListSpacing
function verifyListSpacing(properties: (Tree.Property | Tree.ImportAttribute)[], lineOptions: { beforeColon: number, afterColon: number, mode: 'strict' | 'minimum' }) { const length = properties.length for (let i = 0; i < length; i++) verifySpacing(properties[i], lineOptions) }
/** * Verifies spacing of each property in a list. * @param properties List of Property AST nodes. * @param lineOptions Configured singleLine or multiLine options */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L680-L685
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
verifyAlignment
function verifyAlignment(properties: (Tree.ObjectLiteralElement | Tree.ImportAttribute)[]) { createGroups(properties).forEach((group) => { const properties = group.filter(isKeyValueProperty) if (properties.length > 0 && isSingleLineProperties(properties)) verifyListSpacing(properties, m...
/** * Verifies vertical alignment, taking into account groups of properties. * @param properties List of Property AST nodes being evaluated. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._js_.ts#L691-L700
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
adjustedColumn
function adjustedColumn(position: Tree.Position): number { const line = position.line - 1 // position.line is 1-indexed return getStringLength( sourceCode.lines.at(line)!.slice(0, position.column), ) }
/** * @returns the column of the position after converting all unicode characters in the line to 1 char length */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._ts_.ts#L48-L53
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getLastTokenBeforeColon
function getLastTokenBeforeColon(node: ASTNode): Tree.Token { const colonToken = sourceCode.getTokenAfter(node, isColonToken)! return sourceCode.getTokenBefore(colonToken)! }
/** * Starting from the given a node (a property.key node here) looks forward * until it finds the last token before a colon punctuator and returns it. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._ts_.ts#L59-L63
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getKeyText
function getKeyText(node: KeyTypeNodeWithTypeAnnotation): string { if (node.type !== AST_NODE_TYPES.TSIndexSignature) return sourceCode.getText(node.key) const code = sourceCode.getText(node) return code.slice( 0, sourceCode.getTokenAfter( node.parameters.at(-1)!, ...
/** * To handle index signatures, to get the whole text for the parameters */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._ts_.ts#L97-L109
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getKeyLocEnd
function getKeyLocEnd( node: KeyTypeNodeWithTypeAnnotation, ): Tree.Position { return getLastTokenBeforeColon( node.type !== AST_NODE_TYPES.TSIndexSignature ? node.key : node.parameters.at(-1)!, ).loc.end }
/** * To handle index signatures, be able to get the end position of the parameters */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._ts_.ts#L114-L122
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
continuesAlignGroup
function continuesAlignGroup( lastMember: ASTNode, candidate: ASTNode, ): boolean { const groupEndLine = lastMember.loc.start.line const candidateValueStartLine = ( isKeyTypeNode(candidate) ? candidate.typeAnnotation : candidate ).loc.start.line if (candidateValueStartLi...
// adapted from https://github.com/eslint/eslint/blob/ba74253e8bd63e9e163bbee0540031be77e39253/lib/rules/key-spacing.js#L356
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/key-spacing/key-spacing._ts_.ts#L194-L234
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
override
function override(keyword: string, value: { before?: boolean, after?: boolean }) { const retv = { before: value.before === false, after: value.after === false, overrides: <Record<string, { before?: boolean, after?: boolean }>>{}, } retv.overrides[keyword] = value return retv }
/** * Creates an option object to test an "overrides" option. * * e.g. * * override("as", BOTH) * * returns * * { * before: false, * after: false, * overrides: {as: {before: true, after: true}} * } * @param keyword A keyword to be overridden. * @param value A value to ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L32-L42
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectedBefore
function expectedBefore(keyword: string) { return [{ messageId: 'expectedBefore', data: { value: keyword } }] }
/** * Gets an error message that expected space(s) before a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L49-L51
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectedAfter
function expectedAfter(keyword: string) { return [{ messageId: 'expectedAfter', data: { value: keyword } }] }
/** * Gets an error message that expected space(s) after a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L58-L60
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectedBeforeAndAfter
function expectedBeforeAndAfter(keyword: string) { return [ { messageId: 'expectedBefore', data: { value: keyword } }, { messageId: 'expectedAfter', data: { value: keyword } }, ] }
/** * Gets error messages that expected space(s) before and after a specified * keyword. * @param keyword A keyword. * @returns Error messages. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L68-L73
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectedBefore
function unexpectedBefore(keyword: string) { return [{ messageId: 'unexpectedBefore', data: { value: keyword } }] }
/** * Gets an error message that unexpected space(s) before a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L80-L82
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectedAfter
function unexpectedAfter(keyword: string) { return [{ messageId: 'unexpectedAfter', data: { value: keyword } }] }
/** * Gets an error message that unexpected space(s) after a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L89-L91
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectedBeforeAndAfter
function unexpectedBeforeAndAfter(keyword: string) { return [ { messageId: 'unexpectedBefore', data: { value: keyword } }, { messageId: 'unexpectedAfter', data: { value: keyword } }, ] }
/** * Gets error messages that unexpected space(s) before and after a specified * keyword. * @param keyword A keyword. * @returns Error messages. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.test.ts#L99-L104
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isOpenParenOfTemplate
function isOpenParenOfTemplate(token: Token) { return token.type === 'Template' && TEMPLATE_OPEN_PAREN.test(token.value) }
/** * Checks whether or not a given token is a "Template" token ends with "${". * @param token A token to check. * @returns `true` if the token is a "Template" token ends with "${". */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L35-L37
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
isCloseParenOfTemplate
function isCloseParenOfTemplate(token: Token) { return token.type === 'Template' && TEMPLATE_CLOSE_PAREN.test(token.value) }
/** * Checks whether or not a given token is a "Template" token starts with "}". * @param token A token to check. * @returns `true` if the token is a "Template" token starts with "}". */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L44-L46
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectSpaceBefore
function expectSpaceBefore(token: Token, pattern: RegExp) { const prevToken = sourceCode.getTokenBefore(token) if (prevToken && (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && !isOpenParenOfTemplate(prevToken) && !tokensToIgnore.has(prevToken) && isToke...
/** * Reports a given token if there are not space(s) before the token. * @param token A token to report. * @param pattern A pattern of the previous token to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L103-L123
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectSpaceBefore
function unexpectSpaceBefore(token: Token, pattern: RegExp) { const prevToken = sourceCode.getTokenBefore(token) if (prevToken && (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && !isOpenParenOfTemplate(prevToken) && !tokensToIgnore.has(prevToken) && isTo...
/** * Reports a given token if there are space(s) before the token. * @param token A token to report. * @param pattern A pattern of the previous token to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L130-L150
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectSpaceAfter
function expectSpaceAfter(token: Token, pattern: RegExp) { const nextToken = sourceCode.getTokenAfter(token) if (nextToken && (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && !isCloseParenOfTemplate(nextToken) && !tokensToIgnore.has(nextToken) && isToken...
/** * Reports a given token if there are not space(s) after the token. * @param token A token to report. * @param pattern A pattern of the next token to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L157-L177
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectSpaceAfter
function unexpectSpaceAfter(token: Token, pattern: RegExp) { const nextToken = sourceCode.getTokenAfter(token) if (nextToken && (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && !isCloseParenOfTemplate(nextToken) && !tokensToIgnore.has(nextToken) && isTok...
/** * Reports a given token if there are space(s) after the token. * @param token A token to report. * @param pattern A pattern of the next token to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L184-L204
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
parseOptions
function parseOptions(options: Options = {}): Record<string, { before: (token: Token, pattern?: RegExp) => void after: (token: Token, pattern?: RegExp) => void }> { const before = options.before !== false const after = options.after !== false const defaultValue = { before: befo...
/** * Parses the option object and determines check methods for each keyword. * @param options The option object to parse. * @returns - Normalized option object. * Keys are keywords (there are for every keyword). * Values are instances of `{"before": function, "after": function}`. ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L215-L247
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingBefore
function checkSpacingBefore(token: Token, pattern?: RegExp) { checkMethodMap[token.value].before(token, pattern || PREV_TOKEN) }
/** * Reports a given token if usage of spacing followed by the token is * invalid. * @param token A token to report. * @param [pattern] Optional. A pattern of the previous * token to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L258-L260
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingAfter
function checkSpacingAfter(token: Token, pattern?: RegExp) { checkMethodMap[token.value].after(token, pattern || NEXT_TOKEN) }
/** * Reports a given token if usage of spacing preceded by the token is * invalid. * @param token A token to report. * @param [pattern] Optional. A pattern of the next * token to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L269-L271
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingAround
function checkSpacingAround(token: Token) { checkSpacingBefore(token) checkSpacingAfter(token) }
/** * Reports a given token if usage of spacing around the token is invalid. * @param token A token to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L277-L280
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingAroundFirstToken
function checkSpacingAroundFirstToken(node: ASTNode | null) { const firstToken = node && sourceCode.getFirstToken(node) if (firstToken && firstToken.type === 'Keyword') checkSpacingAround(firstToken) }
/** * Reports the first token of a given node if the first token is a keyword * and usage of spacing around the token is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L287-L292
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingBeforeFirstToken
function checkSpacingBeforeFirstToken(node: ASTNode | null) { const firstToken = node && sourceCode.getFirstToken(node) if (firstToken && firstToken.type === 'Keyword') checkSpacingBefore(firstToken) }
/** * Reports the first token of a given node if the first token is a keyword * and usage of spacing followed by the token is invalid. * * This is used for unary operators (e.g. `typeof`), `function`, and `super`. * Other rules are handling usage of spacing preceded by those keywords. * @p...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L302-L307
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingAroundTokenBefore
function checkSpacingAroundTokenBefore(node: ASTNode | null) { if (node) { const token = sourceCode.getTokenBefore(node, isKeywordToken) if (token) checkSpacingAround(token) } }
/** * Reports the previous token of a given node if the token is a keyword and * usage of spacing around the token is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L314-L321
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForFunction
function checkSpacingForFunction( node: | Tree.FunctionDeclaration | Tree.ArrowFunctionExpression | Tree.FunctionExpression, ) { const firstToken = node && sourceCode.getFirstToken(node) if (firstToken && ((firstToken.type === 'Keyword' && firstToken.value === 'fun...
/** * Reports `async` or `function` keywords of a given node if usage of * spacing around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L328-L342
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForClass
function checkSpacingForClass(node: Tree.ClassDeclaration | Tree.ClassExpression) { checkSpacingAroundFirstToken(node) checkSpacingAroundTokenBefore(node.superClass) }
/** * Reports `class` and `extends` keywords of a given node if usage of * spacing around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L349-L352
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForIfStatement
function checkSpacingForIfStatement(node: Tree.IfStatement) { checkSpacingAroundFirstToken(node) checkSpacingAroundTokenBefore(node.alternate) }
/** * Reports `if` and `else` keywords of a given node if usage of spacing * around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L359-L362
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForTryStatement
function checkSpacingForTryStatement(node: Tree.TryStatement) { checkSpacingAroundFirstToken(node) checkSpacingAroundFirstToken(node.handler) checkSpacingAroundTokenBefore(node.finalizer) }
/** * Reports `try`, `catch`, and `finally` keywords of a given node if usage * of spacing around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L369-L373
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForDoWhileStatement
function checkSpacingForDoWhileStatement(node: Tree.DoWhileStatement) { checkSpacingAroundFirstToken(node) checkSpacingAroundTokenBefore(node.test) }
/** * Reports `do` and `while` keywords of a given node if usage of spacing * around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L380-L383
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForForInStatement
function checkSpacingForForInStatement(node: Tree.ForInStatement) { checkSpacingAroundFirstToken(node) const inToken = sourceCode.getTokenBefore(node.right, isNotOpeningParenToken)! const previousToken = sourceCode.getTokenBefore(inToken) // @ts-expect-error espree has PrivateIdentifier in tok...
/** * Reports `for` and `in` keywords of a given node if usage of spacing * around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L390-L403
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForForOfStatement
function checkSpacingForForOfStatement(node: Tree.ForOfStatement) { if (node.await) { checkSpacingBefore(sourceCode.getFirstToken(node, 0)!) checkSpacingAfter(sourceCode.getFirstToken(node, 1)!) } else { checkSpacingAroundFirstToken(node) } const ofToken = sourceCo...
/** * Reports `for` and `of` keywords of a given node if usage of spacing * around those keywords is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L410-L429
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForModuleDeclaration
function checkSpacingForModuleDeclaration( node: | Tree.ExportNamedDeclaration | Tree.ExportDefaultDeclaration | Tree.ExportAllDeclaration | Tree.ImportDeclaration, ) { const firstToken = sourceCode.getFirstToken(node)! checkSpacingBefore(firstToken, PREV_TOKEN_M) ...
/** * Reports `import`, `export`, `as`, and `from` keywords of a given node if * usage of spacing around those keywords is invalid. * * This rule handles the `*` token in module declarations. * * import*as A from "./a"; /*error Expected space(s) after "import". * ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L441-L469
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForImportSpecifier
function checkSpacingForImportSpecifier(node: Tree.ImportSpecifier) { if (node.imported.range[0] !== node.local.range[0]) { const asToken = sourceCode.getTokenBefore(node.local)! checkSpacingBefore(asToken, PREV_TOKEN_M) } }
/** * Reports `as` keyword of a given node if usage of spacing around this * keyword is invalid. * @param node An `ImportSpecifier` node to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L476-L482
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForExportSpecifier
function checkSpacingForExportSpecifier(node: Tree.ExportSpecifier) { if (node.local.range[0] !== node.exported.range[0]) { const asToken = sourceCode.getTokenBefore(node.exported)! checkSpacingBefore(asToken, PREV_TOKEN_M) checkSpacingAfter(asToken, NEXT_TOKEN_M) } }
/** * Reports `as` keyword of a given node if usage of spacing around this * keyword is invalid. * @param node An `ExportSpecifier` node to check. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L489-L496
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForImportNamespaceSpecifier
function checkSpacingForImportNamespaceSpecifier(node: Tree.ImportNamespaceSpecifier) { const asToken = sourceCode.getFirstToken(node, 1)! checkSpacingBefore(asToken, PREV_TOKEN_M) }
/** * Reports `as` keyword of a given node if usage of spacing around this * keyword is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L503-L507
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForProperty
function checkSpacingForProperty(node: Tree.MethodDefinition | Tree.PropertyDefinition | Tree.Property) { if ('static' in node && node.static) checkSpacingAroundFirstToken(node) if ((<Tree.Property>node).kind === 'get' || (<Tree.Property>node).kind === 'set' || ( (('method...
/** * Reports `static`, `get`, and `set` keywords of a given node if usage of * spacing around those keywords is invalid. * @param node A node to report. * @throws {Error} If unable to find token get, set, or async beside method name. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L515-L545
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
checkSpacingForAwaitExpression
function checkSpacingForAwaitExpression(node: Tree.AwaitExpression) { checkSpacingBefore(sourceCode.getFirstToken(node)!) }
/** * Reports `await` keyword of a given node if usage of spacing before * this keyword is invalid. * @param node A node to report. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._js_.ts#L552-L554
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
overrides
function overrides(keyword: string, value: RuleOptions[0] = {}): RuleOptions[0] { return { before: value.before === false, after: value.after === false, overrides: { [keyword]: value }, } }
/** * Creates an option object to test an 'overrides' option. * * e.g. * * override('as', BOTH) * * returns * * { * before: false, * after: false, * overrides: {as: {before: true, after: true}} * } * @param keyword A keyword to be overridden. * @param value A value to ...
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._ts_.test.ts#L30-L36
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectedBefore
function expectedBefore(keyword: string): TestCaseError[] { return [{ messageId: 'expectedBefore', data: { value: keyword } }] }
/** * Gets an error message that expected space(s) before a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._ts_.test.ts#L43-L45
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
expectedAfter
function expectedAfter(keyword: string): TestCaseError[] { return [{ messageId: 'expectedAfter', data: { value: keyword } }] }
/** * Gets an error message that expected space(s) after a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._ts_.test.ts#L52-L54
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectedBefore
function unexpectedBefore( keyword: string, ): TestCaseError[] { return [{ messageId: 'unexpectedBefore', data: { value: keyword } }] }
/** * Gets an error message that unexpected space(s) before a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._ts_.test.ts#L61-L65
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
unexpectedAfter
function unexpectedAfter( keyword: string, ): TestCaseError[] { return [{ messageId: 'unexpectedAfter', data: { value: keyword } }] }
/** * Gets an error message that unexpected space(s) after a specified keyword. * @param keyword A keyword. * @returns An error message. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/keyword-spacing/keyword-spacing._ts_.test.ts#L72-L76
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
createFix
function createFix(range: Readonly<Tree.Range>, text: string): ReportFixFunction { return function (fixer) { return fixer.replaceTextRange(range, text) } }
/** * Builds a fix function that replaces text at the specified range in the source text. * @param range The range to replace * @param text The text to insert. * @returns Fixer function * @private */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/linebreak-style/linebreak-style._js_.ts#L45-L49
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getEmptyLineNums
function getEmptyLineNums(lines: string[]) { const emptyLines = lines.map((line, i) => ({ code: line.trim(), num: i + 1, })).filter(line => !line.code).map(line => line.num) return emptyLines }
/** * Return an array with any line numbers that are empty. * @param lines An array of each line of the file. * @returns An array of line numbers. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/lines-around-comment/lines-around-comment._js_.ts#L16-L23
481d54b6521b8705570132424c78d320dec57610