Last active
June 12, 2024 10:01
-
-
Save johnsoncodehk/55a4c45a5a35fc30b83de20507fb2bdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Rule } from '@tsslint/config'; | |
export function create(): Rule { | |
return ({ typescript: ts, sourceFile, reportWarning }) => { | |
ts.forEachChild(sourceFile, function cb(node) { | |
if ( | |
ts.isCallExpression(node) && | |
ts.isIdentifier(node.expression) && | |
node.expression.text === 'alert' | |
) { | |
reportWarning( | |
`Calls to 'alert' are not allowed.`, | |
node.getStart(sourceFile), | |
node.getEnd() | |
).withFix( | |
`Remove 'alert' call`, | |
() => [{ | |
fileName: sourceFile.fileName, | |
textChanges: [{ | |
newText: '/* deleted */', | |
span: { | |
start: node.getStart(sourceFile), | |
length: node.getWidth(sourceFile), | |
}, | |
}], | |
}] | |
); | |
} | |
ts.forEachChild(node, cb); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment