mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-05 11:31:31 +08:00
This also adds CC-BY-4.0 to the list of accepted licenses. DISABLE_THIRD_PARTY_CHECK=update dependencies Bug: chromium:1083142 Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org>
75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
// @ts-nocheck
|
|
|
|
'use strict';
|
|
|
|
const isStandardSyntaxRule = require('../utils/isStandardSyntaxRule');
|
|
const parseSelector = require('../utils/parseSelector');
|
|
const report = require('../utils/report');
|
|
const styleSearch = require('style-search');
|
|
|
|
module.exports = function (options) {
|
|
options.root.walkRules((rule) => {
|
|
if (!isStandardSyntaxRule(rule)) {
|
|
return;
|
|
}
|
|
|
|
if (!rule.selector.includes('[') || !rule.selector.includes('=')) {
|
|
return;
|
|
}
|
|
|
|
let hasFixed = false;
|
|
const selector = rule.raws.selector ? rule.raws.selector.raw : rule.selector;
|
|
|
|
const fixedSelector = parseSelector(selector, options.result, rule, (selectorTree) => {
|
|
selectorTree.walkAttributes((attributeNode) => {
|
|
const operator = attributeNode.operator;
|
|
|
|
if (!operator) {
|
|
return;
|
|
}
|
|
|
|
const attributeNodeString = attributeNode.toString();
|
|
|
|
styleSearch({ source: attributeNodeString, target: operator }, (match) => {
|
|
const index = options.checkBeforeOperator ? match.startIndex : match.endIndex - 1;
|
|
|
|
checkOperator(attributeNodeString, index, rule, attributeNode, operator);
|
|
});
|
|
});
|
|
});
|
|
|
|
if (hasFixed) {
|
|
if (!rule.raws.selector) {
|
|
rule.selector = fixedSelector;
|
|
} else {
|
|
rule.raws.selector.raw = fixedSelector;
|
|
}
|
|
}
|
|
|
|
function checkOperator(source, index, node, attributeNode, operator) {
|
|
options.locationChecker({
|
|
source,
|
|
index,
|
|
err: (m) => {
|
|
if (options.fix && options.fix(attributeNode)) {
|
|
hasFixed = true;
|
|
|
|
return;
|
|
}
|
|
|
|
report({
|
|
message: m.replace(
|
|
options.checkBeforeOperator ? operator[0] : operator[operator.length - 1],
|
|
operator,
|
|
),
|
|
node,
|
|
index: attributeNode.sourceIndex + index,
|
|
result: options.result,
|
|
ruleName: options.checkedRuleName,
|
|
});
|
|
},
|
|
});
|
|
}
|
|
});
|
|
};
|