Skip to content

Commit 2c35c69

Browse files
committed
Make cfnFileType private settable only
1 parent 7a51ff0 commit 2c35c69

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/document/Document.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Document {
1010
private readonly log = LoggerFactory.getLogger(Document);
1111
public readonly extension: string;
1212
public readonly documentType: DocumentType;
13-
public cfnFileType: CloudFormationFileType;
13+
private _cfnFileType: CloudFormationFileType;
1414
public readonly fileName: string;
1515
private tabSize: number;
1616
private cachedParsedContent: unknown;
@@ -29,29 +29,33 @@ export class Document {
2929
this.extension = extension;
3030
this.documentType = type;
3131
this.fileName = uriToPath(uri).base;
32-
this.cfnFileType = CloudFormationFileType.Unknown;
32+
this._cfnFileType = CloudFormationFileType.Unknown;
3333

3434
this.updateCfnFileType();
3535
this.tabSize = fallbackTabSize;
3636
this.processIndentation(detectIndentation, fallbackTabSize);
3737
}
3838

39+
public get cfnFileType(): CloudFormationFileType {
40+
return this._cfnFileType;
41+
}
42+
3943
public updateCfnFileType(): void {
4044
const content = this.textDocument.getText();
4145
if (!content.trim()) {
42-
this.cfnFileType = CloudFormationFileType.Unknown;
46+
this._cfnFileType = CloudFormationFileType.Unknown;
4347
this.cachedParsedContent = undefined;
4448
return;
4549
}
4650

4751
try {
4852
this.cachedParsedContent = this.parseContent();
49-
this.cfnFileType = this.detectCfnFileType();
53+
this._cfnFileType = this.detectCfnFileType();
5054
} catch {
5155
// If parsing fails, leave cfnFileType unchanged and clear cache
5256
this.cachedParsedContent = undefined;
5357
this.log.debug(
54-
`Failed to parse document ${this.textDocument.uri}, keeping cfnFileType as ${this.cfnFileType}`,
58+
`Failed to parse document ${this.textDocument.uri}, keeping cfnFileType as ${this._cfnFileType}`,
5559
);
5660
}
5761
}

tst/unit/handlers/DocumentHandler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('DocumentHandler', () => {
2828

2929
function createMockDocument(cfnFileType = CloudFormationFileType.Template) {
3030
const doc = new Document(createTextDocument());
31-
(doc as any).cfnFileType = cfnFileType;
31+
(doc as any)._cfnFileType = cfnFileType;
3232
return doc;
3333
}
3434

0 commit comments

Comments
 (0)