Skip to content

Commit

Permalink
Do not warn about nesting css selectors when firefoxStrictMinVersion …
Browse files Browse the repository at this point in the history
…is >= 117

Co-authored-by: JimKnoxx <imknoxx@knoxx.media>
  • Loading branch information
schmop and JimKnoxx committed Jan 12, 2024
1 parent b893bb0 commit 23420b2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/messages/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
),
};
14 changes: 13 additions & 1 deletion src/rules/css/invalidNesting.js
Original file line number Diff line number Diff line change
@@ -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++) {
Expand Down
15 changes: 15 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23420b2

Please sign in to comment.