_compileAddonValidator()

in src/schema/validator.js [395:463]


  _compileAddonValidator(validator) {
    const { minimum, maximum } = this.allowedManifestVersionsRange;
    const manifestVersion = this.addonManifestVersion;

    const replacer = (key, value) => {
      if (Array.isArray(value)) {
        const patchedValue = value.filter((item) => {
          let includeItem = true;
          if (
            item?.min_manifest_version &&
            minimum < item.min_manifest_version
          ) {
            includeItem =
              item.min_manifest_version >= minimum &&
              item.min_manifest_version <= maximum &&
              item.min_manifest_version <= manifestVersion;
          }
          if (
            item?.max_manifest_version &&
            maximum > item.max_manifest_version
          ) {
            includeItem =
              item.max_manifest_version >= minimum &&
              item.max_manifest_version <= maximum &&
              item.max_manifest_version >= manifestVersion;
          }

          return includeItem;
        });
        return patchedValue;
      }
      return value;
    };

    // Omit from the manifest schema data all entries that include a
    // min/max_manifest_version which is outside of the minimum
    // and maximum manifest_version currently allowed per validator
    // config and if they do not apply to the addon manifest_version.
    //
    // NOTE: the rest of the schema data isn't filtered based on the
    // current manifest version.
    //
    // TODO(https://github.com/mozilla/addons-linter/issues/4512):
    // this shouldn't be necessary anymore if we do generate two sets
    // of schema data (one for MV2 and one for MV3) as part of
    // importing and normalizing the JSONSchema data from Firefox.
    const patchedSchemaObject = JSON.parse(
      JSON.stringify(this.schemaObject, replacer, 2)
    );

    const schemaData = deepPatch(patchedSchemaObject, {
      types: {
        ManifestBase: {
          properties: {
            manifest_version: {
              minimum,
              maximum,
            },
          },
        },
      },
    });

    return validator.compile({
      ...schemaData,
      $id: 'manifest',
      $ref: '#/types/WebExtensionManifest',
    });
  }