mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-11-03 19:59:11 +08:00
Major updates to Puppeteer (Chromium roll and updates to types: https://github.com/puppeteer/puppeteer/blob/0b5969dea9048dc34a4d2e109e96c42e8928182c/CHANGELOG.md#800-2021-02-26) and Sinon (unaffected by browser support changes). DISABLE_THIRD_PARTY_CHECK=NPM updates R=jacktfranklin@chromium.org Fixed: 1176642 Change-Id: I419300fc573e8086b4a7b3b6281c81602890f8d0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2782553 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
112 lines
2.9 KiB
JavaScript
112 lines
2.9 KiB
JavaScript
// @ts-nocheck
|
|
|
|
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const declarationValueIndex = require('../../utils/declarationValueIndex');
|
|
const getDeclarationValue = require('../../utils/getDeclarationValue');
|
|
const isStandardSyntaxFunction = require('../../utils/isStandardSyntaxFunction');
|
|
const keywordSets = require('../../reference/keywordSets');
|
|
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
|
|
const report = require('../../utils/report');
|
|
const ruleMessages = require('../../utils/ruleMessages');
|
|
const setDeclarationValue = require('../../utils/setDeclarationValue');
|
|
const validateOptions = require('../../utils/validateOptions');
|
|
const valueParser = require('postcss-value-parser');
|
|
|
|
const ruleName = 'function-name-case';
|
|
|
|
const messages = ruleMessages(ruleName, {
|
|
expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
|
|
});
|
|
|
|
const mapLowercaseFunctionNamesToCamelCase = new Map();
|
|
|
|
keywordSets.camelCaseFunctionNames.forEach((func) => {
|
|
mapLowercaseFunctionNamesToCamelCase.set(func.toLowerCase(), func);
|
|
});
|
|
|
|
function rule(expectation, options, context) {
|
|
return (root, result) => {
|
|
const validOptions = validateOptions(
|
|
result,
|
|
ruleName,
|
|
{
|
|
actual: expectation,
|
|
possible: ['lower', 'upper'],
|
|
},
|
|
{
|
|
actual: options,
|
|
possible: {
|
|
ignoreFunctions: [_.isString, _.isRegExp],
|
|
},
|
|
optional: true,
|
|
},
|
|
);
|
|
|
|
if (!validOptions) {
|
|
return;
|
|
}
|
|
|
|
root.walkDecls((decl) => {
|
|
let needFix = false;
|
|
const parsed = valueParser(getDeclarationValue(decl));
|
|
|
|
parsed.walk((node) => {
|
|
if (node.type !== 'function' || !isStandardSyntaxFunction(node)) {
|
|
return;
|
|
}
|
|
|
|
const functionName = node.value;
|
|
const functionNameLowerCase = functionName.toLowerCase();
|
|
|
|
const ignoreFunctions = (options && options.ignoreFunctions) || [];
|
|
|
|
if (ignoreFunctions.length > 0 && matchesStringOrRegExp(functionName, ignoreFunctions)) {
|
|
return;
|
|
}
|
|
|
|
let expectedFunctionName = null;
|
|
|
|
if (
|
|
expectation === 'lower' &&
|
|
mapLowercaseFunctionNamesToCamelCase.has(functionNameLowerCase)
|
|
) {
|
|
expectedFunctionName = mapLowercaseFunctionNamesToCamelCase.get(functionNameLowerCase);
|
|
} else if (expectation === 'lower') {
|
|
expectedFunctionName = functionNameLowerCase;
|
|
} else {
|
|
expectedFunctionName = functionName.toUpperCase();
|
|
}
|
|
|
|
if (functionName === expectedFunctionName) {
|
|
return;
|
|
}
|
|
|
|
if (context.fix) {
|
|
needFix = true;
|
|
node.value = expectedFunctionName;
|
|
|
|
return;
|
|
}
|
|
|
|
report({
|
|
message: messages.expected(functionName, expectedFunctionName),
|
|
node: decl,
|
|
index: declarationValueIndex(decl) + node.sourceIndex,
|
|
result,
|
|
ruleName,
|
|
});
|
|
});
|
|
|
|
if (context.fix && needFix) {
|
|
setDeclarationValue(decl, parsed.toString());
|
|
}
|
|
});
|
|
};
|
|
}
|
|
|
|
rule.ruleName = ruleName;
|
|
rule.messages = messages;
|
|
module.exports = rule;
|