Skip to content

Instantly share code, notes, and snippets.

@johnsoncodehk
Last active June 12, 2024 10:01
Show Gist options
  • Save johnsoncodehk/55a4c45a5a35fc30b83de20507fb2bdc to your computer and use it in GitHub Desktop.
Save johnsoncodehk/55a4c45a5a35fc30b83de20507fb2bdc to your computer and use it in GitHub Desktop.
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