Skip to content

ci: allow typography mixins to normalize config #21243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2020
Merged
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
15 changes: 11 additions & 4 deletions tools/stylelint/theme-mixin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
}

const expectedProperty = type === 'density' ? '$density-scale' : '$config';
const expectedValue = `mat-get-${type}-config($config-or-theme)`;
const expectedValues = [`mat-get-${type}-config($config-or-theme)`];
if (type === 'typography') {
expectedValues.unshift(
'mat-private-typography-normalized-config(mat-get-typography-config($config-or-theme))'
);
}
let configExtractionNode: Declaration|null = null;
let nonCommentNodeCount = 0;

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

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

if (!configExtractionNode && nonCommentNodeCount > 0) {
if (context.fix) {
node.insertBefore(0, {prop: expectedProperty, value: expectedValue});
node.insertBefore(0, {prop: expectedProperty, value: expectedValues[0]});
} else {
reportError(
node,
`Config is not extracted. Consumers could pass a theme object. ` +
`Extract the configuration by using: ${expectedProperty}: ${expectedValue}`);
`Extract the configuration by using one of the following:` +
expectedValues.map(expectedValue => `${expectedProperty}: ${expectedValue}`)
.join('\n'));
}
} else if (configExtractionNode && configExtractionNode.prop !== expectedProperty) {
reportError(
Expand Down