Skip to content

Commit

Permalink
chore: Tighten up defaults for filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyJones committed May 29, 2024
1 parent 4cff799 commit 1a1cfa7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/connectors/filesystemVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const createFileContentsVisitor =
}
logger.debug(`Successfully read file contents: ${filePath}`);
visitor(fileContents, {
basename: path.basename(filePath, path.extname(filePath)),
filename: path.basename(filePath),
extension: path.extname(filePath),
fullPath: filePath,
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/filesystemWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const writeFileExclusive = (
};

const cleanName = (example: Example, printer: Printer) => {
const extension = `${printer.extension.startsWith('.') ? '' : '.'}${printer.extension}`;
const extension = `${example.context.extension}${printer.extension.startsWith('.') ? '' : '.'}${printer.extension}`;
const sanitisedName = sanitize(`${example.name}${extension}`);
if (sanitisedName === extension) {
const message = `${example.context.fullPath}: After sanitisation, the example named '${sanitisedName}' was an empty string. You will need to rename it`;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/exampleExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const extractExampleSections = (

if (partialExample === undefined && startMatch) {
partialExample = {
name: startMatch[2] || `${context.filename}-${count}`,
name: startMatch[2] || `${context.basename}-${count}`,
lines: [],
};
count += 1;
Expand Down
1 change: 1 addition & 0 deletions src/domain/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ExampleLocation {
basename: string;
filename: string;
extension: string;
fullPath: string;
Expand Down

0 comments on commit 1a1cfa7

Please sign in to comment.