Skip to content

Commit

Permalink
fix: If the global config is not found, do not pretend it was. (#1079)
Browse files Browse the repository at this point in the history
* fix: If the global config is not found, do not pretend it was.

* Update README.md

* dev: have tests reflect that the filename is not present if config is empty.
  • Loading branch information
Jason3S committed Mar 18, 2021
1 parent 2d39c79 commit fb07679
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The cspell mono-repo, a spell checker for code.

## Support Future Development

[![](https://github.com/streetsidesoftware/cspell/raw/master/resources/100px-Green_Patreon_Donate_Shield_Badge.png)](https://www.patreon.com/streetsidesoftware)
[![Patreon](https://github.com/streetsidesoftware/cspell/raw/master/resources/100px-Green_Patreon_Donate_Shield_Badge.png)](https://www.patreon.com/streetsidesoftware)

## Packages

Expand Down
9 changes: 9 additions & 0 deletions packages/cspell-lib/src/Settings/GlobalSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ describe('Validate GlobalSettings', () => {
const path = getGlobalConfigPath();
const s = getRawGlobalSettings();
expect(s).toEqual({
source: {
name: 'CSpell Configstore',
filename: undefined,
},
});
mockSetData('version', '0.2.0');
const s2 = getRawGlobalSettings();
expect(s2).toEqual({
version: '0.2.0',
source: {
name: 'CSpell Configstore',
filename: path,
Expand Down
14 changes: 9 additions & 5 deletions packages/cspell-lib/src/Settings/GlobalSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ export function getRawGlobalSettings(): GlobalSettingsWithSource {

try {
const cfgStore = new ConfigStore(packageName);
Object.assign(globalConf, cfgStore.all);
globalConf.source = {
name,
filename: cfgStore.path,
};
const cfg = cfgStore.all;
// Only populate globalConf is there are values.
if (cfg && Object.keys(cfg).length) {
Object.assign(globalConf, cfg);
globalConf.source = {
name,
filename: cfgStore.path,
};
}
} catch (error) {
logError(error);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/Settings/link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Validate Link.ts', () => {
expect(r).toEqual({
list: [],
globalSettings: {
source: { filename: configFileLocation, name: 'CSpell Configstore' },
source: { filename: undefined, name: 'CSpell Configstore' },
},
});
expect(mockSetData).not.toHaveBeenCalled();
Expand Down

0 comments on commit fb07679

Please sign in to comment.