Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .changeset/sour-parrots-cry.md

This file was deleted.

50 changes: 28 additions & 22 deletions stylelint-polaris/plugins/custom-property-allowed-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,18 @@ const messages = stylelint.utils.ruleMessages(ruleName, {
* @type {stylelint.RuleMessageFunc}
*/
rejected: (prop, value, prefix, isInvalidProp, invalidValues) => {
const invalidPropertyMessage = isInvalidProp
? `Unexpected prefix "${prefix}" for defined custom property "${prop}" - Properties with prefixes "--p-" or "--pc-" cannot be defined outside of Polaris"`
: null;

const plural = invalidValues?.length > 1;

const invalidValueMessage = invalidValues
? `Unexpected value "${value}" for property "${prop}" - Token${
plural ? 's' : ''
} ${invalidValues.map((token) => `"${token}"`).join(', ')} ${
plural ? 'are' : 'is'
} either private or ${plural ? 'do' : 'does'} not exist`
: null;

const message = [invalidPropertyMessage, invalidValueMessage]
.filter(Boolean)
.join('. ');
if (isInvalidProp) {
return `Unexpected prefix "${prefix}" for defined custom property "${prop}" - Properties with prefixes "--p-" or "--pc-" cannot be defined outside of Polaris"`;
}

return message;
if (invalidValues) {
const plural = invalidValues.length > 1;
return `Unexpected value "${value}" for property "${prop}" - Token${
plural ? 's' : ''
} ${invalidValues.map((token) => `"${token}"`).join(', ')} ${
plural ? 'are' : 'is'
} either private or ${plural ? 'do' : 'does'} not exist`;
}
},
});

Expand Down Expand Up @@ -89,7 +82,7 @@ const {rule} = stylelint.createPlugin(
value,
);

if (isInvalidProperty || invalidValues) {
if (isInvalidProperty) {
stylelint.utils.report({
message: messages.rejected(
prop,
Expand All @@ -103,6 +96,21 @@ const {rule} = stylelint.createPlugin(
ruleName,
});
}

if (invalidValues) {
stylelint.utils.report({
message: messages.rejected(
prop,
value,
undefined,
isInvalidProperty,
invalidValues,
),
node: decl,
result,
ruleName,
});
}
});
};
},
Expand All @@ -114,9 +122,7 @@ const {rule} = stylelint.createPlugin(
* @returns {string}
*/
function getCustomPropertyPrefix(property) {
return isCustomProperty(property)
? `--${property.split('-')[2]}-`
: undefined;
return `--${property.split('-')[2]}-`;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,5 @@ testRule({
endLine: 1,
endColumn: 28,
},
{
code: '.a { --p-foo: var(--p-bar); }',
description: 'Using disallowed --p- prefixed custom property and value',
message: messages.rejected('--p-foo', 'var(--p-bar)', '--p-', true, [
'--p-bar',
]),
line: 1,
column: 6,
endLine: 1,
endColumn: 28,
},
{
code: '.a { --p-foo: var(--p-bar) solid var(--p-baz); }',
description: 'Using disallowed --p- prefixed custom property and values',
message: messages.rejected(
'--p-foo',
'var(--p-bar) solid var(--p-baz)',
'--p-',
true,
['--p-bar', '--p-baz'],
),
line: 1,
column: 6,
endLine: 1,
endColumn: 47,
},
],
});

This file was deleted.

189 changes: 0 additions & 189 deletions stylelint-polaris/plugins/custom-property-disallowed-list/index.js

This file was deleted.

Loading