-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCK-8001: remove trailing comma before last deactivated column (#26)
* HCK-8001: remove trailing comma before last deactivated column * Revert "HCK-8001: remove trailing comma before last deactivated column" This reverts commit 219a67c. * HCK-8001: remove trailing comma before last deactivated column * HCK-8001: add comma commenting for last activated column statement
- Loading branch information
1 parent
d5d65e6
commit 76867db
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
forward_engineering/utils/joinActivatedAndDeactivatedStatements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @param {{ | ||
* index: number; | ||
* numberOfStatements: number; | ||
* lastIndexOfActivatedStatement: number; | ||
* delimiter: string; | ||
* }} | ||
* @return {string} | ||
* */ | ||
const getDelimiter = ({ index, numberOfStatements, lastIndexOfActivatedStatement, delimiter }) => { | ||
const isLastStatement = index === numberOfStatements - 1; | ||
const isLastActivatedStatement = index === lastIndexOfActivatedStatement; | ||
|
||
if (isLastStatement) { | ||
return ''; | ||
} | ||
|
||
if (isLastActivatedStatement) { | ||
return ' --' + delimiter; | ||
} | ||
|
||
return delimiter; | ||
}; | ||
|
||
/** | ||
* @param {{ | ||
* statements?: string[]; | ||
* delimiter?: string; | ||
* indent?: string; | ||
* }} | ||
* @return {string} | ||
* */ | ||
const joinActivatedAndDeactivatedStatements = ({ statements = [], delimiter = ',', indent = '\n' }) => { | ||
const lastIndexOfActivatedStatement = statements.findLastIndex(statement => !statement.startsWith('--')); | ||
const numberOfStatements = statements.length; | ||
|
||
return statements | ||
.map((statement, index) => { | ||
const currentDelimiter = getDelimiter({ | ||
index, | ||
numberOfStatements, | ||
lastIndexOfActivatedStatement, | ||
delimiter, | ||
}); | ||
|
||
return statement + currentDelimiter; | ||
}) | ||
.join(indent); | ||
}; | ||
|
||
module.exports = { | ||
joinActivatedAndDeactivatedStatements, | ||
}; |