diff --git a/src/schema/validator.js b/src/schema/validator.js index 73f53ee5..2ff56cab 100644 --- a/src/schema/validator.js +++ b/src/schema/validator.js @@ -69,21 +69,9 @@ export const validateAddon = (...args) => { return isValid; }; -const _validateLangPack = validator.compile({ - ...schemaObject, - id: 'langpack-manifest', - $ref: '#/types/WebExtensionLangpackManifest', -}); - -export const validateLangPack = (...args) => { - const isValid = _validateLangPack(...args); - validateLangPack.errors = filterErrors(_validateLangPack.errors); - return isValid; -}; - // Create a new schema object that merges theme.json and the regular // manifest.json schema. -// Then modify the result of that to allow `additionalProperties = false` +// Then modify the result of that to set `additionalProperties = false` // so that additional properties are not allowed for themes. // We have to use deepmerge here to make sure we can overwrite the nested // structure and can use object-destructuring at the root level @@ -113,6 +101,34 @@ export const validateStaticTheme = (...args) => { return isValid; }; +// Like with static themes, we don't want additional properties in langpacks. +// The only difference is, this time, there is no additional schema file, we +// just need to reference WebExtensionLangpackManifest and merge it with the +// object that has additionalProperties: false. +const _validateLangPack = validator.compile({ + ...merge( + schemaObject, { + types: { + WebExtensionLangpackManifest: { + $merge: { + with: { + additionalProperties: false, + }, + }, + }, + }, + } + ), + id: 'langpack-manifest', + $ref: '#/types/WebExtensionLangpackManifest', +}); + +export const validateLangPack = (...args) => { + const isValid = _validateLangPack(...args); + validateLangPack.errors = filterErrors(_validateLangPack.errors); + return isValid; +}; + const _validateLocaleMessages = validator.compile({ ...messagesSchemaObject, id: 'messages', diff --git a/tests/unit/parsers/test.manifestjson.js b/tests/unit/parsers/test.manifestjson.js index 3bc13220..ccd72345 100644 --- a/tests/unit/parsers/test.manifestjson.js +++ b/tests/unit/parsers/test.manifestjson.js @@ -1104,6 +1104,22 @@ describe('ManifestJSONParser', () => { ); expect(manifestJSONParser.isValid).toEqual(false); }); + + it('throws warning on additional properties', () => { + const linter = new Linter({ _: ['bar'] }); + const json = validLangpackManifestJSON({ content_scripts: ['foo.js'] }); + const manifestJSONParser = new ManifestJSONParser( + json, linter.collector, { + io: { files: {} }, + } + ); + expect(manifestJSONParser.isValid).toEqual(false); + assertHasMatchingError(linter.collector.errors, { + code: messages.JSON_INVALID.code, + message: '"/content_scripts" is an invalid additional property', + description: 'Your JSON file could not be parsed.', + }); + }); }); describe('static theme', () => {