📄 no-unused-expressions¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 6 |
| 📊 Variables & Constants | 1 |
| 📑 Type Aliases | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/rules/no-unused-expressions.ts
📤 Default Export¶
| Property | Value |
|---|---|
name |
'no-unused-expressions' |
meta.type |
'suggestion' |
meta.docs.description |
'Disallow unused expressions' |
meta.docs.extendsBaseRule |
true |
meta.docs.recommended |
'recommended' |
meta.hasSuggestions |
baseRule.meta.hasSuggestions |
meta.messages |
baseRule.meta.messages |
meta.schema |
baseRule.meta.schema |
Entry point: create — documented under Functions.
📦 Imports¶
| Name | Source |
|---|---|
AST_NODE_TYPES |
@typescript-eslint/utils |
TSESTree |
@typescript-eslint/utils |
InferMessageIdsTypeFromRule |
../util |
InferOptionsTypeFromRule |
../util |
createRule |
../util |
getESLintCoreRule |
../util/getESLintCoreRule |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
defaultOptions |
Options |
const | [ { allowShortCircuit: false, allowTaggedTemplates: false, allowTernary: fals... |
✗ |
Functions¶
create(context: any, [{ allowShortCircuit = false, a…: any): { ExpressionStatement(node: any): void; }¶
Parameters:
contextany[{ allowShortCircuit = false, allowTernary = false }]any
Returns: { ExpressionStatement(node: any): void; }
Calls:
baseRule.createisValidExpressionrules.ExpressionStatement
Code
create(context, [{ allowShortCircuit = false, allowTernary = false }]) {
const rules = baseRule.create(context);
function isValidExpression(node: TSESTree.Node): boolean {
if (allowShortCircuit && node.type === AST_NODE_TYPES.LogicalExpression) {
return isValidExpression(node.right);
}
if (allowTernary && node.type === AST_NODE_TYPES.ConditionalExpression) {
return (
isValidExpression(node.alternate) &&
isValidExpression(node.consequent)
);
}
return (
(node.type === AST_NODE_TYPES.ChainExpression &&
node.expression.type === AST_NODE_TYPES.CallExpression) ||
node.type === AST_NODE_TYPES.ImportExpression
);
}
return {
ExpressionStatement(node): void {
if (node.directive || isValidExpression(node.expression)) {
return;
}
const expressionType = node.expression.type;
if (
expressionType ===
TSESTree.AST_NODE_TYPES.TSInstantiationExpression ||
expressionType === TSESTree.AST_NODE_TYPES.TSAsExpression ||
expressionType === TSESTree.AST_NODE_TYPES.TSNonNullExpression ||
expressionType === TSESTree.AST_NODE_TYPES.TSTypeAssertion
) {
rules.ExpressionStatement({
...node,
expression: node.expression.expression,
});
return;
}
rules.ExpressionStatement(node);
},
};
}
Internal helpers¶
Declared inside another function in this file.
isValidExpression(node: TSESTree.Node): boolean¶
Parameters:
nodeTSESTree.Node
Returns: boolean
Calls:
isValidExpression
Code
function isValidExpression(node: TSESTree.Node): boolean {
if (allowShortCircuit && node.type === AST_NODE_TYPES.LogicalExpression) {
return isValidExpression(node.right);
}
if (allowTernary && node.type === AST_NODE_TYPES.ConditionalExpression) {
return (
isValidExpression(node.alternate) &&
isValidExpression(node.consequent)
);
}
return (
(node.type === AST_NODE_TYPES.ChainExpression &&
node.expression.type === AST_NODE_TYPES.CallExpression) ||
node.type === AST_NODE_TYPES.ImportExpression
);
}
Type Aliases¶
MessageIds¶
Options¶
Generated by Syntax Scribe