keyword-spacing.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /**
  2. * @fileoverview Rule to enforce spacing before and after keywords.
  3. * @author Toru Nagashima
  4. * @deprecated in ESLint v8.53.0
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Requirements
  9. //------------------------------------------------------------------------------
  10. const astUtils = require("./utils/ast-utils"),
  11. keywords = require("./utils/keywords");
  12. //------------------------------------------------------------------------------
  13. // Constants
  14. //------------------------------------------------------------------------------
  15. const PREV_TOKEN = /^[)\]}>]$/u;
  16. const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u;
  17. const PREV_TOKEN_M = /^[)\]}>*]$/u;
  18. const NEXT_TOKEN_M = /^[{*]$/u;
  19. const TEMPLATE_OPEN_PAREN = /\$\{$/u;
  20. const TEMPLATE_CLOSE_PAREN = /^\}/u;
  21. const CHECK_TYPE =
  22. /^(?:JSXElement|RegularExpression|String|Template|PrivateIdentifier)$/u;
  23. const KEYS = keywords.concat([
  24. "as",
  25. "async",
  26. "await",
  27. "from",
  28. "get",
  29. "let",
  30. "of",
  31. "set",
  32. "yield",
  33. ]);
  34. // check duplications.
  35. (function () {
  36. KEYS.sort();
  37. for (let i = 1; i < KEYS.length; ++i) {
  38. if (KEYS[i] === KEYS[i - 1]) {
  39. throw new Error(
  40. `Duplication was found in the keyword list: ${KEYS[i]}`,
  41. );
  42. }
  43. }
  44. })();
  45. //------------------------------------------------------------------------------
  46. // Helpers
  47. //------------------------------------------------------------------------------
  48. /**
  49. * Checks whether or not a given token is a "Template" token ends with "${".
  50. * @param {Token} token A token to check.
  51. * @returns {boolean} `true` if the token is a "Template" token ends with "${".
  52. */
  53. function isOpenParenOfTemplate(token) {
  54. return token.type === "Template" && TEMPLATE_OPEN_PAREN.test(token.value);
  55. }
  56. /**
  57. * Checks whether or not a given token is a "Template" token starts with "}".
  58. * @param {Token} token A token to check.
  59. * @returns {boolean} `true` if the token is a "Template" token starts with "}".
  60. */
  61. function isCloseParenOfTemplate(token) {
  62. return token.type === "Template" && TEMPLATE_CLOSE_PAREN.test(token.value);
  63. }
  64. //------------------------------------------------------------------------------
  65. // Rule Definition
  66. //------------------------------------------------------------------------------
  67. /** @type {import('../types').Rule.RuleModule} */
  68. module.exports = {
  69. meta: {
  70. deprecated: {
  71. message: "Formatting rules are being moved out of ESLint core.",
  72. url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
  73. deprecatedSince: "8.53.0",
  74. availableUntil: "11.0.0",
  75. replacedBy: [
  76. {
  77. message:
  78. "ESLint Stylistic now maintains deprecated stylistic core rules.",
  79. url: "https://eslint.style/guide/migration",
  80. plugin: {
  81. name: "@stylistic/eslint-plugin",
  82. url: "https://eslint.style",
  83. },
  84. rule: {
  85. name: "keyword-spacing",
  86. url: "https://eslint.style/rules/keyword-spacing",
  87. },
  88. },
  89. ],
  90. },
  91. type: "layout",
  92. docs: {
  93. description: "Enforce consistent spacing before and after keywords",
  94. recommended: false,
  95. url: "https://eslint.org/docs/latest/rules/keyword-spacing",
  96. },
  97. fixable: "whitespace",
  98. schema: [
  99. {
  100. type: "object",
  101. properties: {
  102. before: { type: "boolean", default: true },
  103. after: { type: "boolean", default: true },
  104. overrides: {
  105. type: "object",
  106. properties: KEYS.reduce((retv, key) => {
  107. retv[key] = {
  108. type: "object",
  109. properties: {
  110. before: { type: "boolean" },
  111. after: { type: "boolean" },
  112. },
  113. additionalProperties: false,
  114. };
  115. return retv;
  116. }, {}),
  117. additionalProperties: false,
  118. },
  119. },
  120. additionalProperties: false,
  121. },
  122. ],
  123. messages: {
  124. expectedBefore: 'Expected space(s) before "{{value}}".',
  125. expectedAfter: 'Expected space(s) after "{{value}}".',
  126. unexpectedBefore: 'Unexpected space(s) before "{{value}}".',
  127. unexpectedAfter: 'Unexpected space(s) after "{{value}}".',
  128. },
  129. },
  130. create(context) {
  131. const sourceCode = context.sourceCode;
  132. const tokensToIgnore = new WeakSet();
  133. /**
  134. * Reports a given token if there are not space(s) before the token.
  135. * @param {Token} token A token to report.
  136. * @param {RegExp} pattern A pattern of the previous token to check.
  137. * @returns {void}
  138. */
  139. function expectSpaceBefore(token, pattern) {
  140. const prevToken = sourceCode.getTokenBefore(token);
  141. if (
  142. prevToken &&
  143. (CHECK_TYPE.test(prevToken.type) ||
  144. pattern.test(prevToken.value)) &&
  145. !isOpenParenOfTemplate(prevToken) &&
  146. !tokensToIgnore.has(prevToken) &&
  147. astUtils.isTokenOnSameLine(prevToken, token) &&
  148. !sourceCode.isSpaceBetweenTokens(prevToken, token)
  149. ) {
  150. context.report({
  151. loc: token.loc,
  152. messageId: "expectedBefore",
  153. data: token,
  154. fix(fixer) {
  155. return fixer.insertTextBefore(token, " ");
  156. },
  157. });
  158. }
  159. }
  160. /**
  161. * Reports a given token if there are space(s) before the token.
  162. * @param {Token} token A token to report.
  163. * @param {RegExp} pattern A pattern of the previous token to check.
  164. * @returns {void}
  165. */
  166. function unexpectSpaceBefore(token, pattern) {
  167. const prevToken = sourceCode.getTokenBefore(token);
  168. if (
  169. prevToken &&
  170. (CHECK_TYPE.test(prevToken.type) ||
  171. pattern.test(prevToken.value)) &&
  172. !isOpenParenOfTemplate(prevToken) &&
  173. !tokensToIgnore.has(prevToken) &&
  174. astUtils.isTokenOnSameLine(prevToken, token) &&
  175. sourceCode.isSpaceBetweenTokens(prevToken, token)
  176. ) {
  177. context.report({
  178. loc: { start: prevToken.loc.end, end: token.loc.start },
  179. messageId: "unexpectedBefore",
  180. data: token,
  181. fix(fixer) {
  182. return fixer.removeRange([
  183. prevToken.range[1],
  184. token.range[0],
  185. ]);
  186. },
  187. });
  188. }
  189. }
  190. /**
  191. * Reports a given token if there are not space(s) after the token.
  192. * @param {Token} token A token to report.
  193. * @param {RegExp} pattern A pattern of the next token to check.
  194. * @returns {void}
  195. */
  196. function expectSpaceAfter(token, pattern) {
  197. const nextToken = sourceCode.getTokenAfter(token);
  198. if (
  199. nextToken &&
  200. (CHECK_TYPE.test(nextToken.type) ||
  201. pattern.test(nextToken.value)) &&
  202. !isCloseParenOfTemplate(nextToken) &&
  203. !tokensToIgnore.has(nextToken) &&
  204. astUtils.isTokenOnSameLine(token, nextToken) &&
  205. !sourceCode.isSpaceBetweenTokens(token, nextToken)
  206. ) {
  207. context.report({
  208. loc: token.loc,
  209. messageId: "expectedAfter",
  210. data: token,
  211. fix(fixer) {
  212. return fixer.insertTextAfter(token, " ");
  213. },
  214. });
  215. }
  216. }
  217. /**
  218. * Reports a given token if there are space(s) after the token.
  219. * @param {Token} token A token to report.
  220. * @param {RegExp} pattern A pattern of the next token to check.
  221. * @returns {void}
  222. */
  223. function unexpectSpaceAfter(token, pattern) {
  224. const nextToken = sourceCode.getTokenAfter(token);
  225. if (
  226. nextToken &&
  227. (CHECK_TYPE.test(nextToken.type) ||
  228. pattern.test(nextToken.value)) &&
  229. !isCloseParenOfTemplate(nextToken) &&
  230. !tokensToIgnore.has(nextToken) &&
  231. astUtils.isTokenOnSameLine(token, nextToken) &&
  232. sourceCode.isSpaceBetweenTokens(token, nextToken)
  233. ) {
  234. context.report({
  235. loc: { start: token.loc.end, end: nextToken.loc.start },
  236. messageId: "unexpectedAfter",
  237. data: token,
  238. fix(fixer) {
  239. return fixer.removeRange([
  240. token.range[1],
  241. nextToken.range[0],
  242. ]);
  243. },
  244. });
  245. }
  246. }
  247. /**
  248. * Parses the option object and determines check methods for each keyword.
  249. * @param {Object|undefined} options The option object to parse.
  250. * @returns {Object} - Normalized option object.
  251. * Keys are keywords (there are for every keyword).
  252. * Values are instances of `{"before": function, "after": function}`.
  253. */
  254. function parseOptions(options = {}) {
  255. const before = options.before !== false;
  256. const after = options.after !== false;
  257. const defaultValue = {
  258. before: before ? expectSpaceBefore : unexpectSpaceBefore,
  259. after: after ? expectSpaceAfter : unexpectSpaceAfter,
  260. };
  261. const overrides = (options && options.overrides) || {};
  262. const retv = Object.create(null);
  263. for (let i = 0; i < KEYS.length; ++i) {
  264. const key = KEYS[i];
  265. const override = overrides[key];
  266. if (override) {
  267. const thisBefore =
  268. "before" in override ? override.before : before;
  269. const thisAfter =
  270. "after" in override ? override.after : after;
  271. retv[key] = {
  272. before: thisBefore
  273. ? expectSpaceBefore
  274. : unexpectSpaceBefore,
  275. after: thisAfter
  276. ? expectSpaceAfter
  277. : unexpectSpaceAfter,
  278. };
  279. } else {
  280. retv[key] = defaultValue;
  281. }
  282. }
  283. return retv;
  284. }
  285. const checkMethodMap = parseOptions(context.options[0]);
  286. /**
  287. * Reports a given token if usage of spacing followed by the token is
  288. * invalid.
  289. * @param {Token} token A token to report.
  290. * @param {RegExp} [pattern] Optional. A pattern of the previous
  291. * token to check.
  292. * @returns {void}
  293. */
  294. function checkSpacingBefore(token, pattern) {
  295. checkMethodMap[token.value].before(token, pattern || PREV_TOKEN);
  296. }
  297. /**
  298. * Reports a given token if usage of spacing preceded by the token is
  299. * invalid.
  300. * @param {Token} token A token to report.
  301. * @param {RegExp} [pattern] Optional. A pattern of the next
  302. * token to check.
  303. * @returns {void}
  304. */
  305. function checkSpacingAfter(token, pattern) {
  306. checkMethodMap[token.value].after(token, pattern || NEXT_TOKEN);
  307. }
  308. /**
  309. * Reports a given token if usage of spacing around the token is invalid.
  310. * @param {Token} token A token to report.
  311. * @returns {void}
  312. */
  313. function checkSpacingAround(token) {
  314. checkSpacingBefore(token);
  315. checkSpacingAfter(token);
  316. }
  317. /**
  318. * Reports the first token of a given node if the first token is a keyword
  319. * and usage of spacing around the token is invalid.
  320. * @param {ASTNode|null} node A node to report.
  321. * @returns {void}
  322. */
  323. function checkSpacingAroundFirstToken(node) {
  324. const firstToken = node && sourceCode.getFirstToken(node);
  325. if (firstToken && firstToken.type === "Keyword") {
  326. checkSpacingAround(firstToken);
  327. }
  328. }
  329. /**
  330. * Reports the first token of a given node if the first token is a keyword
  331. * and usage of spacing followed by the token is invalid.
  332. *
  333. * This is used for unary operators (e.g. `typeof`), `function`, and `super`.
  334. * Other rules are handling usage of spacing preceded by those keywords.
  335. * @param {ASTNode|null} node A node to report.
  336. * @returns {void}
  337. */
  338. function checkSpacingBeforeFirstToken(node) {
  339. const firstToken = node && sourceCode.getFirstToken(node);
  340. if (firstToken && firstToken.type === "Keyword") {
  341. checkSpacingBefore(firstToken);
  342. }
  343. }
  344. /**
  345. * Reports the previous token of a given node if the token is a keyword and
  346. * usage of spacing around the token is invalid.
  347. * @param {ASTNode|null} node A node to report.
  348. * @returns {void}
  349. */
  350. function checkSpacingAroundTokenBefore(node) {
  351. if (node) {
  352. const token = sourceCode.getTokenBefore(
  353. node,
  354. astUtils.isKeywordToken,
  355. );
  356. checkSpacingAround(token);
  357. }
  358. }
  359. /**
  360. * Reports `async` or `function` keywords of a given node if usage of
  361. * spacing around those keywords is invalid.
  362. * @param {ASTNode} node A node to report.
  363. * @returns {void}
  364. */
  365. function checkSpacingForFunction(node) {
  366. const firstToken = node && sourceCode.getFirstToken(node);
  367. if (
  368. firstToken &&
  369. ((firstToken.type === "Keyword" &&
  370. firstToken.value === "function") ||
  371. firstToken.value === "async")
  372. ) {
  373. checkSpacingBefore(firstToken);
  374. }
  375. }
  376. /**
  377. * Reports `class` and `extends` keywords of a given node if usage of
  378. * spacing around those keywords is invalid.
  379. * @param {ASTNode} node A node to report.
  380. * @returns {void}
  381. */
  382. function checkSpacingForClass(node) {
  383. checkSpacingAroundFirstToken(node);
  384. checkSpacingAroundTokenBefore(node.superClass);
  385. }
  386. /**
  387. * Reports `if` and `else` keywords of a given node if usage of spacing
  388. * around those keywords is invalid.
  389. * @param {ASTNode} node A node to report.
  390. * @returns {void}
  391. */
  392. function checkSpacingForIfStatement(node) {
  393. checkSpacingAroundFirstToken(node);
  394. checkSpacingAroundTokenBefore(node.alternate);
  395. }
  396. /**
  397. * Reports `try`, `catch`, and `finally` keywords of a given node if usage
  398. * of spacing around those keywords is invalid.
  399. * @param {ASTNode} node A node to report.
  400. * @returns {void}
  401. */
  402. function checkSpacingForTryStatement(node) {
  403. checkSpacingAroundFirstToken(node);
  404. checkSpacingAroundFirstToken(node.handler);
  405. checkSpacingAroundTokenBefore(node.finalizer);
  406. }
  407. /**
  408. * Reports `do` and `while` keywords of a given node if usage of spacing
  409. * around those keywords is invalid.
  410. * @param {ASTNode} node A node to report.
  411. * @returns {void}
  412. */
  413. function checkSpacingForDoWhileStatement(node) {
  414. checkSpacingAroundFirstToken(node);
  415. checkSpacingAroundTokenBefore(node.test);
  416. }
  417. /**
  418. * Reports `for` and `in` keywords of a given node if usage of spacing
  419. * around those keywords is invalid.
  420. * @param {ASTNode} node A node to report.
  421. * @returns {void}
  422. */
  423. function checkSpacingForForInStatement(node) {
  424. checkSpacingAroundFirstToken(node);
  425. const inToken = sourceCode.getTokenBefore(
  426. node.right,
  427. astUtils.isNotOpeningParenToken,
  428. );
  429. const previousToken = sourceCode.getTokenBefore(inToken);
  430. if (previousToken.type !== "PrivateIdentifier") {
  431. checkSpacingBefore(inToken);
  432. }
  433. checkSpacingAfter(inToken);
  434. }
  435. /**
  436. * Reports `for` and `of` keywords of a given node if usage of spacing
  437. * around those keywords is invalid.
  438. * @param {ASTNode} node A node to report.
  439. * @returns {void}
  440. */
  441. function checkSpacingForForOfStatement(node) {
  442. if (node.await) {
  443. checkSpacingBefore(sourceCode.getFirstToken(node, 0));
  444. checkSpacingAfter(sourceCode.getFirstToken(node, 1));
  445. } else {
  446. checkSpacingAroundFirstToken(node);
  447. }
  448. const ofToken = sourceCode.getTokenBefore(
  449. node.right,
  450. astUtils.isNotOpeningParenToken,
  451. );
  452. const previousToken = sourceCode.getTokenBefore(ofToken);
  453. if (previousToken.type !== "PrivateIdentifier") {
  454. checkSpacingBefore(ofToken);
  455. }
  456. checkSpacingAfter(ofToken);
  457. }
  458. /**
  459. * Reports `import`, `export`, `as`, and `from` keywords of a given node if
  460. * usage of spacing around those keywords is invalid.
  461. *
  462. * This rule handles the `*` token in module declarations.
  463. *
  464. * import*as A from "./a"; /*error Expected space(s) after "import".
  465. * error Expected space(s) before "as".
  466. * @param {ASTNode} node A node to report.
  467. * @returns {void}
  468. */
  469. function checkSpacingForModuleDeclaration(node) {
  470. const firstToken = sourceCode.getFirstToken(node);
  471. checkSpacingBefore(firstToken, PREV_TOKEN_M);
  472. checkSpacingAfter(firstToken, NEXT_TOKEN_M);
  473. if (node.type === "ExportDefaultDeclaration") {
  474. checkSpacingAround(sourceCode.getTokenAfter(firstToken));
  475. }
  476. if (node.type === "ExportAllDeclaration" && node.exported) {
  477. const asToken = sourceCode.getTokenBefore(node.exported);
  478. checkSpacingBefore(asToken, PREV_TOKEN_M);
  479. checkSpacingAfter(asToken, NEXT_TOKEN_M);
  480. }
  481. if (node.source) {
  482. const fromToken = sourceCode.getTokenBefore(node.source);
  483. checkSpacingBefore(fromToken, PREV_TOKEN_M);
  484. checkSpacingAfter(fromToken, NEXT_TOKEN_M);
  485. }
  486. }
  487. /**
  488. * Reports `as` keyword of a given node if usage of spacing around this
  489. * keyword is invalid.
  490. * @param {ASTNode} node An `ImportSpecifier` node to check.
  491. * @returns {void}
  492. */
  493. function checkSpacingForImportSpecifier(node) {
  494. if (node.imported.range[0] !== node.local.range[0]) {
  495. const asToken = sourceCode.getTokenBefore(node.local);
  496. checkSpacingBefore(asToken, PREV_TOKEN_M);
  497. }
  498. }
  499. /**
  500. * Reports `as` keyword of a given node if usage of spacing around this
  501. * keyword is invalid.
  502. * @param {ASTNode} node An `ExportSpecifier` node to check.
  503. * @returns {void}
  504. */
  505. function checkSpacingForExportSpecifier(node) {
  506. if (node.local.range[0] !== node.exported.range[0]) {
  507. const asToken = sourceCode.getTokenBefore(node.exported);
  508. checkSpacingBefore(asToken, PREV_TOKEN_M);
  509. checkSpacingAfter(asToken, NEXT_TOKEN_M);
  510. }
  511. }
  512. /**
  513. * Reports `as` keyword of a given node if usage of spacing around this
  514. * keyword is invalid.
  515. * @param {ASTNode} node A node to report.
  516. * @returns {void}
  517. */
  518. function checkSpacingForImportNamespaceSpecifier(node) {
  519. const asToken = sourceCode.getFirstToken(node, 1);
  520. checkSpacingBefore(asToken, PREV_TOKEN_M);
  521. }
  522. /**
  523. * Reports `static`, `get`, and `set` keywords of a given node if usage of
  524. * spacing around those keywords is invalid.
  525. * @param {ASTNode} node A node to report.
  526. * @throws {Error} If unable to find token get, set, or async beside method name.
  527. * @returns {void}
  528. */
  529. function checkSpacingForProperty(node) {
  530. if (node.static) {
  531. checkSpacingAroundFirstToken(node);
  532. }
  533. if (
  534. node.kind === "get" ||
  535. node.kind === "set" ||
  536. ((node.method || node.type === "MethodDefinition") &&
  537. node.value.async)
  538. ) {
  539. const token = sourceCode.getTokenBefore(node.key, tok => {
  540. switch (tok.value) {
  541. case "get":
  542. case "set":
  543. case "async":
  544. return true;
  545. default:
  546. return false;
  547. }
  548. });
  549. if (!token) {
  550. throw new Error(
  551. "Failed to find token get, set, or async beside method name",
  552. );
  553. }
  554. checkSpacingAround(token);
  555. }
  556. }
  557. /**
  558. * Reports `await` keyword of a given node if usage of spacing before
  559. * this keyword is invalid.
  560. * @param {ASTNode} node A node to report.
  561. * @returns {void}
  562. */
  563. function checkSpacingForAwaitExpression(node) {
  564. checkSpacingBefore(sourceCode.getFirstToken(node));
  565. }
  566. return {
  567. // Statements
  568. DebuggerStatement: checkSpacingAroundFirstToken,
  569. WithStatement: checkSpacingAroundFirstToken,
  570. // Statements - Control flow
  571. BreakStatement: checkSpacingAroundFirstToken,
  572. ContinueStatement: checkSpacingAroundFirstToken,
  573. ReturnStatement: checkSpacingAroundFirstToken,
  574. ThrowStatement: checkSpacingAroundFirstToken,
  575. TryStatement: checkSpacingForTryStatement,
  576. // Statements - Choice
  577. IfStatement: checkSpacingForIfStatement,
  578. SwitchStatement: checkSpacingAroundFirstToken,
  579. SwitchCase: checkSpacingAroundFirstToken,
  580. // Statements - Loops
  581. DoWhileStatement: checkSpacingForDoWhileStatement,
  582. ForInStatement: checkSpacingForForInStatement,
  583. ForOfStatement: checkSpacingForForOfStatement,
  584. ForStatement: checkSpacingAroundFirstToken,
  585. WhileStatement: checkSpacingAroundFirstToken,
  586. // Statements - Declarations
  587. ClassDeclaration: checkSpacingForClass,
  588. ExportNamedDeclaration: checkSpacingForModuleDeclaration,
  589. ExportDefaultDeclaration: checkSpacingForModuleDeclaration,
  590. ExportAllDeclaration: checkSpacingForModuleDeclaration,
  591. FunctionDeclaration: checkSpacingForFunction,
  592. ImportDeclaration: checkSpacingForModuleDeclaration,
  593. VariableDeclaration: checkSpacingAroundFirstToken,
  594. // Expressions
  595. ArrowFunctionExpression: checkSpacingForFunction,
  596. AwaitExpression: checkSpacingForAwaitExpression,
  597. ClassExpression: checkSpacingForClass,
  598. FunctionExpression: checkSpacingForFunction,
  599. NewExpression: checkSpacingBeforeFirstToken,
  600. Super: checkSpacingBeforeFirstToken,
  601. ThisExpression: checkSpacingBeforeFirstToken,
  602. UnaryExpression: checkSpacingBeforeFirstToken,
  603. YieldExpression: checkSpacingBeforeFirstToken,
  604. // Others
  605. ImportSpecifier: checkSpacingForImportSpecifier,
  606. ExportSpecifier: checkSpacingForExportSpecifier,
  607. ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,
  608. MethodDefinition: checkSpacingForProperty,
  609. PropertyDefinition: checkSpacingForProperty,
  610. StaticBlock: checkSpacingAroundFirstToken,
  611. Property: checkSpacingForProperty,
  612. // To avoid conflicts with `space-infix-ops`, e.g. `a > this.b`
  613. "BinaryExpression[operator='>']"(node) {
  614. const operatorToken = sourceCode.getTokenBefore(
  615. node.right,
  616. astUtils.isNotOpeningParenToken,
  617. );
  618. tokensToIgnore.add(operatorToken);
  619. },
  620. };
  621. },
  622. };