source: imaps-frontend/node_modules/eslint/lib/rules/yield-star-spacing.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[d565449]1/**
2 * @fileoverview Rule to check the spacing around the * in yield* expressions.
3 * @author Bryan Smith
4 * @deprecated in ESLint v8.53.0
5 */
6
7"use strict";
8
9//------------------------------------------------------------------------------
10// Rule Definition
11//------------------------------------------------------------------------------
12
13/** @type {import('../shared/types').Rule} */
14module.exports = {
15 meta: {
16 deprecated: true,
17 replacedBy: [],
18 type: "layout",
19
20 docs: {
21 description: "Require or disallow spacing around the `*` in `yield*` expressions",
22 recommended: false,
23 url: "https://eslint.org/docs/latest/rules/yield-star-spacing"
24 },
25
26 fixable: "whitespace",
27
28 schema: [
29 {
30 oneOf: [
31 {
32 enum: ["before", "after", "both", "neither"]
33 },
34 {
35 type: "object",
36 properties: {
37 before: { type: "boolean" },
38 after: { type: "boolean" }
39 },
40 additionalProperties: false
41 }
42 ]
43 }
44 ],
45 messages: {
46 missingBefore: "Missing space before *.",
47 missingAfter: "Missing space after *.",
48 unexpectedBefore: "Unexpected space before *.",
49 unexpectedAfter: "Unexpected space after *."
50 }
51 },
52
53 create(context) {
54 const sourceCode = context.sourceCode;
55
56 const mode = (function(option) {
57 if (!option || typeof option === "string") {
58 return {
59 before: { before: true, after: false },
60 after: { before: false, after: true },
61 both: { before: true, after: true },
62 neither: { before: false, after: false }
63 }[option || "after"];
64 }
65 return option;
66 }(context.options[0]));
67
68 /**
69 * Checks the spacing between two tokens before or after the star token.
70 * @param {string} side Either "before" or "after".
71 * @param {Token} leftToken `function` keyword token if side is "before", or
72 * star token if side is "after".
73 * @param {Token} rightToken Star token if side is "before", or identifier
74 * token if side is "after".
75 * @returns {void}
76 */
77 function checkSpacing(side, leftToken, rightToken) {
78 if (sourceCode.isSpaceBetweenTokens(leftToken, rightToken) !== mode[side]) {
79 const after = leftToken.value === "*";
80 const spaceRequired = mode[side];
81 const node = after ? leftToken : rightToken;
82 let messageId = "";
83
84 if (spaceRequired) {
85 messageId = side === "before" ? "missingBefore" : "missingAfter";
86 } else {
87 messageId = side === "before" ? "unexpectedBefore" : "unexpectedAfter";
88 }
89
90 context.report({
91 node,
92 messageId,
93 fix(fixer) {
94 if (spaceRequired) {
95 if (after) {
96 return fixer.insertTextAfter(node, " ");
97 }
98 return fixer.insertTextBefore(node, " ");
99 }
100 return fixer.removeRange([leftToken.range[1], rightToken.range[0]]);
101 }
102 });
103 }
104 }
105
106 /**
107 * Enforces the spacing around the star if node is a yield* expression.
108 * @param {ASTNode} node A yield expression node.
109 * @returns {void}
110 */
111 function checkExpression(node) {
112 if (!node.delegate) {
113 return;
114 }
115
116 const tokens = sourceCode.getFirstTokens(node, 3);
117 const yieldToken = tokens[0];
118 const starToken = tokens[1];
119 const nextToken = tokens[2];
120
121 checkSpacing("before", yieldToken, starToken);
122 checkSpacing("after", starToken, nextToken);
123 }
124
125 return {
126 YieldExpression: checkExpression
127 };
128
129 }
130};
Note: See TracBrowser for help on using the repository browser.