forcedotcom / sfdx-scanner

MIT License
212 stars 49 forks source link

[BUG] The Salesforce scanner throws a syntax error in an Apex class when using the GROUPING function in a SOQL query #1579

Open ashishrajbanshi opened 3 weeks ago

ashishrajbanshi commented 3 weeks ago

Have you tried to resolve this issue yourself first?

Yes

Bug Description

By updating scanner from @salesforce/sfdx-scanner 3.15.0 to @salesforce/sfdx-scanner 4.3.2, we are facing syntax error when using command sf scanner run --engine pmd,retire-js --pmdconfig .pmdruleset.xml --format html --target class_name.cls -o src_pmd.html --severity-threshold 2

Method of the class:

private List<AggregateResult> getDefects(){ AggregateResult[] defects = [SELECT object NC, object Part, object Lot, SUM(Defective_Quantity__c) defectiveQuantity, GROUPING(object1) NCGroup, GROUPING(object2) PartGroup, GROUPING(object3) LotGroup FROM object4 WHERE object IN :ncsIdSet WITH SECURITY_ENFORCED GROUP BY ROLLUP(object, object, object)]; return defects; }

Screenshot:

image

Error:

``

Output / Logs

Warning: Plugin @salesforce/sfdx-scanner (4.3.2) differs from the version specified by sf (4.4.0) Warning: The input format for array arguments has changed. Use this format: --array-flag value1 --array-flag value2 --array-flag value3
Warning: We're continually improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA
Warning: PMD failed to evaluate against file 'D:\WORK\SQX\sqx_11\SQX_NonConformance_Fetcher.cls'. Message: ParseException: Parse exception: com.google.summit.SummitAST$ParseException: Failed to parse D:\WORK\SQX\sqx_11\SQX_NonConformance_Fetcher.cls: Syntax error at 200:48: mismatched input '(' expecting {'after', 'before', 'get', 'inherited', 'instanceof', 'set', 'sharing', 'switch', 'transient', 'trigger', 'when', 'with', 'without', 'system', 'user', 'select', 'count', 'from', 'as', 'using', 'scope', 'where', 'order', 'by', 'limit', 'and', 'or', 'not', 'avg', 'count_distinct', 'min', 'max', 'sum', 'typeof', 'end', 'then', 'like', 'in', 'includes', 'excludes', 'asc', 'desc', 'nulls', 'first', 'last', 'group', 'all', 'rows', 'view', 'having', 'rollup', 'tolabel', 'offset', 'data', 'category', 'at', 'above', 'below', 'above_or_below', 'security_enforced', 'system_mode', 'user_mode', 'reference', 'cube', 'format', 'tracking', 'viewstat', 'custom', 'standard', 'distance', 'geolocation', 'calendar_month', 'calendar_quarter', 'calendar_year', 'day_in_month', 'day_in_week', 'day_in_year', 'day_only', 'fiscal_month', 'fiscal_quarter', 'fiscal_year', 'hour_in_day', 'week_in_month', 'week_in_year', 'converttimezone', 'yesterday', 'today', 'tomorrow', 'last_week', 'this_week', 'next_week', 'last_month', 'this_month', 'next_month', 'last_90_days', 'next_90_days', 'last_n_days', 'next_n_days', 'n_days_ago', 'next_n_weeks', 'last_n_weeks', 'n_weeks_ago', 'next_n_months', 'last_n_months', 'n_months_ago', 'this_quarter', 'last_quarter', 'next_quarter', 'next_n_quarters', 'last_n_quarters', 'n_quarters_ago', 'this_year', 'last_year', 'next_year', 'next_n_years', 'last_n_years', 'n_years_ago', 'this_fiscal_quarter', 'last_fiscal_quarter', 'next_fiscal_quarter', 'next_n_fiscal_quarters', 'last_n_fiscal_quarters', 'n_fiscal_quarters_ago', 'this_fiscal_year', 'last_fiscal_year', 'next_fiscal_year', 'next_n_fiscal_years', 'last_n_fiscal_years', 'n_fiscal_years_ago', IntegralCurrencyLiteral, 'find', 'email', 'name', 'phone', 'sidebar', 'fields', 'metadata', 'pricebookid', 'network', 'snippet', 'target_length', 'division', 'returning', 'listview', ',', '.', Identifier} Syntax error at 200:79: mismatched input ',' expecting {'instanceof', '[', ';', '.', '=', '>', '<', '?.', '?', '==', '===', '!=', '<>', '!==', '&&', '||', '??', '++', '--', '+', '-', '', '/', '&', '|', '^', '+=', '-=', '=', '/=', '&=', '|=', '^=', '<<=', '>>=', '>>>='} Syntax error at 201:48: missing ';' at '(' Syntax error at 201:71: mismatched input ',' expecting {'instanceof', '[', ';', '.', '=', '>', '<', '?.', '?', '==', '===', '!=', '<>', '!==', '&&', '||', '??', '++', '--', '+', '-', '*'Syntax error at 204:40: missing ';' at 'WHERE' Syntax error at 204:68: missing ';' at 'IN' Syntax error at 204:86: missing ';' at 'SECURITY_ENFORCED' Syntax error at 205:46: missing ';' at 'BY' Syntax error at 205:55: missing ';' at '(' Syntax error at 206:8: extraneous input 'return' expecting {'abstract', 'after', 'before', 'class', 'enum', 'final', 'get', 'global', 'inherited', 'instanceof', 'interface', 'override', 'private', 'protected', 'public', 'set', 'sharing', 'static', 'switch', 'testmethod', 'transient', 'trigger', 'virtual', 'void', 'webservice', 'when', 'with', 'without', 'list', 'map', 'system', 'user', 'select', 'count', 'from', 'as', 'using', 'scope', 'where', 'order', 'by', 'limit', 'and', 'or', 'not', 'avg', 'count_distinct', 'min', 'max', 'sum', 'typeof', 'end', 'then', 'like', 'in', 'includes', 'excludes', 'asc', 'desc', 'nulls', 'first', 'last', 'group', 'all', 'rows', 'view', 'having', 'rollup', 'tolabel', 'offset', 'data', 'category', 'at', 'above', 'below', 'above_or_below', 'security_enforced', 'system_mode', 'user_mode', 'reference', 'cube', 'format', 'tracking', 'viewstat', 'custom', 'standard', 'distance', 'geolocation', 'calendar_month', 'calendar_quarter', 'calendar_year', 'day_in_month', 'day_in_week', 'day_in_year', 'day_only', 'fiscal_month', 'fiscal_quarter', 'fiscal_year', 'hour_in_day', 'week_in_month', 'week_in_year', 'converttimezone', 'yesterday', 'today', 'tomorrow', 'last_week', 'this_week', 'next_week', 'last_month', 'this_month', 'next_month', 'last_90_days', 'next_90_days', 'last_n_days', 'next_n_days', 'n_days_ago', 'next_n_weeks', 'last_n_weeks', 'n_weeks_ago', 'next_n_months', 'last_n_months', 'n_months_ago', 'this_quarter', 'last_quarter', 'next_quarter', 'next_n_quarters', 'last_n_quarters', 'n_quarters_ago', 'this_year', 'last_year', 'next_year', 'next_n_years', 'last_n_years', 'n_years_ago', 'this_fiscal_quarter', 'last_fiscal_quarter', 'next_fiscal_quarter', 'next_n_fiscal_quarters', 'last_n_fiscal_quarters', 'n_fiscal_quarters_ago', 'this_fiscal_year', 'last_fiscal_year', 'next_fiscal_year', 'next_n_fiscal_years', 'last_n_fiscal_years', 'n_fiscal_years_ago', IntegralCurrencyLiteral, 'find', 'email', 'name', 'phone', 'sidebar', 'fields', 'metadata', 'pricebookid', 'network', 'snippet', 'target_length', 'division', 'returning', 'listview', '{', '}', ';', '@', Identifier} Syntax error at 209:4: mismatched input 'private' expecting

Steps To Reproduce

Update to @salesforce/sfdx-scanner 4.3.2

Expected Behavior

A proper scan of the class

Operating System

Ubuntu, windows

Salesforce CLI Version

@salesforce/cli/2.55.6 win32-x64 node-v18.12.0

Code Analyzer Plugin (@salesforce/sfdx-scanner) Version

@salesforce/sfdx-scanner 4.3.2

Additional Context (Screenshots, Files, etc)

No response

Workaround

No response

Urgency

High

johnbelosf commented 3 weeks ago

Thank you @ashishrajbanshi - I can't reproduce the exact error, but I can see that if I include your code snippet in one of my files, they are ignored when parsing.

This seems to be a gap in PMD. They switched parsing engines between the one we used in Code Analyzer 3 (PMD 6) and Code Analyzer 4 (PMD 7).

We'll investigate and raise it accordingly.

ashishrajbanshi commented 3 weeks ago

@johnbelosf , can you please update the status of the issue ?

stephen-carter-at-sf commented 2 weeks ago

Created PMD issue: https://github.com/pmd/pmd/issues/5182

Will keep this open until PMD has fixed the issue and we have incorporated their updates into Salesforce Code Analyzer