Repository: manusa/electronim
Pull request #353 (2023-10-12 06:43:28)

🐛 en-us dictionary has a new different key (en)

sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=manusa_electronim&pullRequest=353)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=353&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=353&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=353&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=CODE_SMELL)

[![62.5%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '62.5%')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_coverage&view=list) [62.5% Coverage](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_coverage&view=list)  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_duplicated_lines_density&view=list)

![warning](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/message_warning-16px.png 'warning') The version of Java (11.0.3) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more [here](https://docs.sonarcloud.io/appendices/scanner-environment/)




![idea](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png 'idea') Catch issues before they fail your Quality Gate with our IDE extension ![sonarlint](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png 'sonarlint') [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=sonarcloud-welcome)
sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=manusa_electronim&pullRequest=353)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=353&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=353&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=353&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=353&resolved=false&types=CODE_SMELL)

[![100.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100-16px.png '100.0%')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_coverage&view=list) [100.0% Coverage](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_coverage&view=list)  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=353&metric=new_duplicated_lines_density&view=list)

![warning](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/message_warning-16px.png 'warning') The version of Java (11.0.3) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more [here](https://docs.sonarcloud.io/appendices/scanner-environment/)




Patch:
diff --git a/package-lock.json b/package-lock.json
index 61176af..30575e8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,8 +13,8 @@
         "dictionary-ca": "2.6.0",
         "dictionary-ca-valencia": "2.6.0",
         "dictionary-de": "2.0.4",
+        "dictionary-en": "3.2.0",
         "dictionary-en-gb": "2.4.0",
-        "dictionary-en-us": "3.0.0",
         "dictionary-es": "3.2.0",
         "dictionary-eu": "3.2.0",
         "dictionary-fr": "2.8.0",
@@ -3597,6 +3597,15 @@
         "url": "https://github.com/sponsors/wooorm"
       }
     },
+    "node_modules/dictionary-en": {
+      "version": "3.2.0",
+      "resolved": "https://registry.npmjs.org/dictionary-en/-/dictionary-en-3.2.0.tgz",
+      "integrity": "sha512-oujbJhuplUTlDntmOoultEcNyk8ge7cFI6yXNn7eJvpbBJOhGNhWtK0XjOJsiwl4EfIeyvDKwGB95vJXv1d+lQ==",
+      "funding": {
+        "type": "github",
+        "url": "https://github.com/sponsors/wooorm"
+      }
+    },
     "node_modules/dictionary-en-gb": {
       "version": "2.4.0",
       "resolved": "https://registry.npmjs.org/dictionary-en-gb/-/dictionary-en-gb-2.4.0.tgz",
@@ -3606,12 +3615,6 @@
         "url": "https://github.com/sponsors/wooorm"
       }
     },
-    "node_modules/dictionary-en-us": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/dictionary-en-us/-/dictionary-en-us-3.0.0.tgz",
-      "integrity": "sha512-hH033rB5pdVb51QBUBleq8z5XajVrs2tVRe26ZvIJzf5/c8BwZKlPXhr7rrW39AxZz5RQQhPpC/RMbmWtWtBUg==",
-      "deprecated": "Deprecated: use dictionary-en instead for English as spoken in the United States"
-    },
     "node_modules/dictionary-es": {
       "version": "3.2.0",
       "resolved": "https://registry.npmjs.org/dictionary-es/-/dictionary-es-3.2.0.tgz",
@@ -12135,16 +12138,16 @@
       "resolved": "https://registry.npmjs.org/dictionary-de/-/dictionary-de-2.0.4.tgz",
       "integrity": "sha512-TOTvLM7k4wJt3cgus1Ziuiqo5Tx0i+VEmXVDCDxsxHhRdSCnAQFonTx8/YlfGI+AQQIyMJhXfMnceKD56dZrMQ=="
     },
+    "dictionary-en": {
+      "version": "3.2.0",
+      "resolved": "https://registry.npmjs.org/dictionary-en/-/dictionary-en-3.2.0.tgz",
+      "integrity": "sha512-oujbJhuplUTlDntmOoultEcNyk8ge7cFI6yXNn7eJvpbBJOhGNhWtK0XjOJsiwl4EfIeyvDKwGB95vJXv1d+lQ=="
+    },
     "dictionary-en-gb": {
       "version": "2.4.0",
       "resolved": "https://registry.npmjs.org/dictionary-en-gb/-/dictionary-en-gb-2.4.0.tgz",
       "integrity": "sha512-zwc7e6CM/+Em+v74a5/ia6663nwR9vvtEayaX5WkgvHD99al1qm/RbcdLludqX3mggYxXXFN1zN5hzyREW/DXg=="
     },
-    "dictionary-en-us": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/dictionary-en-us/-/dictionary-en-us-3.0.0.tgz",
-      "integrity": "sha512-hH033rB5pdVb51QBUBleq8z5XajVrs2tVRe26ZvIJzf5/c8BwZKlPXhr7rrW39AxZz5RQQhPpC/RMbmWtWtBUg=="
-    },
     "dictionary-es": {
       "version": "3.2.0",
       "resolved": "https://registry.npmjs.org/dictionary-es/-/dictionary-es-3.2.0.tgz",
diff --git a/package.json b/package.json
index bbb5c8b..b72ed69 100644
--- a/package.json
+++ b/package.json
@@ -207,7 +207,7 @@
     "dictionary-ca-valencia": "2.6.0",
     "dictionary-de": "2.0.4",
     "dictionary-en-gb": "2.4.0",
-    "dictionary-en-us": "3.0.0",
+    "dictionary-en": "3.2.0",
     "dictionary-es": "3.2.0",
     "dictionary-eu": "3.2.0",
     "dictionary-fr": "2.8.0",
diff --git a/src/settings/index.js b/src/settings/index.js
index 57cb64f..309496c 100644
--- a/src/settings/index.js
+++ b/src/settings/index.js
@@ -25,7 +25,7 @@ const SETTINGS_FILE = 'settings.json';
 const DEFAULT_SETTINGS = {
   tabs: [],
   useNativeSpellChecker: false,
-  enabledDictionaries: ['en-US'],
+  enabledDictionaries: ['en'],
   theme: 'system',
   trayEnabled: false,
   closeButtonBehavior: CLOSE_BUTTON_BEHAVIORS.quit
@@ -62,6 +62,17 @@ const ensureDefaultValues = settings => {
   return {...settings, activeTab};
 };
 
+const migrate = settings => {
+  // en-us dictionary key is now en
+  if (settings.enabledDictionaries.includes('en-US')) {
+    settings.enabledDictionaries = settings.enabledDictionaries
+      .filter(dictionary => dictionary !== 'en-US')
+      .filter(dictionary => dictionary !== 'en')
+      .concat('en');
+  }
+  return settings;
+};
+
 const initAppDir = () => fs.mkdirSync(appDir, {recursive: true});
 
 const loadSettings = () => {
@@ -70,7 +81,7 @@ const loadSettings = () => {
   if (fs.existsSync(settingsPath)) {
     loadedSettings = JSON.parse(fs.readFileSync(settingsPath));
   }
-  return ensureDefaultValues(loadedSettings);
+  return migrate(ensureDefaultValues(loadedSettings));
 };
 
 const writeSettings = settings => {
diff --git a/src/spell-check/index.js b/src/spell-check/index.js
index 45f8264..ea65c15 100644
--- a/src/spell-check/index.js
+++ b/src/spell-check/index.js
@@ -30,7 +30,7 @@ const AVAILABLE_DICTIONARIES = {
   'en-GB': {
     name: 'English (GB)'
   },
-  'en-US': {
+  en: {
     name: 'English (US)'
   },
   es: {


Test patch:
diff --git a/src/settings/__tests__/index.test.js b/src/settings/__tests__/index.test.js
index 561245e..cde5d7e 100644
--- a/src/settings/__tests__/index.test.js
+++ b/src/settings/__tests__/index.test.js
@@ -43,7 +43,7 @@ describe('Settings module test suite', () => {
       expectHomeDirectoryCreated();
       expect(fs.readFileSync).toHaveBeenCalledTimes(1);
       expect(result.tabs).toEqual([]);
-      expect(result.enabledDictionaries).toEqual(['en-US']);
+      expect(result.enabledDictionaries).toEqual(['en']);
       expect(result.theme).toEqual('system');
     });
     test('settings (empty) exist, should load settings from file system and merge with defaults', () => {
@@ -56,7 +56,7 @@ describe('Settings module test suite', () => {
       expectHomeDirectoryCreated();
       expect(fs.readFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'));
       expect(result.tabs).toEqual([]);
-      expect(result.enabledDictionaries).toEqual(['en-US']);
+      expect(result.enabledDictionaries).toEqual(['en']);
       expect(result.theme).toEqual('system');
       expect(result.trayEnabled).toEqual(false);
     });
@@ -70,7 +70,7 @@ describe('Settings module test suite', () => {
       expectHomeDirectoryCreated();
       expect(fs.readFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'));
       expect(result.tabs).toEqual([{id: '1'}]);
-      expect(result.enabledDictionaries).toEqual(['en-US']);
+      expect(result.enabledDictionaries).toEqual(['en']);
       expect(result.activeTab).toBe('1');
       expect(result.otherSetting).toBe(1337);
     });
@@ -84,6 +84,19 @@ describe('Settings module test suite', () => {
       expect(result.tabs).toEqual([{id: '1', disabled: true}, {id: '2'}]);
       expect(result.activeTab).toBe('2');
     });
+    test.each([
+      {enabledDictionaries: ['en-US', 'es'], expected: ['es', 'en']},
+      {enabledDictionaries: ['en-US', 'en', 'es'], expected: ['es', 'en']},
+      {enabledDictionaries: ['en-GB', 'en'], expected: ['en-GB', 'en']}
+    ])('settings with $enabledDictionaries dictionary, should migrate to $expected', ({enabledDictionaries, expected}) => {
+      // Given
+      fs.existsSync.mockImplementationOnce(() => true);
+      fs.readFileSync.mockImplementationOnce(() => JSON.stringify({enabledDictionaries}));
+      // When
+      const result = settings.loadSettings();
+      // Then
+      expect(result.enabledDictionaries).toEqual(expected);
+    });
     test.each([
       {key: 'theme', value: '"light"', expected: 'light'},
       {key: 'activeTab', value: 42, expected: 42},
@@ -110,7 +123,7 @@ describe('Settings module test suite', () => {
       expect(fs.writeFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'),
         '{\n  "tabs": [],\n' +
         '  "useNativeSpellChecker": false,\n' +
-        '  "enabledDictionaries": [\n    "en-US"\n  ],\n' +
+        '  "enabledDictionaries": [\n    "en"\n  ],\n' +
         '  "theme": "system",\n  "trayEnabled": false,\n' +
         '  "closeButtonBehavior": "quit"\n' +
         '}');
@@ -124,7 +137,7 @@ describe('Settings module test suite', () => {
       expect(fs.writeFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'),
         '{\n  "tabs": [\n    {\n      "id": 1337\n    }\n  ],\n' +
         '  "useNativeSpellChecker": false,\n' +
-        '  "enabledDictionaries": [\n    "en-US"\n  ],\n' +
+        '  "enabledDictionaries": [\n    "en"\n  ],\n' +
         '  "theme": "system",\n' +
         '  "trayEnabled": false,\n' +
         '  "closeButtonBehavior": "quit",\n' +
@@ -141,7 +154,7 @@ describe('Settings module test suite', () => {
       expect(fs.writeFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'),
         '{\n  "tabs": [\n    {\n      "id": 1337\n    }\n  ],\n' +
         '  "useNativeSpellChecker": false,\n' +
-        '  "enabledDictionaries": [\n    "en-US"\n  ],\n' +
+        '  "enabledDictionaries": [\n    "en"\n  ],\n' +
         '  "theme": "system",\n' +
         '  "trayEnabled": false,\n' +
         '  "closeButtonBehavior": "quit",\n' +