Skip to content

Commit 1a1cfa7

Browse files
committed
chore: Tighten up defaults for filenames
1 parent 4cff799 commit 1a1cfa7

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

src/connectors/filesystemVisitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const createFileContentsVisitor =
6767
}
6868
logger.debug(`Successfully read file contents: ${filePath}`);
6969
visitor(fileContents, {
70+
basename: path.basename(filePath, path.extname(filePath)),
7071
filename: path.basename(filePath),
7172
extension: path.extname(filePath),
7273
fullPath: filePath,

src/connectors/filesystemWriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const writeFileExclusive = (
3333
};
3434

3535
const cleanName = (example: Example, printer: Printer) => {
36-
const extension = `${printer.extension.startsWith('.') ? '' : '.'}${printer.extension}`;
36+
const extension = `${example.context.extension}${printer.extension.startsWith('.') ? '' : '.'}${printer.extension}`;
3737
const sanitisedName = sanitize(`${example.name}${extension}`);
3838
if (sanitisedName === extension) {
3939
const message = `${example.context.fullPath}: After sanitisation, the example named '${sanitisedName}' was an empty string. You will need to rename it`;

src/domain/exampleExtractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const extractExampleSections = (
3232

3333
if (partialExample === undefined && startMatch) {
3434
partialExample = {
35-
name: startMatch[2] || `${context.filename}-${count}`,
35+
name: startMatch[2] || `${context.basename}-${count}`,
3636
lines: [],
3737
};
3838
count += 1;

src/domain/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface ExampleLocation {
2+
basename: string;
23
filename: string;
34
extension: string;
45
fullPath: string;

0 commit comments

Comments
 (0)