Skip to content

cosmetic changes #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
9 changes: 5 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

- uses: actions/setup-node@v1
- name: "Setup node"
uses: actions/setup-node@v4
with:
node-version: ">=14"
check-latest: true
node-version: "lts/*"

- name: Install Salesforce CLI + Scanner
run: |
Expand All @@ -37,6 +37,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Authenticate into DevHub
id: authenticate
run: |
echo "${SALESFORCE_JWT_SECRET_KEY}" > server.key
sf org login jwt --client-id ${{ secrets.SALESFORCE_CONSUMER_KEY }} --jwt-key-file server.key --username ${{ secrets.SALESFORCE_DEVHUB_USERNAME}} --set-default-dev-hub --alias devhub
Expand Down
1 change: 1 addition & 0 deletions .husky/_/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run precommit
72 changes: 69 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,81 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the source of all of this customization in this file?

The standard config is available here. I see advantage in specifying apexInsertFinalNewline : false, but the rest of the stuff seems to be the project-specific configuration from another team's project.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the file I use for my projects - it has more granular items from my experiences. For example, the space before the closing /> on the top line of metadata files now won't trigger a whitespace change if the metadata is downloaded from the org.

"plugins": ["prettier-plugin-apex"],
"arrowParens": "avoid",
"bracketSpacing": true,
"bracketSameLine": true,
"printWidth": 100,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"endOfLine": "lf",
"apexInsertFinalNewline": false,
"useTabs": true,
"overrides": [
{
"files": "**/lwc/**/*.html",
"options": { "parser": "lwc" }
},
{
"files": "*.{cls,trigger}",
"options": { "parser": "apex", "tabWidth": 2, "useTabs": true }
},
{
"files": "*.trigger",
"options": { "printWidth": 200 }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different than the other print width specification

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the width is less than 200, all the trigger contexts listed go one above each other on separate lines, making it unnecessarily harder (at least for me) to understand. However, since there are no triggers in this project, I can remove it.

},
{
"files": "*.{cmp,page,component}",
"options": { "parser": "html" }
"options": {
"parser": "html",
"useTabs": true,
"htmlWhitespaceSensitivity": "css"
}
},
{
"files": "*.{apex,soql}",
"options": { "parser": "apex-anonymous" }
},
{
"files": "*.{yml,yaml}",
"options": { "parser": "yaml", "tabWidth": 2, "useTabs": false }
},
{
"files": ".prettier*",
"options": { "parser": "json", "printWidth": 80, "useTabs": true }
},
{
"files": "*.xml",
"options": {
"parser": "xml",
"useTabs": true,
"singleQuote": false,
"xmlSelfClosingSpace": true
}
},
{
"files": ["**/pmd/*.xml", "*ruleset*.xml", "config/**/*.xml"],
"options": {
"parser": "xml",
"xmlSelfClosingSpace": true,
"xmlWhitespaceSensitivity": "ignore"
}
},
{
"files": "*meta.xml",
"options": {
"parser": "xml",
"useTabs": false,
"xmlSelfClosingSpace": false
}
},
{
"files": "*.json",
"options": {
"parser": "json-stringify",
"useTabs": false,
"tabWidth": 2
}
}
]
],
"plugins": ["prettier-plugin-apex", "@prettier/plugin-xml"],
"$schema": "https://json.schemastore.org/prettierrc"
}
34 changes: 9 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,17 @@
"version": "1.0.0",
"description": "Apex Trigger Actions Framework",
"scripts": {
"lint": "npm run lint:lwc && npm run lint:aura",
"lint:aura": "eslint **/aura/**",
"lint:lwc": "eslint **/lwc/**",
"test": "npm run test:unit",
"test:unit": "sfdx-lwc-jest",
"test:unit:watch": "sfdx-lwc-jest --watch",
"test:unit:debug": "sfdx-lwc-jest --debug",
"test:unit:coverage": "sfdx-lwc-jest --coverage",
"prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,yaml,yml}\"",
"prettier:verify": "prettier --list-different \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,yaml,yml}\""
"precommit": "lint-staged",
"prepare": "husky",
"prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",
"prettier:verify": "prettier --list-different \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\""
},
"devDependencies": {
"@prettier/plugin-xml": "^0.13.1",
"@salesforce/eslint-config-lwc": "^0.11.1",
"@salesforce/eslint-plugin-aura": "^2.0.0",
"@salesforce/sfdx-lwc-jest": "^0.10.4",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",
"prettier": "3.0.2",
"prettier-plugin-apex": "2.0.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
"@prettier/plugin-xml": "^3.4.1",
"husky": "^9.1.7",
"lint-staged": "^15.5.0",
"prettier": "3.5.3",
"prettier-plugin-apex": "2.2.5"
},
"lint-staged": {
"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}": [
Expand Down
2 changes: 1 addition & 1 deletion sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
"Trigger Actions [email protected]": "04tKY000000PdZJYA0",
"Trigger Actions [email protected]": "04tKY000000PdZOYA0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ public with sharing virtual class FinalizerHandler {
* @param finalizerMetadata The metadata of the finalizer to execute.
* @param context The context to pass to the finalizer's `execute` method.
*/
private void callReferencedFinalizer(
DML_Finalizer__mdt finalizerMetadata,
Context context
) {
private void callReferencedFinalizer(DML_Finalizer__mdt finalizerMetadata, Context context) {
Object dynamicInstance;
String className = finalizerMetadata.Apex_Class_Name__c;
if (FinalizerHandler.isBypassed(className)) {
Expand Down Expand Up @@ -166,9 +163,7 @@ public with sharing virtual class FinalizerHandler {
}

private void handleFinalizerException(String errorFormat, String className) {
throw new FinalizerException(
String.format(errorFormat, new List<String>{ className })
);
throw new FinalizerException(String.format(errorFormat, new List<String>{ className }));
}

/**
Expand All @@ -178,10 +173,7 @@ public with sharing virtual class FinalizerHandler {
* @param requiredPermission The required permission for the finalizer.
* @return True if bypassed, false otherwise.
*/
private boolean isBypassed(
String bypassPermission,
String requiredPermission
) {
private boolean isBypassed(String bypassPermission, String requiredPermission) {
return (bypassPermission != null && permissionMap.get(bypassPermission)) ||
(requiredPermission != null && !permissionMap.get(requiredPermission));
}
Expand All @@ -192,10 +184,7 @@ public with sharing virtual class FinalizerHandler {
*/
private void populatePermissionMap(String permissionName) {
if (permissionName != null && !permissionMap.containsKey(permissionName)) {
permissionMap.put(
permissionName,
FeatureManagement.checkPermission(permissionName)
);
permissionMap.put(permissionName, FeatureManagement.checkPermission(permissionName));
}
}

Expand Down Expand Up @@ -231,8 +220,7 @@ public with sharing virtual class FinalizerHandler {
* equal to, or greater than the specified object.
*/
public Integer compareTo(Object other) {
Decimal difference = (this.metadata.Order__c -
((FinalizerSorter) other).metadata.Order__c);
Decimal difference = (this.metadata.Order__c - ((FinalizerSorter) other).metadata.Order__c);
return difference < 0 ? -1 : difference == 0 ? 0 : 1;
}
}
Expand All @@ -249,4 +237,4 @@ public with sharing virtual class FinalizerHandler {
*/
private class FinalizerException extends Exception {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ private with sharing class FinalizerHandlerTest {
@IsTest
private static void staticallyBypassedFinalizerShouldNotExecute() {
handler.allFinalizers = new List<DML_Finalizer__mdt>{
new DML_Finalizer__mdt(
Apex_Class_Name__c = TEST_FOO_FINALIZER,
Order__c = 1
)
new DML_Finalizer__mdt(Apex_Class_Name__c = TEST_FOO_FINALIZER, Order__c = 1)
};

FinalizerHandler.bypass(TEST_FOO_FINALIZER);
Expand Down Expand Up @@ -150,14 +147,8 @@ private with sharing class FinalizerHandlerTest {
@IsTest
private static void finalizersShouldExecuteInOrder() {
handler.allFinalizers = new List<DML_Finalizer__mdt>{
new DML_Finalizer__mdt(
Apex_Class_Name__c = TEST_FOO_FINALIZER,
Order__c = 1
),
new DML_Finalizer__mdt(
Apex_Class_Name__c = TEST_BAR_FINALIZER,
Order__c = 2
)
new DML_Finalizer__mdt(Apex_Class_Name__c = TEST_FOO_FINALIZER, Order__c = 1),
new DML_Finalizer__mdt(Apex_Class_Name__c = TEST_BAR_FINALIZER, Order__c = 2)
};

handler.handleDynamicFinalizers();
Expand Down Expand Up @@ -213,10 +204,7 @@ private with sharing class FinalizerHandlerTest {
System.Assert.isNotNull(myException, EXCEPTION_SHOULD_BE_THROWN);

System.Assert.areEqual(
String.format(
FinalizerHandler.INVALID_TYPE_ERROR_FINALIZER,
new List<String>{ MY_CLASS }
),
String.format(FinalizerHandler.INVALID_TYPE_ERROR_FINALIZER, new List<String>{ MY_CLASS }),
myException.getMessage(),
EXCEPTION_SHOULD_HAVE_CORRECT_MESSAGE
);
Expand Down Expand Up @@ -307,4 +295,4 @@ private with sharing class FinalizerHandlerTest {
Database.setSavepoint();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ public with sharing class FlowChangeEventHeader {
public Integer hashCode() {
return JSON.serialize(this).hashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ private with sharing class FlowChangeEventHeaderTest {

@IsTest
private static void shouldBeAbleToConstruct() {
System.Assert.isNotNull(
header,
'Unable to construct a FlowChangeEventHeader'
);
System.Assert.isNotNull(header, 'Unable to construct a FlowChangeEventHeader');
}

@IsTest
Expand All @@ -36,9 +33,7 @@ private with sharing class FlowChangeEventHeaderTest {

@IsTest
private static void shouldBeAbleToCompare() {
FlowChangeEventHeader other = new FlowChangeEventHeader(
new EventBus.ChangeEventHeader()
);
FlowChangeEventHeader other = new FlowChangeEventHeader(new EventBus.ChangeEventHeader());
other.changeType = 'CREATE';

System.Assert.areEqual(
Expand All @@ -57,4 +52,4 @@ private with sharing class FlowChangeEventHeaderTest {
'Unable to detect difference between FlowChangeEventHeader and null'
);
}
}
}
33 changes: 8 additions & 25 deletions trigger-actions-framework/main/default/classes/FormulaFilter.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ global class FormulaFilter {
private static final String ERROR_PREFIX = 'Please check the `SObject_Trigger_Setting__mdt` metadata for the the {0} sObject.';
@TestVisible
private static final String MISSING_CLASS_NAME =
ERROR_PREFIX +
' The record is missing the `TriggerRecord_Class_Name__c` field.';
ERROR_PREFIX + ' The record is missing the `TriggerRecord_Class_Name__c` field.';
@TestVisible
private static final String INVALID_CLASS =
ERROR_PREFIX +
Expand Down Expand Up @@ -74,18 +73,14 @@ global class FormulaFilter {
List<SObject> triggerOld
) {
FormulaFilter.Result result = new FormulaFilter.Result();
String entryCriteriaFormula = this.triggerActionConfiguration
?.Entry_Criteria__c;
String entryCriteriaFormula = this.triggerActionConfiguration?.Entry_Criteria__c;

if (String.isBlank(entryCriteriaFormula)) {
result.triggerNew = triggerNew;
result.triggerOld = triggerOld;
return result;
}
String nameOfType = getNameOfType(
this.triggerActionConfiguration,
this.context
);
String nameOfType = getNameOfType(this.triggerActionConfiguration, this.context);
System.Type triggerRecordSubType = getType(nameOfType);
FormulaEval.FormulaInstance fx = getFormulaInstance(
triggerRecordSubType,
Expand All @@ -97,10 +92,7 @@ global class FormulaFilter {
for (Integer i = 0; i < size; i++) {
SObject record = triggerNew?.get(i);
SObject recordPrior = triggerOld?.get(i);
TriggerRecord toProcess = getTriggerRecord(
triggerRecordSubType,
nameOfType
);
TriggerRecord toProcess = getTriggerRecord(triggerRecordSubType, nameOfType);
toProcess.newSobject = record;
toProcess.oldSobject = recordPrior;
if ((Boolean) fx.evaluate(toProcess)) {
Expand All @@ -120,28 +112,19 @@ global class FormulaFilter {
System.Type response = System.Type.forName(className);
if (response == null) {
throw new IllegalArgumentException(
String.format(
INVALID_CLASS,
new List<String>{ this.sObjectName, className }
)
String.format(INVALID_CLASS, new List<String>{ this.sObjectName, className })
);
}
return response;
}

private TriggerRecord getTriggerRecord(
System.Type triggerRecordSubType,
String nameOfType
) {
private TriggerRecord getTriggerRecord(System.Type triggerRecordSubType, String nameOfType) {
TriggerRecord dynamicInstance;
try {
dynamicInstance = (TriggerRecord) triggerRecordSubType.newInstance();
} catch (System.TypeException e) {
throw new IllegalArgumentException(
String.format(
INVALID_SUBTYPE,
new List<String>{ this.sObjectName, nameOfType }
)
String.format(INVALID_SUBTYPE, new List<String>{ this.sObjectName, nameOfType })
);
}
return dynamicInstance;
Expand Down Expand Up @@ -204,4 +187,4 @@ global class FormulaFilter {
this.triggerOld = new List<SObject>();
}
}
}
}
Loading