⬅️ Back to Table of Contents
📄 prefer-ts-expect-error.ts
📊 Analysis Summary
Metric |
Count |
🔧 Functions |
5 |
📦 Imports |
5 |
📊 Variables & Constants |
2 |
📑 Type Aliases |
1 |
📚 Table of Contents
🛠️ File Location:
📂 packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts
📦 Imports
Name |
Source |
TSESTree |
@typescript-eslint/utils |
RuleFix |
@typescript-eslint/utils/ts-eslint |
RuleFixer |
@typescript-eslint/utils/ts-eslint |
AST_TOKEN_TYPES |
@typescript-eslint/utils |
createRule |
../util |
Variables & Constants
Name |
Type |
Kind |
Value |
Exported |
tsIgnoreRegExpSingleLine |
RegExp |
const |
/^\s*\/?\s*@ts-ignore/ |
✗ |
tsIgnoreRegExpMultiLine |
RegExp |
const |
/^\s*(?:\/|\*)*\s*@ts-ignore/ |
✗ |
Functions
Code
function isLineComment(comment: TSESTree.Comment): boolean {
return comment.type === AST_TOKEN_TYPES.Line;
}
- Parameters:
comment: TSESTree.Comment
- Return Type:
boolean
Code
function getLastCommentLine(comment: TSESTree.Comment): string {
if (isLineComment(comment)) {
return comment.value;
}
// For multiline comments - we look at only the last line.
const commentlines = comment.value.split('\n');
return commentlines[commentlines.length - 1];
}
- Parameters:
comment: TSESTree.Comment
- Return Type:
string
- Calls:
isLineComment
comment.value.split
- Internal Comments:
// For multiline comments - we look at only the last line. (x2)
Code
function isValidTsIgnorePresent(comment: TSESTree.Comment): boolean {
const line = getLastCommentLine(comment);
return isLineComment(comment)
? tsIgnoreRegExpSingleLine.test(line)
: tsIgnoreRegExpMultiLine.test(line);
}
- Parameters:
comment: TSESTree.Comment
- Return Type:
boolean
- Calls:
getLastCommentLine
isLineComment
tsIgnoreRegExpSingleLine.test
tsIgnoreRegExpMultiLine.test
Code
(fixer: RuleFixer): RuleFix =>
fixer.replaceText(
comment,
`//${comment.value.replace('@ts-ignore', '@ts-expect-error')}`,
)
- Parameters:
fixer: RuleFixer
- Return Type:
RuleFix
- Calls:
fixer.replaceText
Code
(fixer: RuleFixer): RuleFix =>
fixer.replaceText(
comment,
`/*${comment.value.replace(
'@ts-ignore',
'@ts-expect-error',
)}*/`,
)
- Parameters:
fixer: RuleFixer
- Return Type:
RuleFix
- Calls:
fixer.replaceText
Type Aliases
MessageIds
type MessageIds = 'preferExpectErrorComment';