Skip to content

Commit 67e0884

Browse files
committed
fixup! fix(material/core): allow mixins to handle 2018 typography configs
1 parent b35a388 commit 67e0884

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/stylelint/theme-mixin-api.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
147147
}
148148

149149
const expectedProperty = type === 'density' ? '$density-scale' : '$config';
150-
const expectedValue = type === 'typography' ?
151-
`mat-private-typography-normalized-config(mat-get-typography-config($config-or-theme))` :
152-
`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+
}
153156
let configExtractionNode: Declaration|null = null;
154157
let nonCommentNodeCount = 0;
155158

@@ -159,7 +162,7 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
159162
nonCommentNodeCount++;
160163
}
161164

162-
if (currentNode.type === 'decl' && currentNode.value === expectedValue) {
165+
if (currentNode.type === 'decl' && expectedValues.includes(currentNode.value)) {
163166
configExtractionNode = currentNode;
164167
break;
165168
}
@@ -168,12 +171,14 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
168171

169172
if (!configExtractionNode && nonCommentNodeCount > 0) {
170173
if (context.fix) {
171-
node.insertBefore(0, {prop: expectedProperty, value: expectedValue});
174+
node.insertBefore(0, {prop: expectedProperty, value: expectedValues[0]});
172175
} else {
173176
reportError(
174177
node,
175178
`Config is not extracted. Consumers could pass a theme object. ` +
176-
`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'));
177182
}
178183
} else if (configExtractionNode && configExtractionNode.prop !== expectedProperty) {
179184
reportError(

0 commit comments

Comments
 (0)