Repository: FHIR/sushi (ts)

Issue:
SUSHI should warn on unused configuration properties in FSHOnly mode
When `sushi-config.yaml` is set to `FSHOnly: true`, many of the config properties are ignored (since SUSHI will not create an ImplementationGuide JSON file).  So... if an author does set these properties in `sushi-config.yaml`, it's very likely a mistake.

We should determine what properties are used in FSHOnly mode and what properties are extraneous -- and warn on the use of any extraneous ones when `FSHOnly` is `true`.

Pull request:
Warn on unused config properties in FSHOnly projects
In FSHOnly projects, only a small subset of config properties are used: `canonical`, `fhirVersion`, `version`, `dependencies`, `instanceOptions`, and `applyExtensionMetadataToRoot`.  If SUSHI encounters any other properties in a FSHOnly project, it should warn the user, since this is likely a mistake.

We already had code that warned on certain properties, but it was only a subset and missed some important ones.  Rather than use a ban-list, we use an allow-list now.

Fixes #1051 

Patch:
diff --git a/package.json b/package.json
index 90ac60f..ae24971 100644
--- a/package.json
+++ b/package.json
@@ -98,4 +98,4 @@
     "winston": "^3.3.3",
     "yaml": "^1.9.2"
   }
-}
\ No newline at end of file
+}
diff --git a/src/import/ensureConfigurationFile.ts b/src/import/ensureConfigurationFile.ts
index 01813ca..26d0dd9 100644
--- a/src/import/ensureConfigurationFile.ts
+++ b/src/import/ensureConfigurationFile.ts
@@ -3,10 +3,9 @@ import fs from 'fs-extra';
 import { logger } from '../utils/FSHLogger';
 
 /**
- * Checks for a sushi-config.yaml or sushi-config.yml file. If it finds one, it returns its path, otherwise it creates one
- * and then returns the new file's path.
+ * Checks for a sushi-config.yaml or sushi-config.yml file. If it finds one, it returns its path,
+ * otherwise it returns undefined.
  * @param root - the root path of the FSH Tank
- * @param allowFromScratch - create a config file from scratch even if package.json isn't found
  * @returns {string|undefined} path to the config file or undefined if it couldn't find or create one
  */
 export function ensureConfiguration(root: string): string {
diff --git a/src/import/importConfiguration.ts b/src/import/importConfiguration.ts
index 1b37d1d..530676c 100644
--- a/src/import/importConfiguration.ts
+++ b/src/import/importConfiguration.ts
@@ -48,24 +48,18 @@ import {
 import { FshCode } from '../fshtypes';
 import { YAMLConfigurationInstanceOptions } from '.';
 
+// Minimal properties needed for any FSH project
 const MINIMAL_CONFIG_PROPERTIES = ['canonical', 'fhirVersion'];
-// Properties that are only relevant when an IG is going to be generated from output, and have no informational purpose
+// Additional minimal properties needed for an IG-producing project (i.e. FSHOnly === false)
 const MINIMAL_IG_ONLY_PROPERTIES = ['id', 'name', 'status', 'copyrightYear', 'releaseLabel'];
-const IG_ONLY_PROPERTIES = [
-  'contained',
-  'extension',
-  'modifierExtension',
-  'groups',
-  'resources',
-  'pages',
-  'parameters',
-  'template',
-  'templates',
-  'menu',
-  'copyrightyear',
-  'copyrightYear',
-  'releaseLabel',
-  'releaselabel'
+// Allowed properties for FSH Only projects (all other properties are irrelevant)
+const ALLOWED_FSH_ONLY_PROPERTIES = [
+  ...MINIMAL_CONFIG_PROPERTIES,
+  'version',
+  'dependencies',
+  'instanceOptions',
+  'applyExtensionMetadataToRoot',
+  'FSHOnly'
 ];
 
 /**
@@ -174,14 +168,14 @@ export function importConfiguration(yaml: YAMLConfiguration | string, file: stri
 
   if (yaml.FSHOnly) {
     // If no IG is being generated, emit warning when IG specific properties are used in config
-    const unusedProperties = Object.keys(yaml).filter((p: keyof YAMLConfiguration) =>
-      IG_ONLY_PROPERTIES.includes(p)
+    const unusedProperties = Object.keys(yaml).filter(
+      (p: any) => !ALLOWED_FSH_ONLY_PROPERTIES.includes(p)
     );
     if (unusedProperties.length > 0) {
       logger.warn(
         `The FSHOnly property is set to true, so no output specific to IG creation will be generated. The following properties are unused and only relevant for IG creation: ${unusedProperties.join(
           ', '
-        )}.`,
+        )}. Consider removing these properties from sushi-config.yaml.`,
         { file }
       );
     }


Test patch:
diff --git a/test/import/importConfiguration.test.ts b/test/import/importConfiguration.test.ts
index d515d42..420cbb3 100644
--- a/test/import/importConfiguration.test.ts
+++ b/test/import/importConfiguration.test.ts
@@ -2295,7 +2295,7 @@ describe('importConfiguration', () => {
       minYAML.FSHOnly = true;
       const config = importConfiguration(minYAML, 'test-config.yaml');
       expect(loggerSpy.getLastMessage('warn')).toMatch(
-        /The following properties are unused and only relevant for IG creation: copyrightYear, releaseLabel, template, menu, contained.*File: test-config.yaml/s
+        /The following properties are unused and only relevant for IG creation: id, name, status, copyrightYear, releaseLabel, template, menu, contained\..*File: test-config.yaml/s
       );
       expect(config.FSHOnly).toBe(true);
     });