1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | var _a;
|
22 | Object.defineProperty(exports, "__esModule", { value: true });
|
23 | const utils_1 = require("@typescript-eslint/utils");
|
24 | const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
|
25 | const util = __importStar(require("../util"));
|
26 | const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('no-unused-expressions');
|
27 | exports.default = util.createRule({
|
28 | name: 'no-unused-expressions',
|
29 | meta: {
|
30 | type: 'suggestion',
|
31 | docs: {
|
32 | description: 'Disallow unused expressions',
|
33 | recommended: false,
|
34 | extendsBaseRule: true,
|
35 | },
|
36 | hasSuggestions: baseRule.meta.hasSuggestions,
|
37 | schema: baseRule.meta.schema,
|
38 |
|
39 | messages: (_a = baseRule.meta.messages) !== null && _a !== void 0 ? _a : {
|
40 | unusedExpression: 'Expected an assignment or function call and instead saw an expression.',
|
41 | },
|
42 | },
|
43 | defaultOptions: [
|
44 | {
|
45 | allowShortCircuit: false,
|
46 | allowTernary: false,
|
47 | allowTaggedTemplates: false,
|
48 | },
|
49 | ],
|
50 | create(context, [{ allowShortCircuit = false, allowTernary = false }]) {
|
51 | const rules = baseRule.create(context);
|
52 | function isValidExpression(node) {
|
53 | if (allowShortCircuit && node.type === utils_1.AST_NODE_TYPES.LogicalExpression) {
|
54 | return isValidExpression(node.right);
|
55 | }
|
56 | if (allowTernary && node.type === utils_1.AST_NODE_TYPES.ConditionalExpression) {
|
57 | return (isValidExpression(node.alternate) &&
|
58 | isValidExpression(node.consequent));
|
59 | }
|
60 | return ((node.type === utils_1.AST_NODE_TYPES.ChainExpression &&
|
61 | node.expression.type === utils_1.AST_NODE_TYPES.CallExpression) ||
|
62 | node.type === utils_1.AST_NODE_TYPES.ImportExpression);
|
63 | }
|
64 | return {
|
65 | ExpressionStatement(node) {
|
66 | if (node.directive || isValidExpression(node.expression)) {
|
67 | return;
|
68 | }
|
69 | rules.ExpressionStatement(node);
|
70 | },
|
71 | };
|
72 | },
|
73 | });
|
74 |
|
\ | No newline at end of file |