-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCK-8007: add comma commenting for last activated column statement (#149
- Loading branch information
1 parent
c2912bf
commit ca0d3fc
Showing
2 changed files
with
56 additions
and
3 deletions.
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, | ||
}; |