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 | getUnquotedKey | function getUnquotedKey(key: Tree.StringLiteral | Tree.Identifier): string {
return key.type === 'Identifier' ? key.name : key.value
} | /**
* Returns a string representation of a property node with quotes removed
* @param key Key AST Node, which may or may not be quoted
* @returns A replacement string for this property
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L114-L116 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getQuotedKey | function getQuotedKey(key: Tree.Literal | Tree.Identifier): string {
if (key.type === 'Literal' && typeof key.value === 'string') {
// If the key is already a string literal, don't replace the quotes with double quotes.
return sourceCode.getText(key)
}
// Otherwise, the key is either ... | /**
* Returns a string representation of a property node with quotes added
* @param key Key AST Node, which may or may not be quoted
* @returns A replacement string for this property
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L123-L131 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkUnnecessaryQuotes | function checkUnnecessaryQuotes(node: Tree.Property | Tree.ImportAttribute): void {
const key = node.key
if (node.type !== 'ImportAttribute' && (node.method || node.computed || node.shorthand))
return
if (key.type === 'Literal' && typeof key.value === 'string') {
let tokens
... | /**
* Ensures that a property's key is quoted only when necessary
* @param node Property AST node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L137-L186 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkOmittedQuotes | function checkOmittedQuotes(node: Tree.Property | Tree.ImportAttribute): void {
if (node.type !== 'ImportAttribute' && (node.method || node.computed || node.shorthand))
return
const key = node.key
if (key.type === 'Literal' && typeof key.value === 'string')
return
context.repor... | /**
* Ensures that a property's key is quoted
* @param node Property AST node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L192-L206 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkConsistencyForObject | function checkConsistencyForObject(node: Tree.ObjectExpression, checkQuotesRedundancy: boolean): void {
checkConsistency(
node.properties.filter((property): property is Tree.PropertyNonComputedName =>
property.type !== 'SpreadElement'
// When called from `quote-props._ts_.ts`, it may b... | /**
* Ensures that an object's keys are consistently quoted, optionally checks for redundancy of quotes
* @param node Property AST node
* @param checkQuotesRedundancy Whether to check quotes' redundancy
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L213-L223 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkImportAttributes | function checkImportAttributes(attributes: Tree.ImportAttribute[] | undefined): void {
if (!attributes)
return
if (MODE === 'consistent')
checkConsistency(attributes, false)
if (MODE === 'consistent-as-needed')
checkConsistency(attributes, true)
} | /**
* Ensures that an import/export's attribute keys are consistently quoted.
* @param attributes Import attribute AST node array
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L229-L237 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkConsistency | function checkConsistency<P extends Tree.PropertyNonComputedName | Tree.ImportAttribute>(
properties: P[],
checkQuotesRedundancy: boolean,
): void {
const quotedProps: P[] = []
const unquotedProps: P[] = []
let keywordKeyName: string | null = null
let necessaryQuotes = false
... | /**
* Ensures these property keys are consistently quoted, optionally checks for redundancy of quotes
* @param properties Property AST node array
* @param checkQuotesRedundancy Whether to check quotes' redundancy
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quote-props/quote-props._js_.ts#L244-L313 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | switchQuote | function switchQuote(this: { quote: string }, str: string) {
const newQuote = this.quote
const oldQuote = str[0]
if (newQuote === oldQuote)
return str
return newQuote + str.slice(1, -1).replace(/\\(\$\{|\r\n?|\n|.)|["'`]|\$\{|(\r\n?|\n)/gu, (match, escaped, newline) => {
if (escaped === oldQuote || ol... | /**
* Switches quoting of javascript string between ' " and `
* escaping and unescaping as necessary.
* Only escaping of the minimal set of characters is changed.
* Note: escaping of newlines when switching from backtick to other quotes is not handled.
* @param str A string to convert.
* @returns The string with ... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quotes/quotes._js_.ts#L20-L39 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isJSXLiteral | function isJSXLiteral(node: ASTNode) {
if (!node.parent)
return false
return node.parent.type === 'JSXAttribute' || node.parent.type === 'JSXElement' || node.parent.type === 'JSXFragment'
} | /**
* Determines if a given node is part of JSX syntax.
*
* This function returns `true` in the following cases:
*
* - `<div className="foo"></div>` ... If the literal is an attribute value, the parent of the literal is `JSXAttribute`.
* - `<div>foo</div>` ... If the literal is a text cont... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quotes/quotes._js_.ts#L167-L172 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isDirective | function isDirective(node: ASTNode) {
return (
node.type === 'ExpressionStatement'
&& node.expression.type === 'Literal'
&& typeof node.expression.value === 'string'
&& !isParenthesised(sourceCode, node.expression)
)
} | /**
* Checks whether or not a given node is a directive.
* The directive is a `ExpressionStatement` which has only a string literal not surrounded by
* parentheses.
* @param node A node to check.
* @returns Whether or not the node is a directive.
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quotes/quotes._js_.ts#L182-L189 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isExpressionInOrJustAfterDirectivePrologue | function isExpressionInOrJustAfterDirectivePrologue(node: ASTNode) {
if (!node.parent)
return false
if (!isTopLevelExpressionStatement(node.parent))
return false
const block = node.parent.parent
if (!block || !('body' in block) || !Array.isArray(block.body))
return fals... | /**
* Checks whether a specified node is either part of, or immediately follows a (possibly empty) directive prologue.
* @see {@link http://www.ecma-international.org/ecma-262/6.0/#sec-directive-prologues-and-the-use-strict-directive}
* @param node A node to check.
* @returns Whether a specified nod... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quotes/quotes._js_.ts#L198-L221 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isAllowedAsNonBacktick | function isAllowedAsNonBacktick(node: ASTNode) {
const parent = node.parent
if (!parent)
return false
switch (parent.type) {
// Directive Prologues.
case 'ExpressionStatement':
return !isParenthesised(sourceCode, node) && isExpressionInOrJustAfterDirectivePrologue(no... | /**
* Checks whether or not a given node is allowed as non backtick.
* @param node A node to check.
* @returns Whether or not the node is allowed as non backtick.
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quotes/quotes._js_.ts#L229-L269 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isUsingFeatureOfTemplateLiteral | function isUsingFeatureOfTemplateLiteral(node: Tree.TemplateLiteral) {
const hasTag = node.parent.type === 'TaggedTemplateExpression' && node === node.parent.quasi
if (hasTag)
return true
const hasStringInterpolation = node.expressions.length > 0
if (hasStringInterpolation)
re... | /**
* Checks whether or not a given TemplateLiteral node is actually using any of the special features provided by template literal strings.
* @param node A TemplateLiteral node to check.
* @returns Whether or not the TemplateLiteral node is using any of the special features provided by template literal ... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/quotes/quotes._js_.ts#L277-L294 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkWhiteSpace | function checkWhiteSpace(
node:
| Tree.SpreadElement
| Tree.RestElement,
) {
const operator = sourceCode.getFirstToken(node)!
const nextToken = sourceCode.getTokenAfter(operator)!
const hasWhitespace = sourceCode.isSpaceBetween(operator, nextToken)
let type
switc... | /**
* Checks whitespace between rest/spread operators and their expressions
* @param node The node to check
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/rest-spread-spacing/rest-spread-spacing._js_.ts#L43-L99 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | hasLeadingSpace | function hasLeadingSpace(token: Token) {
const tokenBefore = sourceCode.getTokenBefore(token)
return tokenBefore && isTokenOnSameLine(tokenBefore, token) && sourceCode.isSpaceBetween(tokenBefore, token)
} | /**
* Checks if a given token has leading whitespace.
* @param token The token to check.
* @returns True if the given token has leading space, false if not.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L64-L68 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | hasTrailingSpace | function hasTrailingSpace(token: Token) {
const tokenAfter = sourceCode.getTokenAfter(token)
return tokenAfter && isTokenOnSameLine(token, tokenAfter) && sourceCode.isSpaceBetween(token, tokenAfter)
} | /**
* Checks if a given token has trailing whitespace.
* @param token The token to check.
* @returns True if the given token has trailing space, false if not.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L75-L79 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isLastTokenInCurrentLine | function isLastTokenInCurrentLine(token: Token) {
const tokenAfter = sourceCode.getTokenAfter(token)
return !(tokenAfter && isTokenOnSameLine(token, tokenAfter))
} | /**
* Checks if the given token is the last token in its line.
* @param token The token to check.
* @returns Whether or not the token is the last in its line.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L86-L90 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isFirstTokenInCurrentLine | function isFirstTokenInCurrentLine(token: Token) {
const tokenBefore = sourceCode.getTokenBefore(token)
return !(tokenBefore && isTokenOnSameLine(token, tokenBefore))
} | /**
* Checks if the given token is the first token in its line
* @param token The token to check.
* @returns Whether or not the token is the first in its line.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L97-L101 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isBeforeClosingParen | function isBeforeClosingParen(token: Token) {
const nextToken = sourceCode.getTokenAfter(token)
return (nextToken && isClosingBraceToken(nextToken) || isClosingParenToken(nextToken!))
} | /**
* Checks if the next token of a given token is a closing parenthesis.
* @param token The token to check.
* @returns Whether or not the next token of a given token is a closing parenthesis.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L108-L112 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkSemicolonSpacing | function checkSemicolonSpacing(token: Token, node: ASTNode) {
if (isSemicolonToken(token)) {
if (hasLeadingSpace(token)) {
if (!requireSpaceBefore) {
const tokenBefore = sourceCode.getTokenBefore(token)
const loc = {
start: tokenBefore!.loc.end,
... | /**
* Report location example :
*
* for unexpected space `before`
*
* var a = 'b' ;
* ^^^
*
* for unexpected space `after`
*
* var a = 'b'; c = 10;
* ^^
*
* Reports if the given token has invalid spacing.
* @param token The ... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L131-L201 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkNode | function checkNode(node: ASTNode) {
const token = sourceCode.getLastToken(node)
checkSemicolonSpacing(token!, node)
} | /**
* Checks the spacing of the semicolon with the assumption that the last token is the semicolon.
* @param node The node to check.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-spacing/semi-spacing._js_.ts#L207-L211 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getChildren | function getChildren(node: ASTNode) {
const t = node.type
if (
t === 'BlockStatement'
|| t === 'StaticBlock'
|| t === 'Program'
|| t === 'ClassBody'
) {
return node.body
}
if (t === 'SwitchCase')
return node.consequent
return null
} | /**
* Get the child node list of a given node.
* This returns `BlockStatement#body`, `StaticBlock#body`, `Program#body`,
* `ClassBody#body`, or `SwitchCase#consequent`.
* This is used to check whether a node is the first/last child.
* @param node A node to get child node list.
* @returns The child node list.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-style/semi-style._js_.ts#L35-L51 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isLastChild | function isLastChild(node: ASTNode): boolean {
if (!node.parent)
return true
const t = node.parent.type
if (t === 'IfStatement' && node.parent.consequent === node && node.parent.alternate) { // before `else` keyword.
return true
}
if (t === 'DoWhileStatement') { // before `while` keyword.
return ... | /**
* Check whether a given node is the last statement in the parent block.
* @param node A node to check.
* @returns `true` if the node is the last statement in the parent block.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-style/semi-style._js_.ts#L58-L72 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | check | function check(semiToken: Token, expected: 'last' | 'first'): void {
const prevToken = sourceCode.getTokenBefore(semiToken)
const nextToken = sourceCode.getTokenAfter(semiToken)
const prevIsSameLine = !prevToken || isTokenOnSameLine(prevToken, semiToken)
const nextIsSameLine = !nextToken || isTo... | /**
* Check the given semicolon token.
* @param semiToken The semicolon token to check.
* @param expected The expected location to check.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi-style/semi-style._js_.ts#L101-L128 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | report | function report(node: ASTNode, missing = false) {
const lastToken = sourceCode.getLastToken(node) as Token
let messageId: 'missingSemi' | 'extraSemi' = 'missingSemi'
let fix,
loc
if (!missing) {
loc = {
start: lastToken.loc.end,
end: getNextLocation(sourceCo... | /**
* Reports a semicolon error with appropriate location and message.
* @param node The node with an extra or missing semicolon.
* @param missing True if the semicolon is missing.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L93-L130 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isRedundantSemi | function isRedundantSemi(semiToken: Token) {
const nextToken = sourceCode.getTokenAfter(semiToken)
return (
!nextToken
|| isClosingBraceToken(nextToken)
|| isSemicolonToken(nextToken)
)
} | /**
* Check whether a given semicolon token is redundant.
* @param semiToken A semicolon token to check.
* @returns `true` if the next token is `;` or `}`.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L137-L145 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isEndOfArrowBlock | function isEndOfArrowBlock(lastToken: Token) {
if (!isClosingBraceToken(lastToken))
return false
const node = sourceCode.getNodeByRangeIndex(lastToken.range[0]) as ASTNode
return (
node.type === 'BlockStatement'
&& node.parent.type === 'ArrowFunctionExpression'
)
} | /**
* Check whether a given token is the closing brace of an arrow function.
* @param lastToken A token to check.
* @returns `true` if the token is the closing brace of an arrow function.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L152-L162 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | maybeClassFieldAsiHazard | function maybeClassFieldAsiHazard(node: ASTNode) {
if (node.type !== 'PropertyDefinition')
return false
/**
* Computed property names and non-identifiers are always safe
* as they can be distinguished from keywords easily.
*/
const needsNameCheck = !node.computed && node.... | /**
* Checks if a given PropertyDefinition node followed by a semicolon
* can safely remove that semicolon. It is not to safe to remove if
* the class field name is "get", "set", or "static", or if
* followed by a generator method.
* @param node The node to check.
* @returns `true` if the ... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L173-L207 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isOnSameLineWithNextToken | function isOnSameLineWithNextToken(node: ASTNode) {
const prevToken = sourceCode.getLastToken(node, 1)
const nextToken = sourceCode.getTokenAfter(node)
return !!nextToken && isTokenOnSameLine(prevToken, nextToken)
} | /**
* Check whether a given node is on the same line with the next token.
* @param node A statement node to check.
* @returns `true` if the node is on the same line with the next token.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L214-L219 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | maybeAsiHazardAfter | function maybeAsiHazardAfter(node: ASTNode) {
const t = node.type
if (t === 'DoWhileStatement'
|| t === 'BreakStatement'
|| t === 'ContinueStatement'
|| t === 'DebuggerStatement'
|| t === 'ImportDeclaration'
|| t === 'ExportAllDeclaration'
) {
return fa... | /**
* Check whether a given node can connect the next line if the next line is unreliable.
* @param node A statement node to check.
* @returns `true` if the node can connect the next line.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L226-L250 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | maybeAsiHazardBefore | function maybeAsiHazardBefore(token: Token) {
return (
Boolean(token)
&& OPT_OUT_PATTERN.test(token.value)
&& token.value !== '++'
&& token.value !== '--'
)
} | /**
* Check whether a given token can connect the previous statement.
* @param token A token to check.
* @returns `true` if the token is one of `[`, `(`, `/`, `+`, `-`, ```, `++`, and `--`.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L257-L264 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | canRemoveSemicolon | function canRemoveSemicolon(node: ASTNode) {
const lastToken = sourceCode.getLastToken(node) as Token
if (isRedundantSemi(lastToken))
return true // `;;` or `;}`
if (maybeClassFieldAsiHazard(node))
return false
if (isOnSameLineWithNextToken(node))
return false // One li... | /**
* Check if the semicolon of a given node is unnecessary, only true if:
* - next token is a valid statement divider (`;` or `}`).
* - next token is on a new line and the node is not connectable to the new line.
* @param node A statement node to check.
* @returns whether the semicolon is ... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L273-L300 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isLastInOneLinerBlock | function isLastInOneLinerBlock(node: ASTNode) {
const parent = node.parent as ASTNode
const nextToken = sourceCode.getTokenAfter(node)
if (!nextToken || nextToken.value !== '}')
return false
if (parent.type === 'BlockStatement')
return parent.loc.start.line === parent.loc.end.l... | /**
* Checks a node to see if it's the last item in a one-liner block.
* Block is any `BlockStatement` or `StaticBlock` node. Block is a one-liner if its
* braces (and consequently everything between them) are on the same line.
* @param node The node to check.
* @returns whether the node is the... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L309-L326 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isLastInOneLinerClassBody | function isLastInOneLinerClassBody(node: ASTNode) {
const parent = node.parent as ASTNode
const nextToken = sourceCode.getTokenAfter(node)
if (!nextToken || nextToken.value !== '}')
return false
if (parent.type === 'ClassBody')
return parent.loc.start.line === parent.loc.end.li... | /**
* Checks a node to see if it's the last item in a one-liner `ClassBody` node.
* ClassBody is a one-liner if its braces (and consequently everything between them) are on the same line.
* @param node The node to check.
* @returns whether the node is the last item in a one-liner ClassBody.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L334-L345 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForSemicolon | function checkForSemicolon(node: ASTNode) {
const lastToken = sourceCode.getLastToken(node) as Token
const isSemi = isSemicolonToken(lastToken)
if (never) {
const nextToken = sourceCode.getTokenAfter(node) as Token
if (isSemi && canRemoveSemicolon(node)) {
report(node, true... | /**
* Checks a node to see if it's followed by a semicolon.
* @param node The node to check.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L351-L380 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForSemicolonForVariableDeclaration | function checkForSemicolonForVariableDeclaration(node: Tree.VariableDeclaration) {
const parent = node.parent as ASTNode
if ((parent.type !== 'ForStatement' || parent.init !== node)
&& (!/^For(?:In|Of)Statement/u.test(parent.type) || (parent as Tree.ForInStatement).left !== node)
) {
... | /**
* Checks to see if there's a semicolon after a variable declaration.
* @param node The node to check.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/semi/semi._js_.ts#L386-L394 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isFunctionBody | function isFunctionBody(node: ASTNode): boolean {
const parent = node.parent
return (
node.type === 'BlockStatement'
&& isFunction(parent)
&& parent.body === node
)
} | /**
* Checks whether the given node represents the body of a function.
* @param node the node to check.
* @returns `true` if the node is function body.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-blocks/space-before-blocks._js_.ts#L16-L24 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isConflicted | function isConflicted(precedingToken: Token, node: ASTNode | Token) {
return (
isArrowToken(precedingToken)
|| (
isKeywordToken(precedingToken)
// @ts-expect-error type cast
&& !isFunctionBody(node)
)
|| (
isColonToken(precedingToken)
... | /**
* Checks whether the spacing before the given block is already controlled by another rule:
* - `arrow-spacing` checks spaces after `=>`.
* - `keyword-spacing` checks spaces after keywords in certain contexts.
* - `switch-colon-spacing` checks spaces after `:` of switch cases.
* @param prece... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-blocks/space-before-blocks._js_.ts#L109-L125 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkPrecedingSpace | function checkPrecedingSpace(node: ASTNode | Token) {
const precedingToken = sourceCode.getTokenBefore(node)
if (precedingToken && !isConflicted(precedingToken, node) && isTokenOnSameLine(precedingToken, node)) {
const hasSpace = sourceCode.isSpaceBetween(precedingToken, node)
let requireSp... | /**
* Checks the given BlockStatement node has a preceding space if it doesn’t start on a new line.
* @param node The AST node of a BlockStatement.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-blocks/space-before-blocks._js_.ts#L131-L172 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkSpaceBeforeCaseBlock | function checkSpaceBeforeCaseBlock(node: Tree.SwitchStatement) {
const cases = node.cases
let openingBrace: Token
if (cases.length > 0)
openingBrace = sourceCode.getTokenBefore(cases[0])!
else
openingBrace = sourceCode.getLastToken(node, 1)!
checkPrecedingSpace(openingBra... | /**
* Checks if the CaseBlock of an given SwitchStatement node has a preceding space.
* @param node The node of a SwitchStatement.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-blocks/space-before-blocks._js_.ts#L178-L188 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isNamedFunction | function isNamedFunction(
node:
| Tree.ArrowFunctionExpression
| Tree.FunctionDeclaration
| Tree.FunctionExpression,
) {
if (node.id)
return true
const parent = node.parent
return parent.type === 'MethodDefinition'
|| (parent.type === 'Property'
... | /**
* Determines whether a function has a name.
* @param node The function node.
* @returns Whether the function has a name.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-function-paren/space-before-function-paren._js_.ts#L69-L88 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getConfigForFunction | function getConfigForFunction(node:
| Tree.ArrowFunctionExpression
| Tree.FunctionDeclaration
| Tree.FunctionExpression,
) {
if (node.type === 'ArrowFunctionExpression') {
// Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar
if (node.... | /**
* Gets the config for a given function
* @param node The function node
* @returns "always", "never", or "ignore"
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-function-paren/space-before-function-paren._js_.ts#L95-L115 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkFunction | function checkFunction(node:
| Tree.ArrowFunctionExpression
| Tree.FunctionDeclaration
| Tree.FunctionExpression,
) {
const functionConfig = getConfigForFunction(node)
if (functionConfig === 'ignore')
return
const rightToken = sourceCode.getFirstToken(node, isOpeningPar... | /**
* Checks the parens of a function node
* @param node A function node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-function-paren/space-before-function-paren._js_.ts#L121-L165 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isNamedFunction | function isNamedFunction(
node:
| Tree.ArrowFunctionExpression
| Tree.FunctionDeclaration
| Tree.FunctionExpression
| Tree.TSDeclareFunction
| Tree.TSEmptyBodyFunctionExpression,
): boolean {
if (node.id != null)
return true
const parent = node.pare... | /**
* Determines whether a function has a name.
* @param node The function node.
* @returns Whether the function has a name.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-function-paren/space-before-function-paren._ts_.ts#L64-L85 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getConfigForFunction | function getConfigForFunction(
node:
| Tree.ArrowFunctionExpression
| Tree.FunctionDeclaration
| Tree.FunctionExpression
| Tree.TSDeclareFunction
| Tree.TSEmptyBodyFunctionExpression,
): FuncOption {
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {
... | /**
* Gets the config for a given function
* @param node The function node
* @returns "always", "never", or "ignore"
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-function-paren/space-before-function-paren._ts_.ts#L92-L119 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkFunction | function checkFunction(
node:
| Tree.ArrowFunctionExpression
| Tree.FunctionDeclaration
| Tree.FunctionExpression
| Tree.TSDeclareFunction
| Tree.TSEmptyBodyFunctionExpression,
): void {
const functionConfig = getConfigForFunction(node)
if (functionConfig =... | /**
* Checks the parens of a function node
* @param node A function node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-before-function-paren/space-before-function-paren._ts_.ts#L125-L185 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getExceptions | function getExceptions() {
const openers: string[] = []
const closers: string[] = []
if (options.braceException) {
openers.push('{')
closers.push('}')
}
if (options.bracketException) {
openers.push('[')
closers.push(']')
}
if (options.parenExc... | /**
* Produces an object with the opener and closer exception values
* @returns `openers` and `closers` exception values
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L79-L107 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isOpenerException | function isOpenerException(token: Token) {
return exceptions.openers.includes(token.value)
} | /**
* Determines if a token is one of the exceptions for the opener paren
* @param token The token to check
* @returns True if the token is one of the exceptions for the opener paren
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L115-L117 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isCloserException | function isCloserException(token: Token) {
return exceptions.closers.includes(token.value)
} | /**
* Determines if a token is one of the exceptions for the closer paren
* @param token The token to check
* @returns True if the token is one of the exceptions for the closer paren
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L124-L126 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | openerMissingSpace | function openerMissingSpace(openingParenToken: Token, tokenAfterOpeningParen: Token) {
if (sourceCode.isSpaceBetween(openingParenToken, tokenAfterOpeningParen))
return false
if (!options.empty && isClosingParenToken(tokenAfterOpeningParen))
return false
if (ALWAYS)
return !is... | /**
* Determines if an opening paren is immediately followed by a required space
* @param openingParenToken The paren token
* @param tokenAfterOpeningParen The token after it
* @returns True if the opening paren is missing a required space
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L134-L145 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | openerRejectsSpace | function openerRejectsSpace(openingParenToken: Token, tokenAfterOpeningParen: Token) {
if (!isTokenOnSameLine(openingParenToken, tokenAfterOpeningParen))
return false
if (tokenAfterOpeningParen.type === 'Line')
return false
if (!sourceCode.isSpaceBetween(openingParenToken, tokenAfter... | /**
* Determines if an opening paren is immediately followed by a disallowed space
* @param openingParenToken The paren token
* @param tokenAfterOpeningParen The token after it
* @returns True if the opening paren has a disallowed space
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L153-L167 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | closerMissingSpace | function closerMissingSpace(tokenBeforeClosingParen: Token, closingParenToken: Token) {
if (sourceCode.isSpaceBetween(tokenBeforeClosingParen, closingParenToken))
return false
if (!options.empty && isOpeningParenToken(tokenBeforeClosingParen))
return false
if (ALWAYS)
return ... | /**
* Determines if a closing paren is immediately preceded by a required space
* @param tokenBeforeClosingParen The token before the paren
* @param closingParenToken The paren token
* @returns True if the closing paren is missing a required space
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L175-L186 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | closerRejectsSpace | function closerRejectsSpace(tokenBeforeClosingParen: Token, closingParenToken: Token) {
if (!isTokenOnSameLine(tokenBeforeClosingParen, closingParenToken))
return false
if (!sourceCode.isSpaceBetween(tokenBeforeClosingParen, closingParenToken))
return false
if (ALWAYS)
return... | /**
* Determines if a closer paren is immediately preceded by a disallowed space
* @param tokenBeforeClosingParen The token before the paren
* @param closingParenToken The paren token
* @returns True if the closing paren has a disallowed space
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-in-parens/space-in-parens._js_.ts#L194-L205 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getFirstNonSpacedToken | function getFirstNonSpacedToken(left: ASTNode, right: ASTNode, op: string) {
const operator = sourceCode.getFirstTokenBetween(left, right, token => token.value === op)!
const prev = sourceCode.getTokenBefore(operator)!
const next = sourceCode.getTokenAfter(operator)!
if (!sourceCode.isSpaceBetw... | /**
* Returns the first token which violates the rule
* @param left The left node of the main node
* @param right The right node of the main node
* @param op The operator of the main node
* @returns The violator token or null
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._js_.ts#L53-L61 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | report | function report(mainNode: ASTNode, culpritToken: Token) {
context.report({
node: mainNode,
loc: culpritToken.loc,
messageId: 'missingSpace',
data: {
operator: culpritToken.value,
},
fix(fixer) {
const previousToken = sourceCode.getTokenBefore(cul... | /**
* Reports an AST node as a rule violation
* @param mainNode The node to report
* @param culpritToken The token which has a problem
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._js_.ts#L69-L93 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkBinary | function checkBinary(
node:
| Tree.AssignmentExpression
| Tree.AssignmentPattern
| Tree.BinaryExpression
| Tree.LogicalExpression,
) {
const leftNode = ('typeAnnotation' in node.left && node.left.typeAnnotation)
? node.left.typeAnnotation : node.left
const r... | /**
* Check if the node is binary then report
* @param node node to evaluate
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._js_.ts#L100-L120 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkConditional | function checkConditional(node: Tree.ConditionalExpression) {
const nonSpacedConsequentNode = getFirstNonSpacedToken(node.test, node.consequent, '?')
const nonSpacedAlternateNode = getFirstNonSpacedToken(node.consequent, node.alternate, ':')
if (nonSpacedConsequentNode)
report(node, nonSpaced... | /**
* Check if the node is conditional
* @param node node to evaluate
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._js_.ts#L127-L136 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkVar | function checkVar(node: Tree.VariableDeclarator) {
const leftNode = (node.id.typeAnnotation) ? node.id.typeAnnotation : node.id
const rightNode = node.init
if (rightNode) {
const nonSpacedNode = getFirstNonSpacedToken(leftNode, rightNode, '=')
if (nonSpacedNode)
report(node... | /**
* Check if the node is a variable
* @param node node to evaluate
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._js_.ts#L143-L153 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForEnumAssignmentSpace | function checkForEnumAssignmentSpace(node: Tree.TSEnumMember): void {
checkAndReportAssignmentSpace(node, node.id, node.initializer)
} | /**
* Check if it has an assignment char and report if it's faulty
* @param node The node to report
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._ts_.ts#L95-L97 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForPropertyDefinitionAssignmentSpace | function checkForPropertyDefinitionAssignmentSpace(
node: Tree.PropertyDefinition,
): void {
const leftNode
= node.optional && !node.typeAnnotation
? sourceCode.getTokenAfter(node.key)
: node.typeAnnotation ?? node.key
checkAndReportAssignmentSpace(node, leftNode, node... | /**
* Check if it has an assignment char and report if it's faulty
* @param node The node to report
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._ts_.ts#L103-L112 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForTypeAnnotationSpace | function checkForTypeAnnotationSpace(
typeAnnotation: Tree.TSIntersectionType | Tree.TSUnionType,
): void {
const types = typeAnnotation.types
types.forEach((type) => {
const skipFunctionParenthesis
= type.type === AST_NODE_TYPES.TSFunctionType
? isNotOpeningParenTok... | /**
* Check if it is missing spaces between type annotations chaining
* @param typeAnnotation TypeAnnotations list
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._ts_.ts#L118-L145 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForTypeAliasAssignment | function checkForTypeAliasAssignment(
node: Tree.TSTypeAliasDeclaration,
): void {
checkAndReportAssignmentSpace(
node,
node.typeParameters ?? node.id,
node.typeAnnotation,
)
} | /**
* Check if it has an assignment char and report if it's faulty
* @param node The node to report
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-infix-ops/space-infix-ops._ts_.ts#L151-L159 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isFirstBangInBangBangExpression | function isFirstBangInBangBangExpression(node: ASTNode) {
return node && node.type === 'UnaryExpression' && node.argument && node.argument.type === 'UnaryExpression' && node.argument.operator === '!'
} | /**
* Check if the node is the first "!" in a "!!" convert to Boolean expression
* @param node AST node
* @returns Whether or not the node is first "!" in "!!"
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L65-L67 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | overrideExistsForOperator | function overrideExistsForOperator(operator: string) {
return options.overrides && Object.prototype.hasOwnProperty.call(options.overrides, operator)
} | /**
* Checks if an override exists for a given operator.
* @param operator Operator
* @returns Whether or not an override has been provided for the operator
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L74-L76 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | overrideEnforcesSpaces | function overrideEnforcesSpaces(operator: string) {
return options.overrides?.[operator]
} | /**
* Gets the value that the override was set to for this operator
* @param operator Operator
* @returns Whether or not an override enforces a space with this operator
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L83-L85 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | verifyWordHasSpaces | function verifyWordHasSpaces(node: ASTNode, firstToken: Token, secondToken: Token, word: string) {
if (secondToken.range[0] === firstToken.range[1]) {
context.report({
node,
messageId: 'wordOperator',
data: {
word,
},
fix(fixer) {
r... | /**
* Verify Unary Word Operator has spaces after the word operator
* @param node AST node
* @param firstToken first token from the AST node
* @param secondToken second token from the AST node
* @param word The word to be used for reporting
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L94-L107 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | verifyWordDoesntHaveSpaces | function verifyWordDoesntHaveSpaces(node: ASTNode, firstToken: Token, secondToken: Token, word: string) {
if (canTokensBeAdjacent(firstToken, secondToken)) {
if (secondToken.range[0] > firstToken.range[1]) {
context.report({
node,
messageId: 'unexpectedAfterWord',
... | /**
* Verify Unary Word Operator doesn't have spaces after the word operator
* @param node AST node
* @param firstToken first token from the AST node
* @param secondToken second token from the AST node
* @param word The word to be used for reporting
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L116-L131 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkUnaryWordOperatorForSpaces | function checkUnaryWordOperatorForSpaces(node: ASTNode, firstToken: Token, secondToken: Token, word: string) {
if (overrideExistsForOperator(word)) {
if (overrideEnforcesSpaces(word))
verifyWordHasSpaces(node, firstToken, secondToken, word)
else
verifyWordDoesntHaveSpaces(node,... | /**
* Check Unary Word Operators for spaces after the word operator
* @param node AST node
* @param firstToken first token from the AST node
* @param secondToken second token from the AST node
* @param word The word to be used for reporting
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L140-L153 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForSpacesAfterYield | function checkForSpacesAfterYield(node: Tree.YieldExpression) {
const tokens = sourceCode.getFirstTokens(node, 3)
const word = 'yield'
if (!node.argument || node.delegate)
return
checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], word)
} | /**
* Verifies YieldExpressions satisfy spacing requirements
* @param node AST node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L159-L167 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForSpacesAfterAwait | function checkForSpacesAfterAwait(node: Tree.AwaitExpression) {
const tokens = sourceCode.getFirstTokens(node, 3)
checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], 'await')
} | /**
* Verifies AwaitExpressions satisfy spacing requirements
* @param node AwaitExpression AST node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L173-L177 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | verifyNonWordsHaveSpaces | function verifyNonWordsHaveSpaces(
node:
| Tree.UnaryExpression
| Tree.UpdateExpression
| Tree.NewExpression,
firstToken: Token,
secondToken: Token,
) {
if (('prefix' in node && node.prefix)) {
if (isFirstBangInBangBangExpression(node))
return
... | /**
* Verifies UnaryExpression, UpdateExpression and NewExpression have spaces before or after the operator
* @param node AST node
* @param firstToken First token in the expression
* @param secondToken Second token in the expression
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L185-L224 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | verifyNonWordsDontHaveSpaces | function verifyNonWordsDontHaveSpaces(node:
| Tree.UnaryExpression
| Tree.UpdateExpression
| Tree.NewExpression, firstToken: Token, secondToken: Token) {
if (('prefix' in node && node.prefix)) {
if (secondToken.range[0] > firstToken.range[1]) {
context.report({
node... | /**
* Verifies UnaryExpression, UpdateExpression and NewExpression don't have spaces before or after the operator
* @param node AST node
* @param firstToken First token in the expression
* @param secondToken Second token in the expression
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L232-L267 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkForSpaces | function checkForSpaces(node:
| Tree.UnaryExpression
| Tree.UpdateExpression
| Tree.NewExpression,
) {
const tokens = node.type === 'UpdateExpression' && !node.prefix
? sourceCode.getLastTokens(node, 2)
: sourceCode.getFirstTokens(node, 2)
const firstToken = tokens[0]
... | /**
* Verifies UnaryExpression, UpdateExpression and NewExpression satisfy spacing requirements
* @param node AST node
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/space-unary-ops/space-unary-ops._js_.ts#L273-L303 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | escape | function escape(s: string) {
return `(?:${escapeRegExp(s)})`
} | /**
* Escapes the control characters of a given string.
* @param s A string to escape.
* @returns An escaped string.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L16-L18 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | escapeAndRepeat | function escapeAndRepeat(s: string) {
return `${escape(s)}+`
} | /**
* Escapes the control characters of a given string.
* And adds a repeat flag.
* @param s A string to escape.
* @returns An escaped string.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L26-L28 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | parseMarkersOption | function parseMarkersOption(markers: string[]) {
// `*` is a marker for JSDoc comments.
if (!markers.includes('*'))
return markers.concat('*')
return markers
} | /**
* Parses `markers` option.
* If markers don't include `"*"`, this adds `"*"` to allow JSDoc comments.
* @param [markers] A marker list.
* @returns A marker list.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L36-L42 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | createExceptionsPattern | function createExceptionsPattern(exceptions: string[]) {
let pattern = ''
/**
* A space or an exception pattern sequence.
* [] ==> "\s"
* ["-"] ==> "(?:\s|\-+$)"
* ["-", "="] ==> "(?:\s|(?:\-+|=+)$)"
* ["-", "=", "--=="] ==> "(?:\s|(?:\-+|=+|(?:\-\-==)+)$)" ==> h... | /**
* Creates string pattern for exceptions.
* Generated pattern:
*
* 1. A space or an exception pattern sequence.
* @param exceptions An exception pattern list.
* @returns A regular expression string for exceptions.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L52-L84 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | createAlwaysStylePattern | function createAlwaysStylePattern(markers: string[], exceptions: string[]) {
let pattern = '^'
/**
* A marker or nothing.
* ["*"] ==> "\*?"
* ["*", "!"] ==> "(?:\*|!)?"
* ["*", "/", "!<"] ==> "(?:\*|\/|(?:!<))?" ==> https://jex.im/regulex/#!embed=false&flags=&re=(%3F%3A%5C*%7C%5C%2F%7C... | /**
* Creates RegExp object for `always` mode.
* Generated pattern for beginning of comment:
*
* 1. First, a marker or nothing.
* 2. Next, a space or an exception pattern sequence.
* @param markers A marker list.
* @param exceptions An exception pattern list.
* @returns A RegExp object for the beginning of a co... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L96-L120 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | createNeverStylePattern | function createNeverStylePattern(markers: string[]) {
const pattern = `^(${markers.map(escape).join('|')})?[ \t]+`
return new RegExp(pattern, 'u')
} | /**
* Creates RegExp object for `never` mode.
* Generated pattern for beginning of comment:
*
* 1. First, a marker or nothing (captured).
* 2. Next, a space or a tab.
* @param markers A marker list.
* @returns A RegExp object for `never` mode.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L131-L135 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportBegin | function reportBegin(node: Tree.Comment, messageId: MessageIds, match: RegExpExecArray | null, refChar: string) {
const type = node.type.toLowerCase()
const commentIdentifier = type === 'block' ? '/*' : '//'
context.report({
node,
fix(fixer) {
const start = node.range[0]
... | /**
* Reports a beginning spacing error with an appropriate message.
* @param node A comment node to check.
* @param messageId An error message to report.
* @param match An array of match results for markers.
* @param refChar Character used for reference in the error message.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L273-L297 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | reportEnd | function reportEnd(node: Tree.Comment, messageId: MessageIds, match: RegExpExecArray | null) {
context.report({
node,
fix(fixer) {
if (requireSpace)
return fixer.insertTextAfterRange([node.range[0], node.range[1] - 2], ' ')
const end = node.range[1] - 2
l... | /**
* Reports an ending spacing error with an appropriate message.
* @param node A comment node to check.
* @param messageId An error message to report.
* @param match An array of the matched whitespace characters.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L305-L321 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkCommentForSpace | function checkCommentForSpace(node: Tree.Comment) {
const type = node.type.toLowerCase() as Style
const rule = styleRules[type]
const commentIdentifier = type === 'block' ? '/*' : '//'
// Ignores empty comments and comments that consist only of a marker.
if (node.value.length === 0 || rul... | /**
* Reports a given comment if it's invalid.
* @param node a comment node to check.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/spaced-comment/spaced-comment._js_.ts#L327-L369 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isValidSpacing | function isValidSpacing(left: Token, right: Token, expected: boolean) {
return (
isClosingBraceToken(right)
|| !isTokenOnSameLine(left, right)
|| sourceCode.isSpaceBetween(left, right) === expected
)
} | /**
* Check whether the spacing between the given 2 tokens is valid or not.
* @param left The left token to check.
* @param right The right token to check.
* @param expected The expected spacing to check. `true` if there should be a space.
* @returns `true` if the spacing between the tokens is ... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/switch-colon-spacing/switch-colon-spacing._js_.ts#L53-L59 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | commentsExistBetween | function commentsExistBetween(left: Token, right: Token) {
return sourceCode.getFirstTokenBetween(
left,
right,
{
includeComments: true,
filter: isCommentToken,
},
) !== null
} | /**
* Check whether comments exist between the given 2 tokens.
* @param left The left token to check.
* @param right The right token to check.
* @returns `true` if comments exist between the given 2 tokens.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/switch-colon-spacing/switch-colon-spacing._js_.ts#L67-L76 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | fix | function fix(fixer: RuleFixer, left: Token, right: Token, spacing: boolean) {
if (commentsExistBetween(left, right))
return null
if (spacing)
return fixer.insertTextAfter(left, ' ')
return fixer.removeRange([left.range[1], right.range[0]])
} | /**
* Fix the spacing between the given 2 tokens.
* @param fixer The fixer to fix.
* @param left The left token of fix range.
* @param right The right token of fix range.
* @param spacing The spacing style. `true` if there should be a space.
* @returns The fix object.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/switch-colon-spacing/switch-colon-spacing._js_.ts#L86-L94 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkSpacingBefore | function checkSpacingBefore(token: Token) {
if (!token.value.startsWith('}'))
return // starts with a backtick, this is the first template element in the template literal
const prevToken = sourceCode.getTokenBefore(token, { includeComments: true })!
const hasSpace = sourceCode.isSpaceBetween!... | /**
* Checks spacing before `}` of a given token.
* @param token A token to check. This is a Template token.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/template-curly-spacing/template-curly-spacing._js_.ts#L45-L79 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkSpacingAfter | function checkSpacingAfter(token: Token) {
if (!token.value.endsWith('${'))
return // ends with a backtick, this is the last template element in the template literal
const nextToken = sourceCode.getTokenAfter(token, { includeComments: true })!
const hasSpace = sourceCode.isSpaceBetween!(token... | /**
* Checks spacing after `${` of a given token.
* @param token A token to check. This is a Template token.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/template-curly-spacing/template-curly-spacing._js_.ts#L85-L119 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkSpacing | function checkSpacing(node: Tree.TaggedTemplateExpression) {
const tagToken = sourceCode.getTokenBefore(node.quasi)!
const literalToken = sourceCode.getFirstToken(node.quasi)!
const hasWhitespace = sourceCode.isSpaceBetween(tagToken, literalToken)
if (never && hasWhitespace) {
context.r... | /**
* Check if a space is present between a template tag and its literal
* @param node node to evaluate
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/template-tag-spacing/template-tag-spacing._js_.ts#L43-L83 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkTypeAnnotationSpacing | function checkTypeAnnotationSpacing(
typeAnnotation: Tree.TypeNode,
): void {
const nextNode = typeAnnotation
const punctuatorTokenEnd = sourceCode.getTokenBefore(nextNode)!
let punctuatorTokenStart = punctuatorTokenEnd
let previousToken = sourceCode.getTokenBefore(punctuatorTokenEnd)!... | /**
* Checks if there's proper spacing around type annotations (no space
* before colon, one space after).
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/type-annotation-spacing/type-annotation-spacing._ts_.ts#L166-L272 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isCalleeOfNewExpression | function isCalleeOfNewExpression(node: ASTNode) {
const maybeCallee = node.parent?.type === 'ChainExpression'
? node.parent
: node
return (maybeCallee.parent?.type === 'NewExpression' && maybeCallee.parent.callee === maybeCallee)
} | /**
* Check if the given node is callee of a `NewExpression` node
* @param node node to check
* @returns True if the node is callee of a `NewExpression` node
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/wrap-iife/wrap-iife._js_.ts#L17-L23 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isWrappedInAnyParens | function isWrappedInAnyParens(node: ASTNode) {
return isParenthesised(sourceCode, node)
} | /**
* Check if the node is wrapped in any (). All parens count: grouping parens and parens for constructs such as if()
* @param node node to evaluate
* @returns True if it is wrapped in any parens
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/wrap-iife/wrap-iife._js_.ts#L72-L74 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | isWrappedInGroupingParens | function isWrappedInGroupingParens(node: ASTNode) {
return isParenthesized(node, sourceCode, 1)
} | /**
* Check if the node is wrapped in grouping (). Parens for constructs such as if() don't count
* @param node node to evaluate
* @returns True if it is wrapped in grouping parens
* @private
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/wrap-iife/wrap-iife._js_.ts#L82-L84 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | getFunctionNodeFromIIFE | function getFunctionNodeFromIIFE(node: Tree.CallExpression) {
const callee = skipChainExpression(node.callee)
if (callee.type === 'FunctionExpression')
return callee
if (includeFunctionPrototypeMethods
&& callee.type === 'MemberExpression'
&& callee.object.type === 'FunctionE... | /**
* Get the function node from an IIFE
* @param node node to evaluate
* @returns node that is the function expression of the given IIFE, or null if none exist
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/wrap-iife/wrap-iife._js_.ts#L91-L106 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkSpacing | function checkSpacing(side: 'before' | 'after', leftToken: Token, rightToken: Token) {
if (sourceCode.isSpaceBetween(leftToken, rightToken) !== mode[side]) {
const after = leftToken.value === '*'
const spaceRequired = mode[side]
const node = after ? leftToken : rightToken
const me... | /**
* Checks the spacing between two tokens before or after the star token.
* @param side Either "before" or "after".
* @param leftToken `function` keyword token if side is "before", or
* star token if side is "after".
* @param rightToken Star token if side is "before", or identifier
*... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/yield-star-spacing/yield-star-spacing._js_.ts#L71-L95 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | checkExpression | function checkExpression(node: ASTNode) {
if (!('delegate' in node && node.delegate))
return
const tokens = sourceCode.getFirstTokens(node, 3)
const yieldToken = tokens[0]
const starToken = tokens[1]
const nextToken = tokens[2]
checkSpacing('before', yieldToken, starToken)
... | /**
* Enforces the spacing around the star if node is a yield* expression.
* @param node A yield expression node.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/eslint-plugin/rules/yield-star-spacing/yield-star-spacing._js_.ts#L101-L112 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | FixTracker.constructor | constructor(
public fixer: RuleFixer,
public sourceCode: SourceCode,
) {
this.retainedRange = null
} | /**
* Create a new FixTracker.
* @param fixer A ruleFixer instance.
* @param sourceCode A SourceCode object for the current code.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/fix-tracker.ts#L23-L28 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | FixTracker.retainRange | retainRange(range: number[]) {
this.retainedRange = range
return this
} | /**
* Mark the given range as "retained", meaning that other fixes may not
* may not modify this region in the same pass.
* @param range The range to retain.
* @returns The same RuleFixer, for chained calls.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/fix-tracker.ts#L36-L39 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | FixTracker.retainEnclosingFunction | retainEnclosingFunction(node: ASTNode) {
const functionNode = getUpperFunction(node)
return this.retainRange(functionNode ? functionNode.range : this.sourceCode.ast.range)
} | /**
* Given a node, find the function containing it (or the entire program) and
* mark it as retained, meaning that other fixes may not modify it in this
* pass. This is useful for avoiding conflicts in fixes that modify control
* flow.
* @param node The node to use as a starting point.
* @returns The... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/fix-tracker.ts#L49-L53 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | FixTracker.retainSurroundingTokens | retainSurroundingTokens(nodeOrToken: Tree.Token | ASTNode) {
const tokenBefore = this.sourceCode.getTokenBefore(nodeOrToken) || nodeOrToken
const tokenAfter = this.sourceCode.getTokenAfter(nodeOrToken) || nodeOrToken
return this.retainRange([tokenBefore.range[0], tokenAfter.range[1]])
} | /**
* Given a node or token, find the token before and afterward, and mark that
* range as retained, meaning that other fixes may not modify it in this
* pass. This is useful for avoiding conflicts in fixes that make a small
* change to the code where the AST should not be changed.
* @param nodeOrToken T... | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/fix-tracker.ts#L64-L69 | 481d54b6521b8705570132424c78d320dec57610 |
eslint-stylistic | github_2023 | eslint-stylistic | typescript | FixTracker.replaceTextRange | replaceTextRange(range: [number, number], text: string) {
let actualRange: AST.Range
if (this.retainedRange) {
actualRange = [
Math.min(this.retainedRange[0], range[0]),
Math.max(this.retainedRange[1], range[1]),
]
}
else {
actualRange = range
}
return this.fi... | /**
* Create a fix command that replaces the given range with the given text,
* accounting for any retained ranges.
* @param range The range to remove in the fix.
* @param text The text to insert in place of the range.
* @returns The fix command.
*/ | https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/fix-tracker.ts#L78-L97 | 481d54b6521b8705570132424c78d320dec57610 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.