eslint-plugin-crisp 1.4.16 → 1.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -29,6 +29,7 @@ import ruleMultilineCommentEndBackslash from "./rules/multiline-comment-end-back
29
29
  import ruleNewlineAfterSwitchCase from "./rules/newline-after-switch-case.js";
30
30
  import ruleNoAsync from "./rules/no-async.js";
31
31
  import ruleNoExtraLineWithinFunction from "./rules/no-extra-line-within-function.js";
32
+ import ruleNoInlineFunctionInTernary from "./rules/no-inline-function-in-ternary.js";
32
33
  import ruleNoSpaceInOptionalArguments from "./rules/no-space-in-optional-arguments.js";
33
34
  import ruleNoUselessTemplateLiterals from "./rules/no-useless-template-literals.js";
34
35
  import ruleNoVarInBlocks from "./rules/no-var-in-blocks.js";
@@ -96,6 +97,7 @@ const plugin = {
96
97
  "newline-after-switch-case": ruleNewlineAfterSwitchCase,
97
98
  "no-async": ruleNoAsync,
98
99
  "no-extra-line-within-function": ruleNoExtraLineWithinFunction,
100
+ "no-inline-function-in-ternary": ruleNoInlineFunctionInTernary,
99
101
  "no-space-in-optional-arguments": ruleNoSpaceInOptionalArguments,
100
102
  "no-var-in-blocks": ruleNoVarInBlocks,
101
103
  "no-useless-template-literals": ruleNoUselessTemplateLiterals,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.4.16",
3
+ "version": "1.4.17",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
package/recommended-ts.js CHANGED
@@ -163,6 +163,7 @@ export default function configRecommendedTS(pluginCrisp) {
163
163
  "crisp/newline-after-switch-case": "error",
164
164
  "crisp/no-async": "off",
165
165
  "crisp/no-extra-line-within-function": "error",
166
+ "crisp/no-inline-function-in-ternary": "error",
166
167
  "crisp/no-short-parameters": [
167
168
  "error",
168
169
  {
@@ -179,6 +179,7 @@ export default function configRecommendedVue(pluginCrisp) {
179
179
  "crisp/newline-after-switch-case": "error",
180
180
  "crisp/no-async": "error",
181
181
  "crisp/no-extra-line-within-function": "error",
182
+ "crisp/no-inline-function-in-ternary": "error",
182
183
  "crisp/no-short-parameters": [
183
184
  "error",
184
185
 
package/recommended.js CHANGED
@@ -171,6 +171,7 @@ export default function configRecommended(pluginCrisp) {
171
171
  "crisp/newline-after-switch-case": "error",
172
172
  "crisp/no-async": "error",
173
173
  "crisp/no-extra-line-within-function": "error",
174
+ "crisp/no-inline-function-in-ternary": "error",
174
175
  "crisp/no-var-in-blocks": "error",
175
176
  "crisp/no-short-parameters": [
176
177
  "error",
@@ -0,0 +1,49 @@
1
+ const findContainingTernaryBranch = (node) => {
2
+ let child = node;
3
+ let parent = node.parent;
4
+
5
+ while (parent) {
6
+ if (
7
+ parent.type === "ConditionalExpression" &&
8
+ (parent.consequent === child || parent.alternate === child)
9
+ ) {
10
+ return parent;
11
+ }
12
+
13
+ child = parent;
14
+ parent = parent.parent;
15
+ }
16
+
17
+ return null;
18
+ };
19
+
20
+ export default {
21
+ meta: {
22
+ type: "suggestion",
23
+ docs: {
24
+ description: "Disallow inline functions in ternary branches."
25
+ },
26
+ schema: [],
27
+ messages: {
28
+ inlineFunction: "Extract this inline function from the ternary expression."
29
+ }
30
+ },
31
+
32
+ create(context) {
33
+ const checkFunction = (node) => {
34
+ if (!findContainingTernaryBranch(node)) {
35
+ return;
36
+ }
37
+
38
+ context.report({
39
+ node,
40
+ messageId: "inlineFunction"
41
+ });
42
+ };
43
+
44
+ return {
45
+ ArrowFunctionExpression: checkFunction,
46
+ FunctionExpression: checkFunction
47
+ };
48
+ }
49
+ };