Skip to content

Commit 2d6685e

Browse files
dannyvassallojoshfried-aws
authored andcommitted
fix(typescript-library): Organize types and add missing slash aws-cloudformation#532
1 parent 195ffab commit 2d6685e

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

guard/ts-lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const formatOutput = ({ result, rulesNames, dataNames }) => {
1313
const output = JSON.parse(JSON.stringify(result).replace(dataPattern, (match, index) => {
1414
const fileIndex = parseInt(index, 10) - 1;
1515
const fileName = dataNames[fileIndex];
16-
return fileName ? fileName.split(isWindows ? '\\' : '/').join('') : match;
16+
return fileName ? (isWindows ? fileName.split('\\').join('/') : fileName) : match;
1717
}).replace(rulesPattern, (match, index) => {
1818
const ruleIndex = parseInt(index, 10) - 1;
1919
const ruleName = rulesNames[ruleIndex];

guard/ts-lib/index.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export type SarifShortDescription = {
8181
text: string;
8282
}
8383

84+
type ValidateParams = {
85+
dataPath: string;
86+
rulesPath: string;
87+
}
88+
8489
const formatOutput = ({ result, rulesNames, dataNames }: FormatOutputParams): SarifReport => {
8590
const dataPattern = /DATA_STDIN\[(\d+)\]/g;
8691
const rulesPattern = /RULES_STDIN\[(\d+)\]\/DEFAULT/g;
@@ -90,7 +95,7 @@ const formatOutput = ({ result, rulesNames, dataNames }: FormatOutputParams): Sa
9095
const fileIndex = parseInt(index, 10) - 1;
9196
const fileName = dataNames[fileIndex];
9297

93-
return fileName ? fileName.split(isWindows ? '\\' : '/').join('') : match;
98+
return fileName ? (isWindows ? fileName.split('\\').join('/') : fileName) : match;
9499
}).replace(rulesPattern, (match: string, index: string) => {
95100
const ruleIndex = parseInt(index, 10) - 1;
96101
const ruleName = rulesNames[ruleIndex];
@@ -104,31 +109,26 @@ const formatOutput = ({ result, rulesNames, dataNames }: FormatOutputParams): Sa
104109
return JSON.parse(output);
105110
};
106111

107-
async function readFiles(dirPath: string, supportedExtensions: string[]): Promise<TraversalResult> {
108-
const fileNames: string[] = [];
109-
const fileContents: string[] = [];
110-
111-
const files = await fs.promises.readdir(dirPath, { withFileTypes: true });
112-
const readPromises = files.map(async (file) => {
113-
const filePath = path.join(dirPath, file.name);
114-
if (!file.isDirectory() && supportedExtensions.includes(path.extname(filePath))) {
115-
const content = await fs.promises.readFile(filePath, 'utf8');
116-
fileNames.push(filePath);
117-
fileContents.push(content);
118-
}
119-
});
120-
await Promise.all(readPromises);
121-
122-
return {
123-
fileContents,
124-
fileNames,
125-
};
126-
}
127-
128-
type ValidateParams = {
129-
dataPath: string;
130-
rulesPath: string;
131-
}
112+
async function readFiles(dirPath: string, supportedExtensions: string[]): Promise<TraversalResult> {
113+
const fileNames: string[] = [];
114+
const fileContents: string[] = [];
115+
116+
const files = await fs.promises.readdir(dirPath, { withFileTypes: true });
117+
const readPromises = files.map(async (file) => {
118+
const filePath = path.join(dirPath, file.name);
119+
if (!file.isDirectory() && supportedExtensions.includes(path.extname(filePath))) {
120+
const content = await fs.promises.readFile(filePath, 'utf8');
121+
fileNames.push(filePath);
122+
fileContents.push(content);
123+
}
124+
});
125+
await Promise.all(readPromises);
126+
127+
return {
128+
fileContents,
129+
fileNames,
130+
};
131+
}
132132

133133
export const validate = async ({ rulesPath, dataPath }: ValidateParams): Promise<SarifReport> => {
134134
const rulesResult = await readFiles(rulesPath, RULE_FILE_SUPPORTED_EXTENSIONS);

0 commit comments

Comments
 (0)