📄 no-unsafe-unary-minus¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📑 Type Aliases | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/rules/no-unsafe-unary-minus.ts
📤 Default Export¶
| Property | Value |
|---|---|
name |
'no-unsafe-unary-minus' |
meta.type |
'problem' |
meta.docs.description |
'Require unary negation to take a number' |
meta.docs.recommended |
'recommended' |
meta.docs.requiresTypeChecking |
true |
meta.messages.unaryMinus |
'Argument of unary negation should be assignable to number | bigint but is {{type}} instead.' |
meta.schema |
[] |
defaultOptions |
[] |
Entry point: create — documented under Functions.
Functions¶
create(context: any): { UnaryExpression(node: any): void; }¶
Parameters:
contextany
Returns: { UnaryExpression(node: any): void; }
Calls:
util.getParserServicesutil.getConstrainedTypeAtLocationservices.program.getTypeCheckertsutils .unionConstituents(argType) .sometsutils.isTypeFlagSetcontext.reportchecker.typeToString
Code
create(context) {
return {
UnaryExpression(node): void {
if (node.operator !== '-') {
return;
}
const services = util.getParserServices(context);
const argType = util.getConstrainedTypeAtLocation(
services,
node.argument,
);
const checker = services.program.getTypeChecker();
if (
tsutils
.unionConstituents(argType)
.some(
type =>
!tsutils.isTypeFlagSet(
type,
ts.TypeFlags.Any |
ts.TypeFlags.Never |
ts.TypeFlags.BigIntLike |
ts.TypeFlags.NumberLike,
),
)
) {
context.report({
node,
messageId: 'unaryMinus',
data: { type: checker.typeToString(argType) },
});
}
},
};
}
Type Aliases¶
Options¶
MessageIds¶
Generated by Syntax Scribe