Skip to content

Commit 8fc6aec

Browse files
authored
ci: allow typography mixins to normalize config (#21243)
1 parent 87dcfad commit 8fc6aec

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
@@ -147,7 +147,12 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
147147
}
148148

149149
const expectedProperty = type === 'density' ? '$density-scale' : '$config';
150-
const expectedValue = `mat-get-${type}-config($config-or-theme)`;
150+
const expectedValues = [`mat-get-${type}-config($config-or-theme)`];
151+
if (type === 'typography') {
152+
expectedValues.unshift(
153+
'mat-private-typography-normalized-config(mat-get-typography-config($config-or-theme))'
154+
);
155+
}
151156
let configExtractionNode: Declaration|null = null;
152157
let nonCommentNodeCount = 0;
153158

@@ -157,7 +162,7 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
157162
nonCommentNodeCount++;
158163
}
159164

160-
if (currentNode.type === 'decl' && currentNode.value === expectedValue) {
165+
if (currentNode.type === 'decl' && expectedValues.includes(currentNode.value)) {
161166
configExtractionNode = currentNode;
162167
break;
163168
}
@@ -166,12 +171,14 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
166171

167172
if (!configExtractionNode && nonCommentNodeCount > 0) {
168173
if (context.fix) {
169-
node.insertBefore(0, {prop: expectedProperty, value: expectedValue});
174+
node.insertBefore(0, {prop: expectedProperty, value: expectedValues[0]});
170175
} else {
171176
reportError(
172177
node,
173178
`Config is not extracted. Consumers could pass a theme object. ` +
174-
`Extract the configuration by using: ${expectedProperty}: ${expectedValue}`);
179+
`Extract the configuration by using one of the following:` +
180+
expectedValues.map(expectedValue => `${expectedProperty}: ${expectedValue}`)
181+
.join('\n'));
175182
}
176183
} else if (configExtractionNode && configExtractionNode.prop !== expectedProperty) {
177184
reportError(

0 commit comments

Comments
 (0)