Skip to content

Commit 75e23cb

Browse files
committed
ci: allow typography mixins to normalize config (#21243)
(cherry picked from commit 8fc6aec)
1 parent 0dae8a8 commit 75e23cb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/stylelint/theme-mixin-api.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
141141
}
142142

143143
const expectedProperty = type === 'density' ? '$density-scale' : '$config';
144-
const expectedValue = `mat-get-${type}-config($config-or-theme)`;
144+
const expectedValues = [`mat-get-${type}-config($config-or-theme)`];
145+
if (type === 'typography') {
146+
expectedValues.unshift(
147+
'mat-private-typography-normalized-config(mat-get-typography-config($config-or-theme))'
148+
);
149+
}
145150
let configExtractionNode: Declaration|null = null;
146151
let nonCommentNodeCount = 0;
147152

@@ -151,7 +156,7 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
151156
nonCommentNodeCount++;
152157
}
153158

154-
if (currentNode.type === 'decl' && currentNode.value === expectedValue) {
159+
if (currentNode.type === 'decl' && expectedValues.includes(currentNode.value)) {
155160
configExtractionNode = currentNode;
156161
break;
157162
}
@@ -160,12 +165,14 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
160165

161166
if (!configExtractionNode && nonCommentNodeCount > 0) {
162167
if (context.fix) {
163-
node.insertBefore(0, {prop: expectedProperty, value: expectedValue});
168+
node.insertBefore(0, {prop: expectedProperty, value: expectedValues[0]});
164169
} else {
165170
reportError(
166171
node,
167172
`Config is not extracted. Consumers could pass a theme object. ` +
168-
`Extract the configuration by using: ${expectedProperty}: ${expectedValue}`);
173+
`Extract the configuration by using one of the following:` +
174+
expectedValues.map(expectedValue => `${expectedProperty}: ${expectedValue}`)
175+
.join('\n'));
169176
}
170177
} else if (configExtractionNode && configExtractionNode.prop !== expectedProperty) {
171178
reportError(

0 commit comments

Comments
 (0)