diff --git a/force-app/main/default/lwc/orgcheckApp/api/dataset/orgcheck-api-dataset-apexclasses.js b/force-app/main/default/lwc/orgcheckApp/api/dataset/orgcheck-api-dataset-apexclasses.js index 8106953..c7939ac 100644 --- a/force-app/main/default/lwc/orgcheckApp/api/dataset/orgcheck-api-dataset-apexclasses.js +++ b/force-app/main/default/lwc/orgcheckApp/api/dataset/orgcheck-api-dataset-apexclasses.js @@ -6,7 +6,7 @@ const REGEX_COMMENTS_AND_NEWLINES = new RegExp('(\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.* const REGEX_ISINTERFACE = new RegExp("(?:public|global)\\s+(?:interface)\\s+\\w+(\\s+(?:extends)\\s+\\w+)?\\s*\\{", 'i'); const REGEX_ISENUM = new RegExp("(?:public|global)\\s+(?:enum)\\s+\\w+\\s*\\{", 'i'); const REGEX_ISTESTSEEALLDATA = new RegExp("@IsTest\\(.*SeeAllData=true.*\\)", 'i'); -const REGEX_TESTNBASSERTS = new RegExp("System.assert(?:Equals|NotEquals|)\\(", 'ig'); +const REGEX_TESTNBASSERTS = new RegExp("(System.assert(Equals|NotEquals|)\\(|Assert\\.[a-zA-Z]*\\()", 'ig'); export class OrgCheckDatasetApexClasses extends OrgCheckDataset { @@ -83,15 +83,7 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset { allDependencies: dependencies }); - // Get information directly from the source code (if available) - if (record.Body) { - const sourceCode = record.Body.replaceAll(REGEX_COMMENTS_AND_NEWLINES, ' '); - apexClass.isInterface = sourceCode.match(REGEX_ISINTERFACE) !== null; - apexClass.isEnum = sourceCode.match(REGEX_ISENUM) !== null; - apexClass.isClass = (apexClass.isInterface === false && apexClass.isEnum === false); - } - - // If the apex class compiled we will get information from compilation + // Get information from the compilation output information by the Apex compiler on salesforce side (if available) if (record.SymbolTable) { apexClass.innerClassesCount = record.SymbolTable.innerClasses.length || 0; apexClass.interfaces = record.SymbolTable.interfaces; @@ -116,8 +108,22 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset { }); } } + + // Get information directly from the source code (if available) + if (record.Body) { + const sourceCode = record.Body.replaceAll(REGEX_COMMENTS_AND_NEWLINES, ' '); + apexClass.isInterface = sourceCode.match(REGEX_ISINTERFACE) !== null; + apexClass.isEnum = sourceCode.match(REGEX_ISENUM) !== null; + apexClass.isClass = (apexClass.isInterface === false && apexClass.isEnum === false); + + // Specific scanning for Test Classes + if (apexClass.isTest === true) { // this is defined only from the SymbolTable! + apexClass.isTestSeeAllData = sourceCode.match(REGEX_ISTESTSEEALLDATA) !== null; + apexClass.nbSystemAsserts = sourceCode.match(REGEX_TESTNBASSERTS)?.length || 0; + } + } - // Defin type + // Define type if (apexClass.isTest === true) { apexClass.type = 'test'; } else if (apexClass.isInterface === true) { @@ -134,12 +140,6 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset { apexClass.isSharingMissing = true; } - // Specific scanning for Test Classes - if (apexClass.isTest === true) { - apexClass.isTestSeeAllData = record.Body.match(REGEX_ISTESTSEEALLDATA) !== null; - apexClass.nbSystemAsserts = record.Body.match(REGEX_TESTNBASSERTS)?.length || 0; - } - // Add it to the map return [ apexClass.id, apexClass ]; })); diff --git a/force-app/main/default/lwc/orgcheckApp/orgcheckApp.html b/force-app/main/default/lwc/orgcheckApp/orgcheckApp.html index d57df68..59a5291 100644 --- a/force-app/main/default/lwc/orgcheckApp/orgcheckApp.html +++ b/force-app/main/default/lwc/orgcheckApp/orgcheckApp.html @@ -770,7 +770,7 @@

Relationships

diff --git a/force-app/main/default/lwc/orgcheckApp/orgcheckApp.js b/force-app/main/default/lwc/orgcheckApp/orgcheckApp.js index c481425..df7eba2 100644 --- a/force-app/main/default/lwc/orgcheckApp/orgcheckApp.js +++ b/force-app/main/default/lwc/orgcheckApp/orgcheckApp.js @@ -785,6 +785,7 @@ export default class OrgCheckApp extends LightningElement { { label: 'API Version', type: 'numeric', data: { value: 'apiVersion' }, modifier: { valueIfEmpty: 'No version.' }}, { label: 'Package', type: 'text', data: { value: 'package' }}, { label: 'Size', type: 'numeric', data: { value: 'length' }}, + { label: 'Nb Asserts', type: 'numeric', data: { value: 'nbSystemAsserts' }, modifier: { valueIfEmpty: 'No direct usage of Assert.Xxx() or System.assertXxx().' }}, { label: 'Methods', type: 'numeric', data: { value: 'methodsCount' }}, { label: 'Inner Classes', type: 'numeric', data: { value: 'innerClassesCount' }}, { label: 'Sharing', type: 'text', data: { value: 'specifiedSharing' }, modifier: { valueIfEmpty: 'Not specified.' }},