Skip to content

Commit

Permalink
Support WITH SECURITY_ENFORCED (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangmai committed Dec 17, 2018
1 parent d778f9d commit a973839
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0-alpha.4
- Support `WITH SECURITY_ENFORCED` in SOQL ([issue](https://github.com/dangmai/prettier-plugin-apex/issues/9)).
- Fix `npm scripts` pointing to old files.

## 1.0.0-alpha.3

- Fix DML operation having double indents ([issue](https://github.com/dangmai/prettier-plugin-apex/issues/8)).
Expand Down
6 changes: 6 additions & 0 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,15 @@ function handleWhereInnerExpression(path, print) {
}

function handleQuery(path, print) {
const withIdentifierDocs = path.map(print, "withIdentifiers");
const parts = [];
parts.push(path.call(print, "select"));
parts.push(path.call(print, "from"));
_pushIfExist(parts, path.call(print, "where", "value"));
_pushIfExist(parts, path.call(print, "with", "value"));
if (withIdentifierDocs.length > 0) {
parts.push(join(" ", withIdentifierDocs));
}
_pushIfExist(parts, path.call(print, "groupBy", "value"));
_pushIfExist(parts, path.call(print, "orderBy", "value"));
_pushIfExist(parts, path.call(print, "limit", "value"));
Expand Down Expand Up @@ -2202,6 +2206,8 @@ nodeHandler[apexNames.SEARCH_USING_CLAUSE] = (path, print) =>
nodeHandler[apexNames.USING_TYPE] = handleUsingType;
nodeHandler[apexNames.BIND_CLAUSE] = handleBindClause;
nodeHandler[apexNames.BIND_EXPRESSION] = handleBindExpression;
nodeHandler[apexNames.WITH_IDENTIFIER] = (path, print) =>
concat(["WITH", " ", path.call(print, "identifier")]);

function handleTrailingEmptyLines(doc, node) {
if (node.trailingEmptyLine) {
Expand Down
1 change: 1 addition & 0 deletions src/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const values = {
WITH_DATA_CATEGORIES: "apex.jorje.data.soql.WithClause$WithDataCategories",
DATA_CATEGORY: "apex.jorje.data.soql.DataCategory",
DATA_CATEGORY_OPERATOR: "apex.jorje.data.soql.DataCategoryOperator",
WITH_IDENTIFIER: "apex.jorje.data.soql.WithIdentifier",
},
BINARY: {
ADDITION: "+",
Expand Down
6 changes: 6 additions & 0 deletions tests/soql/SOQLClass.cls
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class SOQLClass {
Contact[] fullOrder = [SELECT Id FROM Contact ORDER BY Name ASC NULLS FIRST];
}

void withIdentifiersSoql() {
Account[] withSecurityEnforced = [SELECT Id FROM Account WITH SECURITY_ENFORCED];
Account[] withRandomIdentifiers = [SELECT Id FROM Account WITH SECURITY_ENFORCED WITH RANDOM_IDENTIFIER];
Account[] withIdentifierOrder = [SELECT Id FROM Account WHERE Name = 'Hello' WITH SECURITY_ENFORCED GROUP BY Id];
}

void nicheSoql() {
Contact[] forView = [SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW];
Contact[] forReference = [SELECT Name, ID FROM Contact LIMIT 1 FOR REFERENCE];
Expand Down
26 changes: 26 additions & 0 deletions tests/soql/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class SOQLClass {
Contact[] fullOrder = [SELECT Id FROM Contact ORDER BY Name ASC NULLS FIRST];
}
void withIdentifiersSoql() {
Account[] withSecurityEnforced = [SELECT Id FROM Account WITH SECURITY_ENFORCED];
Account[] withRandomIdentifiers = [SELECT Id FROM Account WITH SECURITY_ENFORCED WITH RANDOM_IDENTIFIER];
Account[] withIdentifierOrder = [SELECT Id FROM Account WHERE Name = 'Hello' WITH SECURITY_ENFORCED GROUP BY Id];
}
void nicheSoql() {
Contact[] forView = [SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW];
Contact[] forReference = [SELECT Name, ID FROM Contact LIMIT 1 FOR REFERENCE];
Expand Down Expand Up @@ -369,6 +375,26 @@ class SOQLClass {
];
}
void withIdentifiersSoql() {
Account[] withSecurityEnforced = [
SELECT Id
FROM Account
WITH SECURITY_ENFORCED
];
Account[] withRandomIdentifiers = [
SELECT Id
FROM Account
WITH SECURITY_ENFORCED WITH RANDOM_IDENTIFIER
];
Account[] withIdentifierOrder = [
SELECT Id
FROM Account
WHERE Name = 'Hello'
WITH SECURITY_ENFORCED
GROUP BY Id
];
}
void nicheSoql() {
Contact[] forView = [SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW];
Contact[] forReference = [
Expand Down
Binary file not shown.
Binary file modified vendor/apex-ast-serializer/lib/apex-jorje-lsp.jar
Binary file not shown.

0 comments on commit a973839

Please sign in to comment.