Skip to content

Commit

Permalink
[chore] remove unnecessary aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
dangmai committed Dec 31, 2024
1 parent ad0dcd7 commit f6bf871
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
30 changes: 15 additions & 15 deletions packages/prettier-plugin-apex/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import type { AstPath, Doc, ParserOptions } from "prettier";
import * as prettier from "prettier";

import * as jorje from "../vendor/apex-ast-serializer/typings/jorje.d.js";
import {
ALLOW_DANGLING_COMMENTS,
APEX_TYPES as apexTypes,
} from "./constants.js";
import { ALLOW_DANGLING_COMMENTS, APEX_TYPES } from "./constants.js";
import {
AnnotatedComment,
GenericComment,
Expand Down Expand Up @@ -45,7 +42,7 @@ function printApexDocComment(comment: jorje.BlockComment): Doc {

export function isPrettierIgnore(comment: AnnotatedComment): boolean {
let content;
if (comment["@class"] === apexTypes.BLOCK_COMMENT) {
if (comment["@class"] === APEX_TYPES.BLOCK_COMMENT) {
// For simplicity sake we only support this format
// /* prettier-ignore */
content = comment.value
Expand Down Expand Up @@ -105,7 +102,7 @@ export function printDanglingComment(
const numberOfNewLinesToInsert = Math.min(numberOfNewLines, 2);
parts.push(...Array(numberOfNewLinesToInsert).fill(hardline));
}
if (comment["@class"] === apexTypes.INLINE_COMMENT) {
if (comment["@class"] === APEX_TYPES.INLINE_COMMENT) {
parts.push(lineSuffix(printComment(commentPath)));
} else {
parts.push(printComment(commentPath));
Expand All @@ -125,8 +122,8 @@ export function canAttachComment(node: any): boolean {
return (
node.loc &&
node["@class"] &&
node["@class"] !== apexTypes.INLINE_COMMENT &&
node["@class"] !== apexTypes.BLOCK_COMMENT
node["@class"] !== APEX_TYPES.INLINE_COMMENT &&
node["@class"] !== APEX_TYPES.BLOCK_COMMENT
);
}

Expand All @@ -138,7 +135,7 @@ export function canAttachComment(node: any): boolean {
* @returns {boolean} whether it is a block comment.
*/
export function isBlockComment(comment: GenericComment): boolean {
return comment["@class"] === apexTypes.BLOCK_COMMENT;
return comment["@class"] === APEX_TYPES.BLOCK_COMMENT;
}

/**
Expand All @@ -149,7 +146,7 @@ export function isBlockComment(comment: GenericComment): boolean {
*/
export function willPrintOwnComments(path: AstPath): boolean {
const node = path.getNode();
return !node || !node["@class"] || node["@class"] === apexTypes.ANNOTATION;
return !node || !node["@class"] || node["@class"] === APEX_TYPES.ANNOTATION;
}

export function getTrailingComments(node: any): AnnotatedComment[] {
Expand Down Expand Up @@ -206,7 +203,7 @@ function handleWhereExpression(
!followingNode ||
!precedingNode["@class"] ||
!followingNode["@class"] ||
enclosingNode["@class"] !== apexTypes.WHERE_COMPOUND_EXPRESSION ||
enclosingNode["@class"] !== APEX_TYPES.WHERE_COMPOUND_EXPRESSION ||
comment.location === undefined ||
comment.location.startIndex === undefined
) {
Expand Down Expand Up @@ -247,7 +244,10 @@ function handleBlockStatementLeadingComment(
comment: AnnotatedComment,
): boolean {
const { followingNode } = comment;
if (!followingNode || followingNode["@class"] !== apexTypes.BLOCK_STATEMENT) {
if (
!followingNode ||
followingNode["@class"] !== APEX_TYPES.BLOCK_STATEMENT
) {
return false;
}
if (followingNode.stmnts.length) {
Expand Down Expand Up @@ -303,8 +303,8 @@ function handleLongChainComment(comment: AnnotatedComment): boolean {
!enclosingNode ||
!precedingNode ||
!followingNode ||
(enclosingNode["@class"] !== apexTypes.METHOD_CALL_EXPRESSION &&
enclosingNode["@class"] !== apexTypes.VARIABLE_EXPRESSION)
(enclosingNode["@class"] !== APEX_TYPES.METHOD_CALL_EXPRESSION &&
enclosingNode["@class"] !== APEX_TYPES.VARIABLE_EXPRESSION)
) {
return false;
}
Expand Down Expand Up @@ -333,7 +333,7 @@ function handleModifierPrettierIgnoreComment(
!enclosingNode ||
!followingNode ||
!followingNode["@class"] ||
!followingNode["@class"].startsWith(apexTypes.MODIFIER)
!followingNode["@class"].startsWith(APEX_TYPES.MODIFIER)
) {
return false;
}
Expand Down
17 changes: 8 additions & 9 deletions packages/prettier-plugin-apex/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { AstPath } from "prettier";
import * as jorje from "../vendor/apex-ast-serializer/typings/jorje.d.js";
import {
APEX_TYPES,
APEX_TYPES as apexTypes,
DATA_CATEGORY,
MODIFIER,
ORDER,
Expand Down Expand Up @@ -50,8 +49,8 @@ export type AnnotatedComment = AnnotatedAstNode &

export function isBinaryish(node: jorje.Expr): boolean {
return (
node["@class"] === apexTypes.BOOLEAN_EXPRESSION ||
node["@class"] === apexTypes.BINARY_EXPRESSION
node["@class"] === APEX_TYPES.BOOLEAN_EXPRESSION ||
node["@class"] === APEX_TYPES.BINARY_EXPRESSION
);
}

Expand Down Expand Up @@ -89,8 +88,8 @@ export function checkIfParentIsDottedExpression(path: AstPath): boolean {
if (parentNodeName === "dottedExpr") {
result = true;
} else if (
node["@class"] === apexTypes.VARIABLE_EXPRESSION &&
parentNode["@class"] === apexTypes.ARRAY_EXPRESSION &&
node["@class"] === APEX_TYPES.VARIABLE_EXPRESSION &&
parentNode["@class"] === APEX_TYPES.ARRAY_EXPRESSION &&
grandParentNodeName === "dottedExpr"
) {
// a
Expand Down Expand Up @@ -134,7 +133,7 @@ export function massageAstNode(ast: any, newObj: any): any {
// Handling ApexDoc
if (
ast["@class"] &&
ast["@class"] === apexTypes.BLOCK_COMMENT &&
ast["@class"] === APEX_TYPES.BLOCK_COMMENT &&
isApexDocComment(ast)
) {
newObj.value = ast.value.replace(/\s/g, "");
Expand All @@ -148,7 +147,7 @@ export function massageAstNode(ast: any, newObj: any): any {
ast.dottedExpr &&
ast.dottedExpr.value &&
ast.dottedExpr.value.names &&
ast.dottedExpr.value["@class"] === apexTypes.VARIABLE_EXPRESSION &&
ast.dottedExpr.value["@class"] === APEX_TYPES.VARIABLE_EXPRESSION &&
ast.names
) {
// This is a workaround for #38 - jorje sometimes groups names with
Expand All @@ -158,15 +157,15 @@ export function massageAstNode(ast: any, newObj: any): any {
newObj.dottedExpr = newObj.dottedExpr.value.dottedExpr;
} else if (
ast["@class"] &&
ast["@class"] === apexTypes.WHERE_COMPOUND_EXPRESSION
ast["@class"] === APEX_TYPES.WHERE_COMPOUND_EXPRESSION
) {
// This flattens the SOQL/SOSL Compound Expression, e.g.:
// SELECT Id FROM Account WHERE Name = 'Name' AND (Status = 'Active' AND City = 'Boston')
// is equivalent to:
// SELECT Id FROM Account WHERE Name = 'Name' AND Status = 'Active' AND City = 'Boston'
for (let i = newObj.expr.length - 1; i >= 0; i -= 1) {
if (
newObj.expr[i]["@class"] === apexTypes.WHERE_COMPOUND_EXPRESSION &&
newObj.expr[i]["@class"] === APEX_TYPES.WHERE_COMPOUND_EXPRESSION &&
newObj.expr[i].op["@class"] === newObj.op["@class"]
) {
newObj.expr.splice(i, 1, ...newObj.expr[i].expr);
Expand Down

0 comments on commit f6bf871

Please sign in to comment.