From 23420b2d13ad504f349e5cf9f9363fe3e48ae648 Mon Sep 17 00:00:00 2001 From: Schmop Date: Sat, 13 Jan 2024 00:06:05 +0100 Subject: [PATCH 01/11] Do not warn about nesting css selectors when firefoxStrictMinVersion is >= 117 Co-authored-by: JimKnoxx --- src/messages/css.js | 4 +++- src/rules/css/invalidNesting.js | 14 +++++++++++++- src/utils.js | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/messages/css.js b/src/messages/css.js index 78468c645f..f677883f54 100644 --- a/src/messages/css.js +++ b/src/messages/css.js @@ -11,5 +11,7 @@ export const CSS_SYNTAX_ERROR = { export const INVALID_SELECTOR_NESTING = { code: 'INVALID_SELECTOR_NESTING', message: i18n._('Invalid nesting of selectors found'), - description: i18n._(`Selectors should not be nested`), + description: i18n._( + `Selector nesting is supported from firefox version 117.0 and above` + ), }; diff --git a/src/rules/css/invalidNesting.js b/src/rules/css/invalidNesting.js index 9667249e8c..64c77461cf 100644 --- a/src/rules/css/invalidNesting.js +++ b/src/rules/css/invalidNesting.js @@ -1,10 +1,22 @@ import * as messages from 'messages'; +import { basicCompatVersionComparisonGEQ } from '../../utils'; + +const CSS_NESTING_MIN_VERSION = 117; + export function invalidNesting( cssNode, filename, - { startLine, startColumn } = {} + { startLine, startColumn, addonMetadata } = {} ) { + if ( + basicCompatVersionComparisonGEQ( + addonMetadata?.firefoxMinVersion, + CSS_NESTING_MIN_VERSION + ) + ) { + return []; + } const messageList = []; if (cssNode.type === 'rule') { for (let i = 0; i < cssNode.nodes.length; i++) { diff --git a/src/utils.js b/src/utils.js index 45c1d671b2..c93fa4ac2c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -415,11 +415,26 @@ export function androidStrictMinVersion(manifestJson) { return version; } +/** + * @param {*} versionAdded + * @param {number} minVersion + * @returns {boolean} true if versionAdded has a strictly greater major version than minVersion + */ export function basicCompatVersionComparison(versionAdded, minVersion) { const asNumber = parseInt(versionAdded, 10); return !Number.isNaN(asNumber) && asNumber > minVersion; } +/** + * @param {*} versionAdded + * @param {number} minVersion + * @returns {boolean} true if versionAdded has a greater or equal major version than minVersion + */ +export function basicCompatVersionComparisonGEQ(versionAdded, minVersion) { + const asNumber = parseInt(versionAdded, 10); + return !Number.isNaN(asNumber) && asNumber >= minVersion; +} + /** * @param {*} supportInfo - bcd support info of a feature * @returns {string|boolean} The first version number to support the feature From 18d158571499c07979822d4aa756935cb75d7188 Mon Sep 17 00:00:00 2001 From: Schmop Date: Sat, 13 Jan 2024 09:58:15 +0100 Subject: [PATCH 02/11] Add tests for invalid nesting and new version comparison --- src/parsers/manifestjson.js | 14 +++++++++++ src/scanners/base.js | 12 +++++++++ tests/unit/rules/css/test.invalidNesting.js | 23 +++++++++++++++++- tests/unit/test.utils.js | 27 +++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/parsers/manifestjson.js b/src/parsers/manifestjson.js index 32bd18f25b..a3bd1fa4af 100644 --- a/src/parsers/manifestjson.js +++ b/src/parsers/manifestjson.js @@ -47,6 +47,17 @@ import { } from 'utils'; import BLOCKED_CONTENT_SCRIPT_HOSTS from 'blocked_content_script_hosts.txt'; +/** + * @typedef {Object} Metadata + * @property {string} id + * @property {number} manifestVersion + * @property {string} name + * @property {number} type + * @property {string} version + * @property {string} firefoxMinVersion + * @property {Set} experimentApiPaths + */ + async function getStreamImageSize(stream) { const chunks = []; for await (const chunk of stream) { @@ -1285,6 +1296,9 @@ export default class ManifestJSONParser extends JSONParser { return apiPaths; } + /** + * @returns {Metadata} + */ getMetadata() { return { id: this.getAddonId(), diff --git a/src/scanners/base.js b/src/scanners/base.js index 4004c9b1bf..ef7121ac3f 100644 --- a/src/scanners/base.js +++ b/src/scanners/base.js @@ -27,6 +27,18 @@ export default class BaseScanner { throw new Error('scannerName is not implemented'); } + /** + * @typedef {Object} ScannerOptions + * @property {import('../parsers/manifestjson').Metadata} addonMetadata + * @property {import('../collector').default} collector + * @property {string[]} disabledRules + * @property {string[]} existingFiles + * @property {boolean} privileged + * + * @param {string|Buffer|import('stream').Readable} contents + * @param {string} filename + * @param {ScannerOptions} options + */ constructor(contents, filename, options = {}) { this.contents = contents; this.filename = filename; diff --git a/tests/unit/rules/css/test.invalidNesting.js b/tests/unit/rules/css/test.invalidNesting.js index cfbcf96781..b91e8695a7 100644 --- a/tests/unit/rules/css/test.invalidNesting.js +++ b/tests/unit/rules/css/test.invalidNesting.js @@ -12,7 +12,11 @@ describe('CSS Rule InvalidNesting', () => { height: 100px; } }`; - const cssScanner = new CSSScanner(code, 'fakeFile.css'); + const cssScanner = new CSSScanner(code, 'fakeFile.css', { + addonMetadata: { + firefoxStrictMinVersion: '60.5', + }, + }); const { linterMessages } = await cssScanner.scan(); expect(linterMessages.length).toEqual(1); @@ -22,6 +26,23 @@ describe('CSS Rule InvalidNesting', () => { expect(linterMessages[0].type).toEqual(VALIDATION_WARNING); }); + it('should not report invalid nesting on sufficient version', async () => { + const code = oneLine`/* I'm a comment */ + #something { + .bar { + height: 100px; + } + }`; + const cssScanner = new CSSScanner(code, 'fakeFile.css', { + addonMetadata: { + firefoxMinVersion: '117.0.1', + }, + }); + + const { linterMessages } = await cssScanner.scan(); + expect(linterMessages.length).toEqual(0); + }); + it('should not detect invalid nesting', async () => { const code = oneLine`/* I'm a comment */ @media only screen and (max-width: 959px) { diff --git a/tests/unit/test.utils.js b/tests/unit/test.utils.js index 43b91aec51..834bbb7378 100644 --- a/tests/unit/test.utils.js +++ b/tests/unit/test.utils.js @@ -5,6 +5,7 @@ import { AddonsLinterUserError, androidStrictMinVersion, basicCompatVersionComparison, + basicCompatVersionComparisonGEQ, buildI18nObject, checkMinNodeVersion, ensureFilenameExists, @@ -602,11 +603,37 @@ describe('basicCompatVersionComparison', () => { expect(basicCompatVersionComparison('61', 60)).toBe(true); }); + it('should return false when version added is equals than min version', () => { + expect(basicCompatVersionComparison('61.5.2', 61)).toBe(false); + }); + it('should return false when version added is smaller than min version', () => { expect(basicCompatVersionComparison('59', 60)).toBe(false); }); }); +describe('basicCompatVersionComparisonEQ', () => { + it('should return false when version added is a boolean', () => { + expect(basicCompatVersionComparisonGEQ(false, 60)).toBe(false); + }); + + it('should return false when version added is undefined', () => { + expect(basicCompatVersionComparisonGEQ(undefined, 60)).toBe(false); + }); + + it('should return true when version added is bigger than min version', () => { + expect(basicCompatVersionComparisonGEQ('61', 60)).toBe(true); + }); + + it('should return true when version added is equals than min version', () => { + expect(basicCompatVersionComparisonGEQ('61.5.2', 61)).toBe(true); + }); + + it('should return false when version added is smaller than min version', () => { + expect(basicCompatVersionComparisonGEQ('59', 60)).toBe(false); + }); +}); + describe('isCompatible', () => { const getBCD = (data) => ({ webextensions: { From 625216775255d226a9c98335f65835b06adbcf30 Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 25 Jan 2024 12:13:58 +0100 Subject: [PATCH 03/11] Removed basicCompatVersionComparisonGEQ in favor of basicCompatVersionComparison --- src/rules/css/invalidNesting.js | 7 ++++--- src/utils.js | 10 ---------- tests/unit/test.utils.js | 25 +------------------------ 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/src/rules/css/invalidNesting.js b/src/rules/css/invalidNesting.js index 64c77461cf..259eef6f97 100644 --- a/src/rules/css/invalidNesting.js +++ b/src/rules/css/invalidNesting.js @@ -1,8 +1,9 @@ import * as messages from 'messages'; -import { basicCompatVersionComparisonGEQ } from '../../utils'; +import { basicCompatVersionComparison } from '../../utils'; -const CSS_NESTING_MIN_VERSION = 117; +// Allowed version is 117.0 and above +const CSS_NESTING_MIN_VERSION = 116; export function invalidNesting( cssNode, @@ -10,7 +11,7 @@ export function invalidNesting( { startLine, startColumn, addonMetadata } = {} ) { if ( - basicCompatVersionComparisonGEQ( + basicCompatVersionComparison( addonMetadata?.firefoxMinVersion, CSS_NESTING_MIN_VERSION ) diff --git a/src/utils.js b/src/utils.js index c93fa4ac2c..9795f7deb3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -425,16 +425,6 @@ export function basicCompatVersionComparison(versionAdded, minVersion) { return !Number.isNaN(asNumber) && asNumber > minVersion; } -/** - * @param {*} versionAdded - * @param {number} minVersion - * @returns {boolean} true if versionAdded has a greater or equal major version than minVersion - */ -export function basicCompatVersionComparisonGEQ(versionAdded, minVersion) { - const asNumber = parseInt(versionAdded, 10); - return !Number.isNaN(asNumber) && asNumber >= minVersion; -} - /** * @param {*} supportInfo - bcd support info of a feature * @returns {string|boolean} The first version number to support the feature diff --git a/tests/unit/test.utils.js b/tests/unit/test.utils.js index 834bbb7378..17afae85db 100644 --- a/tests/unit/test.utils.js +++ b/tests/unit/test.utils.js @@ -5,7 +5,6 @@ import { AddonsLinterUserError, androidStrictMinVersion, basicCompatVersionComparison, - basicCompatVersionComparisonGEQ, buildI18nObject, checkMinNodeVersion, ensureFilenameExists, @@ -603,7 +602,7 @@ describe('basicCompatVersionComparison', () => { expect(basicCompatVersionComparison('61', 60)).toBe(true); }); - it('should return false when version added is equals than min version', () => { + it('should return false when version added is equal to min version', () => { expect(basicCompatVersionComparison('61.5.2', 61)).toBe(false); }); @@ -612,28 +611,6 @@ describe('basicCompatVersionComparison', () => { }); }); -describe('basicCompatVersionComparisonEQ', () => { - it('should return false when version added is a boolean', () => { - expect(basicCompatVersionComparisonGEQ(false, 60)).toBe(false); - }); - - it('should return false when version added is undefined', () => { - expect(basicCompatVersionComparisonGEQ(undefined, 60)).toBe(false); - }); - - it('should return true when version added is bigger than min version', () => { - expect(basicCompatVersionComparisonGEQ('61', 60)).toBe(true); - }); - - it('should return true when version added is equals than min version', () => { - expect(basicCompatVersionComparisonGEQ('61.5.2', 61)).toBe(true); - }); - - it('should return false when version added is smaller than min version', () => { - expect(basicCompatVersionComparisonGEQ('59', 60)).toBe(false); - }); -}); - describe('isCompatible', () => { const getBCD = (data) => ({ webextensions: { From aef74aa7f6ed4c5db357fbe2051df972a812df94 Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 25 Jan 2024 12:14:33 +0100 Subject: [PATCH 04/11] Fixed formatting --- src/messages/css.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/messages/css.js b/src/messages/css.js index f677883f54..3fb64256b3 100644 --- a/src/messages/css.js +++ b/src/messages/css.js @@ -11,7 +11,5 @@ export const CSS_SYNTAX_ERROR = { export const INVALID_SELECTOR_NESTING = { code: 'INVALID_SELECTOR_NESTING', message: i18n._('Invalid nesting of selectors found'), - description: i18n._( - `Selector nesting is supported from firefox version 117.0 and above` - ), + description: i18n._(`Selector nesting is supported from firefox version 117.0 and above`), }; From 83c51cd553aacfc7f8605425942ed2e3357a1aef Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 25 Jan 2024 12:15:23 +0100 Subject: [PATCH 05/11] Added a test, that checks for exactly the minimal allowed version of css nesting --- tests/unit/rules/css/test.invalidNesting.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unit/rules/css/test.invalidNesting.js b/tests/unit/rules/css/test.invalidNesting.js index b91e8695a7..6144929010 100644 --- a/tests/unit/rules/css/test.invalidNesting.js +++ b/tests/unit/rules/css/test.invalidNesting.js @@ -43,6 +43,23 @@ describe('CSS Rule InvalidNesting', () => { expect(linterMessages.length).toEqual(0); }); + it('should not report invalid nesting on minimal allowed version', async () => { + const code = oneLine`/* I'm a comment */ + #something { + .bar { + height: 100px; + } + }`; + const cssScanner = new CSSScanner(code, 'fakeFile.css', { + addonMetadata: { + firefoxMinVersion: '117.0.0', + }, + }); + + const { linterMessages } = await cssScanner.scan(); + expect(linterMessages.length).toEqual(0); + }); + it('should not detect invalid nesting', async () => { const code = oneLine`/* I'm a comment */ @media only screen and (max-width: 959px) { From e151a122f4b642ee885be4ca5e4de3a87c087371 Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 25 Jan 2024 12:15:46 +0100 Subject: [PATCH 06/11] Move type documentations of MetaData closer to getMetadata --- src/parsers/manifestjson.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/parsers/manifestjson.js b/src/parsers/manifestjson.js index a3bd1fa4af..b160062bb0 100644 --- a/src/parsers/manifestjson.js +++ b/src/parsers/manifestjson.js @@ -47,17 +47,6 @@ import { } from 'utils'; import BLOCKED_CONTENT_SCRIPT_HOSTS from 'blocked_content_script_hosts.txt'; -/** - * @typedef {Object} Metadata - * @property {string} id - * @property {number} manifestVersion - * @property {string} name - * @property {number} type - * @property {string} version - * @property {string} firefoxMinVersion - * @property {Set} experimentApiPaths - */ - async function getStreamImageSize(stream) { const chunks = []; for await (const chunk of stream) { @@ -1297,6 +1286,15 @@ export default class ManifestJSONParser extends JSONParser { } /** + * @typedef {Object} Metadata + * @property {string} id + * @property {number} manifestVersion + * @property {string} name + * @property {number} type + * @property {string} version + * @property {string} firefoxMinVersion + * @property {Set} experimentApiPaths + * * @returns {Metadata} */ getMetadata() { From 01d6e709070b8c66b6118b1906854591e889761d Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 25 Jan 2024 22:56:36 +0100 Subject: [PATCH 07/11] Fix style to calm prettier --- src/messages/css.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/messages/css.js b/src/messages/css.js index 3fb64256b3..f677883f54 100644 --- a/src/messages/css.js +++ b/src/messages/css.js @@ -11,5 +11,7 @@ export const CSS_SYNTAX_ERROR = { export const INVALID_SELECTOR_NESTING = { code: 'INVALID_SELECTOR_NESTING', message: i18n._('Invalid nesting of selectors found'), - description: i18n._(`Selector nesting is supported from firefox version 117.0 and above`), + description: i18n._( + `Selector nesting is supported from firefox version 117.0 and above` + ), }; From c4e0b7c63c35e2fcdd9a6dc7ff9e1e3595f1a5dd Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 1 Feb 2024 17:05:51 +0100 Subject: [PATCH 08/11] Apply code style suggestions --- src/messages/css.js | 5 +-- src/rules/css/invalidNesting.js | 1 + tests/unit/rules/css/test.invalidNesting.js | 41 +++++++-------------- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/messages/css.js b/src/messages/css.js index f677883f54..6c33f1b8e4 100644 --- a/src/messages/css.js +++ b/src/messages/css.js @@ -11,7 +11,6 @@ export const CSS_SYNTAX_ERROR = { export const INVALID_SELECTOR_NESTING = { code: 'INVALID_SELECTOR_NESTING', message: i18n._('Invalid nesting of selectors found'), - description: i18n._( - `Selector nesting is supported from firefox version 117.0 and above` - ), + description: i18n._(`Selector nesting is supported from firefox version 117.0 + and above`), }; diff --git a/src/rules/css/invalidNesting.js b/src/rules/css/invalidNesting.js index 259eef6f97..b8cf9733d9 100644 --- a/src/rules/css/invalidNesting.js +++ b/src/rules/css/invalidNesting.js @@ -18,6 +18,7 @@ export function invalidNesting( ) { return []; } + const messageList = []; if (cssNode.type === 'rule') { for (let i = 0; i < cssNode.nodes.length; i++) { diff --git a/tests/unit/rules/css/test.invalidNesting.js b/tests/unit/rules/css/test.invalidNesting.js index 6144929010..ecf05ea419 100644 --- a/tests/unit/rules/css/test.invalidNesting.js +++ b/tests/unit/rules/css/test.invalidNesting.js @@ -26,39 +26,24 @@ describe('CSS Rule InvalidNesting', () => { expect(linterMessages[0].type).toEqual(VALIDATION_WARNING); }); - it('should not report invalid nesting on sufficient version', async () => { - const code = oneLine`/* I'm a comment */ - #something { - .bar { - height: 100px; - } - }`; - const cssScanner = new CSSScanner(code, 'fakeFile.css', { - addonMetadata: { - firefoxMinVersion: '117.0.1', - }, - }); - - const { linterMessages } = await cssScanner.scan(); - expect(linterMessages.length).toEqual(0); - }); - - it('should not report invalid nesting on minimal allowed version', async () => { - const code = oneLine`/* I'm a comment */ + it.each(['117.0.0', '117.0.1'])( + 'should not report invalid nesting when firefoxMinVersion=%s', + async (firefoxMinVersion) => { + const code = oneLine`/* I'm a comment */ #something { .bar { height: 100px; } }`; - const cssScanner = new CSSScanner(code, 'fakeFile.css', { - addonMetadata: { - firefoxMinVersion: '117.0.0', - }, - }); - - const { linterMessages } = await cssScanner.scan(); - expect(linterMessages.length).toEqual(0); - }); + const cssScanner = new CSSScanner(code, 'fakeFile.css', { + addonMetadata: { + firefoxMinVersion, + }, + }); + const { linterMessages } = await cssScanner.scan(); + expect(linterMessages.length).toEqual(0); + } + ); it('should not detect invalid nesting', async () => { const code = oneLine`/* I'm a comment */ From 7fe86b08bde6b89ea085cf9b121ff756eab9de4a Mon Sep 17 00:00:00 2001 From: Schmop Date: Wed, 7 Feb 2024 11:36:48 +0100 Subject: [PATCH 09/11] Reverse version comparison call order --- src/rules/css/invalidNesting.js | 9 +++--- tests/unit/rules/css/test.invalidNesting.js | 33 +++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/rules/css/invalidNesting.js b/src/rules/css/invalidNesting.js index b8cf9733d9..b51eab8f8e 100644 --- a/src/rules/css/invalidNesting.js +++ b/src/rules/css/invalidNesting.js @@ -3,7 +3,7 @@ import * as messages from 'messages'; import { basicCompatVersionComparison } from '../../utils'; // Allowed version is 117.0 and above -const CSS_NESTING_MIN_VERSION = 116; +const CSS_NESTING_MIN_VERSION = 117; export function invalidNesting( cssNode, @@ -11,9 +11,10 @@ export function invalidNesting( { startLine, startColumn, addonMetadata } = {} ) { if ( - basicCompatVersionComparison( - addonMetadata?.firefoxMinVersion, - CSS_NESTING_MIN_VERSION + addonMetadata?.firefoxMinVersion && + !basicCompatVersionComparison( + CSS_NESTING_MIN_VERSION, + addonMetadata?.firefoxMinVersion ) ) { return []; diff --git a/tests/unit/rules/css/test.invalidNesting.js b/tests/unit/rules/css/test.invalidNesting.js index ecf05ea419..4ec67b11d5 100644 --- a/tests/unit/rules/css/test.invalidNesting.js +++ b/tests/unit/rules/css/test.invalidNesting.js @@ -5,28 +5,31 @@ import { VALIDATION_WARNING } from 'const'; import CSSScanner from 'scanners/css'; describe('CSS Rule InvalidNesting', () => { - it('should detect invalid nesting', async () => { - const code = oneLine`/* I'm a comment */ + it.each(['60.5', '116.0', '116'])( + 'should detect invalid nesting when firefoxMinVersion=%s', + async (firefoxMinVersion) => { + const code = oneLine`/* I'm a comment */ #something { .bar { height: 100px; } }`; - const cssScanner = new CSSScanner(code, 'fakeFile.css', { - addonMetadata: { - firefoxStrictMinVersion: '60.5', - }, - }); + const cssScanner = new CSSScanner(code, 'fakeFile.css', { + addonMetadata: { + firefoxMinVersion, + }, + }); - const { linterMessages } = await cssScanner.scan(); - expect(linterMessages.length).toEqual(1); - expect(linterMessages[0].code).toEqual( - messages.INVALID_SELECTOR_NESTING.code - ); - expect(linterMessages[0].type).toEqual(VALIDATION_WARNING); - }); + const { linterMessages } = await cssScanner.scan(); + expect(linterMessages.length).toEqual(1); + expect(linterMessages[0].code).toEqual( + messages.INVALID_SELECTOR_NESTING.code + ); + expect(linterMessages[0].type).toEqual(VALIDATION_WARNING); + } + ); - it.each(['117.0.0', '117.0.1'])( + it.each(['117', '117.0', '117.1', '117.0.0', '117.0.1'])( 'should not report invalid nesting when firefoxMinVersion=%s', async (firefoxMinVersion) => { const code = oneLine`/* I'm a comment */ From 43f315b41d3ff5e2f97b086799c9f26993967005 Mon Sep 17 00:00:00 2001 From: Schmop Date: Wed, 7 Feb 2024 14:17:21 +0100 Subject: [PATCH 10/11] Add failing testcases --- tests/unit/rules/css/test.invalidNesting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/rules/css/test.invalidNesting.js b/tests/unit/rules/css/test.invalidNesting.js index 4ec67b11d5..cff50a05b8 100644 --- a/tests/unit/rules/css/test.invalidNesting.js +++ b/tests/unit/rules/css/test.invalidNesting.js @@ -5,7 +5,7 @@ import { VALIDATION_WARNING } from 'const'; import CSSScanner from 'scanners/css'; describe('CSS Rule InvalidNesting', () => { - it.each(['60.5', '116.0', '116'])( + it.each(['60.5', '116.0', '116', '116.1', '116.0.1', '116.0.0'])( 'should detect invalid nesting when firefoxMinVersion=%s', async (firefoxMinVersion) => { const code = oneLine`/* I'm a comment */ From 4c5a8905eaf29b8d986a8183d00ef201db2e4b43 Mon Sep 17 00:00:00 2001 From: Schmop Date: Thu, 8 Feb 2024 23:24:34 +0100 Subject: [PATCH 11/11] Add firefoxStrictMinVersion to Metadata object Co-authored-by: William Durand --- src/parsers/manifestjson.js | 5 +++++ src/rules/css/invalidNesting.js | 5 ++--- tests/unit/rules/css/test.invalidNesting.js | 16 ++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/parsers/manifestjson.js b/src/parsers/manifestjson.js index b160062bb0..7b4dae8f65 100644 --- a/src/parsers/manifestjson.js +++ b/src/parsers/manifestjson.js @@ -1293,6 +1293,7 @@ export default class ManifestJSONParser extends JSONParser { * @property {number} type * @property {string} version * @property {string} firefoxMinVersion + * @property {string} firefoxStrictMinVersion * @property {Set} experimentApiPaths * * @returns {Metadata} @@ -1304,10 +1305,14 @@ export default class ManifestJSONParser extends JSONParser { name: this.parsedJSON.name, type: PACKAGE_EXTENSION, version: this.parsedJSON.version, + // This is the `strict_min_version` value set in the `manifest.json` file + // for Firefox for desktop. firefoxMinVersion: this.parsedJSON.applications && this.parsedJSON.applications.gecko && this.parsedJSON.applications.gecko.strict_min_version, + // This is the strict min *major* version for Firefox for desktop. + firefoxStrictMinVersion: firefoxStrictMinVersion(this.parsedJSON), experimentApiPaths: this.getExperimentApiPaths(), }; } diff --git a/src/rules/css/invalidNesting.js b/src/rules/css/invalidNesting.js index b51eab8f8e..dcb111f136 100644 --- a/src/rules/css/invalidNesting.js +++ b/src/rules/css/invalidNesting.js @@ -2,7 +2,6 @@ import * as messages from 'messages'; import { basicCompatVersionComparison } from '../../utils'; -// Allowed version is 117.0 and above const CSS_NESTING_MIN_VERSION = 117; export function invalidNesting( @@ -11,10 +10,10 @@ export function invalidNesting( { startLine, startColumn, addonMetadata } = {} ) { if ( - addonMetadata?.firefoxMinVersion && + addonMetadata?.firefoxStrictMinVersion && !basicCompatVersionComparison( CSS_NESTING_MIN_VERSION, - addonMetadata?.firefoxMinVersion + addonMetadata?.firefoxStrictMinVersion ) ) { return []; diff --git a/tests/unit/rules/css/test.invalidNesting.js b/tests/unit/rules/css/test.invalidNesting.js index cff50a05b8..a6c7dcf442 100644 --- a/tests/unit/rules/css/test.invalidNesting.js +++ b/tests/unit/rules/css/test.invalidNesting.js @@ -5,9 +5,9 @@ import { VALIDATION_WARNING } from 'const'; import CSSScanner from 'scanners/css'; describe('CSS Rule InvalidNesting', () => { - it.each(['60.5', '116.0', '116', '116.1', '116.0.1', '116.0.0'])( - 'should detect invalid nesting when firefoxMinVersion=%s', - async (firefoxMinVersion) => { + it.each([60, 116])( + 'should detect invalid nesting when firefoxStrictMinVersion=%s', + async (firefoxStrictMinVersion) => { const code = oneLine`/* I'm a comment */ #something { .bar { @@ -16,7 +16,7 @@ describe('CSS Rule InvalidNesting', () => { }`; const cssScanner = new CSSScanner(code, 'fakeFile.css', { addonMetadata: { - firefoxMinVersion, + firefoxStrictMinVersion, }, }); @@ -29,9 +29,9 @@ describe('CSS Rule InvalidNesting', () => { } ); - it.each(['117', '117.0', '117.1', '117.0.0', '117.0.1'])( - 'should not report invalid nesting when firefoxMinVersion=%s', - async (firefoxMinVersion) => { + it.each([117, 118])( + 'should not report invalid nesting when firefoxStrictMinVersion=%s', + async (firefoxStrictMinVersion) => { const code = oneLine`/* I'm a comment */ #something { .bar { @@ -40,7 +40,7 @@ describe('CSS Rule InvalidNesting', () => { }`; const cssScanner = new CSSScanner(code, 'fakeFile.css', { addonMetadata: { - firefoxMinVersion, + firefoxStrictMinVersion, }, }); const { linterMessages } = await cssScanner.scan();