β¬ οΈ Back to Table of Contents
π ban-tslint-comment¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 2 |
| π¦ Imports | 2 |
| π Variables & Constants | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/rules/ban-tslint-comment.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'ban-tslint-comment' |
meta.type |
'suggestion' |
meta.docs.description |
'Disallow // tslint:<rule-flag> comments' |
meta.docs.recommended |
'stylistic' |
meta.fixable |
'code' |
meta.messages.commentDetected |
'tslint comment detected: "{{ text }}"' |
meta.schema |
[] |
defaultOptions |
[] |
Entry point: create β documented under Functions.
π¦ Imports¶
| Name | Source |
|---|---|
AST_TOKEN_TYPES |
@typescript-eslint/utils |
createRule |
../util |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
ENABLE_DISABLE_REGEX |
RegExp |
const | /^\s*tslint:(enable\|disable)(?:-(line\|next-line))?(:\|\s\|$)/ |
β |
Functions¶
create(context: any): { Program(): void; }¶
Parameters:
contextany
Returns: { Program(): void; }
Calls:
context.sourceCode.getAllCommentscomments.forEachENABLE_DISABLE_REGEX.testcontext.reporttoTextcontext.sourceCode.getIndexFromLocfixer.removeRange
Code
context => {
return {
Program(): void {
const comments = context.sourceCode.getAllComments();
comments.forEach(c => {
if (ENABLE_DISABLE_REGEX.test(c.value)) {
context.report({
node: c,
messageId: 'commentDetected',
data: { text: toText(c.value, c.type) },
fix(fixer) {
const rangeStart = context.sourceCode.getIndexFromLoc({
column: c.loc.start.column > 0 ? c.loc.start.column - 1 : 0,
line: c.loc.start.line,
});
const rangeEnd = context.sourceCode.getIndexFromLoc({
column: c.loc.end.column,
line: c.loc.end.line,
});
return fixer.removeRange([rangeStart, rangeEnd + 1]);
},
});
}
});
},
};
}
toText(text: string, type: AST_TOKEN_TYPES.Block | AST_TOKEN_TYPESβ¦): string¶
Parameters:
textstringtypeAST_TOKEN_TYPES.Block | AST_TOKEN_TYPES.Line
Returns: string
Code
Generated by Syntax Scribe