Skip to content

Commit

Permalink
fix: Always add a new line at the end of (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Sep 17, 2021
1 parent 23cf6fd commit 62b7894
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ exports[`Validate configFileReadWrite update package.json 1`] = `
"
`;

exports[`Validate configFileReadWrite write cspell.config.json 1`] = `
"// This is a Json file with comments.
{
// Version should be 0.2
\\"version\\": \\"0.2\\",
// Custom terms should be here.
\\"words\\": [],
// Words to be ignored
\\"ignoreWords\\": []
}
"
`;

exports[`Validate configFileReadWrite write cspell.config.yaml 1`] = `
"version: \\"0.2\\"
words: []
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/settings/configFileReadWrite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Validate configFileReadWrite', () => {
test.each`
filename | initialContent
${'cspell.json'} | ${undefined}
${'cspell.config.json'} | ${toJson(parseJsonc('{}'))}
${'cspell.jsonc'} | ${undefined}
${'cspell.config.yaml'} | ${undefined}
${'package.json'} | ${toJson(samplePackageJson)}
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/settings/configFileReadWrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ class ConfigFileReaderWriterJson extends AbstractConfigFileReaderWriter {

async write(cfg: CSpellSettings): Promise<void> {
await this.mkdir();
return fs.writeFile(this.uri.fsPath, stringifyJson(cfg));
const json = stringifyJson(cfg);
const content = json[json.length - 1] !== '\n' ? json + '\n' : json;
return fs.writeFile(this.uri.fsPath, content);
}

async _read(): Promise<CSpellSettings> {
Expand Down

0 comments on commit 62b7894

Please sign in to comment.