first commit
This commit is contained in:
75
node_modules/stylelint/lib/rules/no-unknown-custom-properties/index.cjs
generated
vendored
Normal file
75
node_modules/stylelint/lib/rules/no-unknown-custom-properties/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// NOTICE: This file is generated by Rollup. To modify it,
|
||||
// please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
|
||||
'use strict';
|
||||
|
||||
const valueParser = require('postcss-value-parser');
|
||||
const nodeFieldIndices = require('../../utils/nodeFieldIndices.cjs');
|
||||
const isVarFunction = require('../../utils/isVarFunction.cjs');
|
||||
const report = require('../../utils/report.cjs');
|
||||
const ruleMessages = require('../../utils/ruleMessages.cjs');
|
||||
const validateOptions = require('../../utils/validateOptions.cjs');
|
||||
|
||||
const ruleName = 'no-unknown-custom-properties';
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
rejected: (propName) => `Unexpected unknown custom property "${propName}"`,
|
||||
});
|
||||
|
||||
const meta = {
|
||||
url: 'https://stylelint.io/user-guide/rules/no-unknown-custom-properties',
|
||||
};
|
||||
|
||||
/** @type {import('stylelint').CoreRules[ruleName]} */
|
||||
const rule = (primary) => {
|
||||
return (root, result) => {
|
||||
const validOptions = validateOptions(result, ruleName, { actual: primary });
|
||||
|
||||
if (!validOptions) return;
|
||||
|
||||
/** @type {Set<string>} */
|
||||
const declaredCustomProps = new Set();
|
||||
|
||||
root.walkAtRules(/^property$/i, ({ params }) => {
|
||||
declaredCustomProps.add(params);
|
||||
});
|
||||
|
||||
root.walkDecls(/^--/, ({ prop }) => {
|
||||
declaredCustomProps.add(prop);
|
||||
});
|
||||
|
||||
root.walkDecls((decl) => {
|
||||
const { value } = decl;
|
||||
|
||||
const parsedValue = valueParser(value);
|
||||
|
||||
parsedValue.walk((node) => {
|
||||
if (!isVarFunction(node)) return;
|
||||
|
||||
const [firstNode, secondNode] = node.nodes;
|
||||
|
||||
if (!firstNode || declaredCustomProps.has(firstNode.value)) return;
|
||||
|
||||
// Second node (div) indicates fallback exists in all cases
|
||||
if (secondNode && secondNode.type === 'div') return;
|
||||
|
||||
const startIndex = nodeFieldIndices.declarationValueIndex(decl);
|
||||
|
||||
report({
|
||||
result,
|
||||
ruleName,
|
||||
message: messages.rejected,
|
||||
messageArgs: [firstNode.value],
|
||||
node: decl,
|
||||
index: startIndex + firstNode.sourceIndex,
|
||||
endIndex: startIndex + firstNode.sourceEndIndex,
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
rule.ruleName = ruleName;
|
||||
rule.messages = messages;
|
||||
rule.meta = meta;
|
||||
|
||||
module.exports = rule;
|
||||
71
node_modules/stylelint/lib/rules/no-unknown-custom-properties/index.mjs
generated
vendored
Normal file
71
node_modules/stylelint/lib/rules/no-unknown-custom-properties/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import valueParser from 'postcss-value-parser';
|
||||
|
||||
import { declarationValueIndex } from '../../utils/nodeFieldIndices.mjs';
|
||||
import isVarFunction from '../../utils/isVarFunction.mjs';
|
||||
import report from '../../utils/report.mjs';
|
||||
import ruleMessages from '../../utils/ruleMessages.mjs';
|
||||
import validateOptions from '../../utils/validateOptions.mjs';
|
||||
|
||||
const ruleName = 'no-unknown-custom-properties';
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
rejected: (propName) => `Unexpected unknown custom property "${propName}"`,
|
||||
});
|
||||
|
||||
const meta = {
|
||||
url: 'https://stylelint.io/user-guide/rules/no-unknown-custom-properties',
|
||||
};
|
||||
|
||||
/** @type {import('stylelint').CoreRules[ruleName]} */
|
||||
const rule = (primary) => {
|
||||
return (root, result) => {
|
||||
const validOptions = validateOptions(result, ruleName, { actual: primary });
|
||||
|
||||
if (!validOptions) return;
|
||||
|
||||
/** @type {Set<string>} */
|
||||
const declaredCustomProps = new Set();
|
||||
|
||||
root.walkAtRules(/^property$/i, ({ params }) => {
|
||||
declaredCustomProps.add(params);
|
||||
});
|
||||
|
||||
root.walkDecls(/^--/, ({ prop }) => {
|
||||
declaredCustomProps.add(prop);
|
||||
});
|
||||
|
||||
root.walkDecls((decl) => {
|
||||
const { value } = decl;
|
||||
|
||||
const parsedValue = valueParser(value);
|
||||
|
||||
parsedValue.walk((node) => {
|
||||
if (!isVarFunction(node)) return;
|
||||
|
||||
const [firstNode, secondNode] = node.nodes;
|
||||
|
||||
if (!firstNode || declaredCustomProps.has(firstNode.value)) return;
|
||||
|
||||
// Second node (div) indicates fallback exists in all cases
|
||||
if (secondNode && secondNode.type === 'div') return;
|
||||
|
||||
const startIndex = declarationValueIndex(decl);
|
||||
|
||||
report({
|
||||
result,
|
||||
ruleName,
|
||||
message: messages.rejected,
|
||||
messageArgs: [firstNode.value],
|
||||
node: decl,
|
||||
index: startIndex + firstNode.sourceIndex,
|
||||
endIndex: startIndex + firstNode.sourceEndIndex,
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
rule.ruleName = ruleName;
|
||||
rule.messages = messages;
|
||||
rule.meta = meta;
|
||||
export default rule;
|
||||
Reference in New Issue
Block a user