Skip to content

Commit

Permalink
Add messageArgs to declaration-property-value-no-unknown, `font-f…
Browse files Browse the repository at this point in the history
…amily-name-quotes`, `font-family-no-duplicate-names`, `function-calc-no-unspaced-operator`, `import-notation` and `selector-attribute-quotes` (#8285)
  • Loading branch information
Mouvedia authored Jan 7, 2025
1 parent 8ddbe17 commit a80cdf6
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-carpets-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": minor
---

Added: `messageArgs` to `declaration-property-value-no-unknown`, `font-family-name-quotes`, `font-family-no-duplicate-names`, `function-calc-no-unspaced-operator`, `import-notation` and `selector-attribute-quotes`
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ This rule flags keywords that were removed or deprecated after being in the CSS

The [`fix` option](../../../docs/user-guide/options.md#fix) can automatically fix some of the problems reported by this rule.

The [`message` secondary option](../../../docs/user-guide/configure.md#message) accept arguments.

Prior art:

- [@isnotdefined/no-obsolete](https://www.npmjs.com/package/@isnotdefined/stylelint-plugin)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,17 @@ const rule = (primary, secondaryOptions) => {
const lowercasedValue = node.value.toLowerCase();
let fix;
let message;
let messageArgs;

if (Array.isArray(keywords)) {
if (!keywords.includes(lowercasedValue)) return;

message = messages.rejected;
messageArgs = [prop, value];
message = messages.rejected(prop, value);
} else {
const expectedKeyword = keywords[lowercasedValue];

if (!expectedKeyword) return;

message = messages.expected;
messageArgs = [value, expectedKeyword];
message = messages.expected(value, expectedKeyword);
fix = () => {
node.value = expectedKeyword;
setDeclarationValue(decl, parsedValue.toString());
Expand All @@ -161,7 +158,6 @@ const rule = (primary, secondaryOptions) => {

report({
message,
messageArgs,
node: decl,
result,
ruleName,
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/declaration-property-value-no-unknown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This rule overlaps with:

You can either turn off the rules or configure them to ignore the overlaps.

The [`message` secondary option](../../../docs/user-guide/configure.md#message) can accept arguments.

Prior art:

- [stylelint-csstree-validator](https://www.npmjs.com/package/stylelint-csstree-validator)
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/declaration-property-value-no-unknown/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/rules/declaration-property-value-no-unknown/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ const rule = (primary, secondaryOptions) => {
const endIndex = index + value.length;

report({
message: messages.rejectedParseError(prop, value),
message: messages.rejectedParseError,
messageArgs: [prop, value],
node: decl,
index,
endIndex,
Expand Down Expand Up @@ -185,7 +186,8 @@ const rule = (primary, secondaryOptions) => {
const mismatchValue = value.slice(loc.start.offset, loc.end.offset);

report({
message: messages.rejected(prop, mismatchValue),
message: messages.rejected,
messageArgs: [prop, mismatchValue],
node: decl,
index: valueIndex + loc.start.offset,
endIndex: valueIndex + loc.end.offset,
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/font-family-name-quotes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This rule ignores `$sass`, `@less`, and `var(--custom-property)` variable syntax

The [`fix` option](../../../docs/user-guide/options.md#fix) can automatically fix most of the problems reported by this rule.

The [`message` secondary option](../../../docs/user-guide/configure.md#message) can accept arguments.

## Options

`string`: `"always-where-required"|"always-where-recommended"|"always-unless-keyword"`
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/font-family-name-quotes/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/rules/font-family-name-quotes/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ const rule = (primary) => {
report({
result,
ruleName,
message: messages[messageType](name),
message: messages[messageType],
messageArgs: [name],
node: decl,
word: rawName,
fix,
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/font-family-no-duplicate-names/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This rule ignores `$sass`, `@less`, and `var(--custom-property)` variable syntax
> [!WARNING]
> This rule will stumble on _unquoted_ multi-word font names and _unquoted_ font names containing escape sequences. Wrap these font names in quotation marks, and everything should be fine.
The [`message` secondary option](../../../docs/user-guide/configure.md#message) can accept arguments.

## Options

### `true`
Expand Down
13 changes: 7 additions & 6 deletions lib/rules/font-family-no-duplicate-names/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/rules/font-family-no-duplicate-names/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import validateOptions from '../../utils/validateOptions.mjs';
const ruleName = 'font-family-no-duplicate-names';

const messages = ruleMessages(ruleName, {
rejected: (name) => `Unexpected duplicate name ${name}`,
rejected: (name) => `Unexpected duplicate font-family name ${name}`,
});

const meta = {
Expand Down Expand Up @@ -66,7 +66,7 @@ const rule = (primary, secondaryOptions) => {
if (isFamilyNameKeyword(fontFamilyNode)) {
if (keywords.has(family.toLowerCase())) {
complain(
messages.rejected(family),
family,
declarationValueIndex(decl) + fontFamilyNode.sourceIndex,
rawFamily.length,
decl,
Expand All @@ -82,7 +82,7 @@ const rule = (primary, secondaryOptions) => {

if (familyNames.has(family)) {
complain(
messages.rejected(family),
family,
declarationValueIndex(decl) + fontFamilyNode.sourceIndex,
rawFamily.length,
decl,
Expand All @@ -96,16 +96,17 @@ const rule = (primary, secondaryOptions) => {
});

/**
* @param {string} message
* @param {string} name
* @param {number} index
* @param {number} length
* @param {import('postcss').Declaration} decl
*/
function complain(message, index, length, decl) {
function complain(name, index, length, decl) {
report({
result,
ruleName,
message,
message: messages.rejected,
messageArgs: [name],
node: decl,
index,
endIndex: index + length,
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/function-calc-no-unspaced-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This rule checks that there is a single whitespace or a newline plus indentation

The [`fix` option](../../../docs/user-guide/options.md#fix) can automatically fix all of the problems reported by this rule.

The [`message` secondary option](../../../docs/user-guide/configure.md#message) can accept arguments.

## Options

### `true`
Expand Down
13 changes: 7 additions & 6 deletions lib/rules/function-calc-no-unspaced-operator/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/rules/function-calc-no-unspaced-operator/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ const rule = (primary) => {
if (!validOptions) return;

/**
* @param {string} message
* @param {messages[keyof messages]} message
* @param {import('postcss').Node} node
* @param {number} index
* @param {string} operator
* @param {() => void} fix
*/
function complain(message, node, index, operator, fix) {
const endIndex = index + operator.length;
const messageArgs = [operator];

report({ message, node, index, endIndex, result, ruleName, fix });
report({ message, messageArgs, node, index, endIndex, result, ruleName, fix });
}

root.walkDecls((decl) => {
Expand Down Expand Up @@ -103,7 +104,7 @@ const rule = (primary) => {
const messageKey = position === 'before' ? 'expectedBefore' : 'expectedAfter';

complain(
messages[messageKey](operation.operatorChar),
messages[messageKey],
decl,
valueIndex + operation.operatorCharPosition,
operation.operatorChar,
Expand Down Expand Up @@ -135,7 +136,7 @@ const rule = (primary) => {
operation.completeMissingOperator(operatorChar, endPos, 'append');

complain(
messages.expectedBefore(operation.operatorChar),
messages.expectedBefore,
decl,
valueIndex + operation.operatorCharPosition,
operation.operatorChar,
Expand Down Expand Up @@ -180,7 +181,7 @@ const rule = (primary) => {
operation.completeMissingOperator(operatorChar, startPos, 'prepend');

complain(
messages.expectedAfter(operation.operatorChar),
messages.expectedAfter,
decl,
valueIndex + operation.operatorCharPosition,
operation.operatorChar,
Expand Down Expand Up @@ -217,7 +218,7 @@ const rule = (primary) => {
const message = position === 'before' ? messages.expectedBefore : messages.expectedAfter;

complain(
message(operation.operatorChar),
message,
decl,
valueIndex + operation.operatorCharPosition,
operation.operatorChar,
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/import-notation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Specify string or URL notation for `@import` rules.

The [`fix` option](../../../docs/user-guide/options.md#fix) can automatically fix all of the problems reported by this rule.

The [`message` secondary option](../../../docs/user-guide/configure.md#message) can accept arguments.

## Options

`string`: `"string"|"url"`
Expand Down
Loading

0 comments on commit a80cdf6

Please sign in to comment.