Skip to content

Commit 3c975e9

Browse files
authored
build: enforce that we use comments that won't show up in the generated output (angular#22309)
Adds a custom stylelint rule that will prevent multi-line comments (`/* */`) from being used in .scss files. The problem with such comments are preserved by Sass and will show up in the user's output, whereas single-line comments (`//`) will not. **Note:** while Stylelint has a `comment-pattern` rule already, we can't use it because the rule works on the comment text which doesn't include the syntax.
1 parent af3e74c commit 3c975e9

File tree

20 files changed

+84
-50
lines changed

20 files changed

+84
-50
lines changed

.stylelintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"./tools/stylelint/no-concrete-rules.ts",
1010
"./tools/stylelint/no-top-level-ampersand-in-mixin.ts",
1111
"./tools/stylelint/theme-mixin-api.ts",
12-
"./tools/stylelint/no-import.ts"
12+
"./tools/stylelint/no-import.ts",
13+
"./tools/stylelint/single-line-comment-only.ts"
1314
],
1415
"rules": {
1516
"material/no-prefixes": [true, {
@@ -19,6 +20,9 @@
1920
"material/theme-mixin-api": true,
2021
"material/selector-no-deep": true,
2122
"material/no-nested-mixin": true,
23+
"material/single-line-comment-only": [true, {
24+
"filePattern": "\\.scss$"
25+
}],
2226
"material/no-import": [true, {
2327
"exclude": "\\.import\\.scss$"
2428
}],

src/dev-app/virtual-scroll/virtual-scroll-demo.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.demo-item {
1818
-ms-writing-mode: tb-lr;
1919
-webkit-writing-mode: vertical-lr;
20-
/* stylelint-disable-next-line material/no-prefixes */
20+
// stylelint-disable-next-line material/no-prefixes
2121
writing-mode: vertical-lr;
2222
}
2323
}

src/material-experimental/mdc-button/fab.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// ```
2222
// However, Angular Material expects a `mat-icon` instead. The following
2323
// mixin will style the icons appropriately.
24-
/* stylelint-disable-next-line selector-class-pattern */
24+
// stylelint-disable-next-line selector-class-pattern
2525
.mat-icon, .material-icons {
2626
@include mdc-fab.icon_();
2727
}
@@ -30,7 +30,7 @@
3030
.mat-mdc-extended-fab {
3131
@include mdc-fab.extended_();
3232

33-
/* stylelint-disable-next-line selector-class-pattern */
33+
// stylelint-disable-next-line selector-class-pattern
3434
.mat-icon, .material-icons {
3535
@include mdc-fab.extended-icon-padding(
3636
mdc-fab.$extended-icon-padding,
@@ -41,7 +41,7 @@
4141
// For Extended FAB with text label followed by icon.
4242
// We are checking for the a button class because white this is a FAB it
4343
// uses the same template as button.
44-
/* stylelint-disable-next-line selector-class-pattern */
44+
// stylelint-disable-next-line selector-class-pattern
4545
.mdc-button__label + .mat-icon, .mdc-button__label + .material-icons {
4646
@include mdc-fab.extended-icon-padding(
4747
mdc-fab.$extended-icon-padding,
@@ -50,4 +50,3 @@
5050
);
5151
}
5252
}
53-

src/material-experimental/mdc-form-field/_mdc-text-field-structure-overrides.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
// placeholder if the form-field label is set to always float.
6969
// TODO(devversion): consider getting a mixin or variables for this (currently not available).
7070
// Stylelint no-prefixes rule disabled because MDC text-field only uses "::placeholder" too.
71-
/* stylelint-disable-next-line material/no-prefixes */
71+
// stylelint-disable-next-line material/no-prefixes
7272
.mat-mdc-form-field-label-always-float .mdc-text-field__input::placeholder {
7373
transition-delay: 40ms;
7474
transition-duration: 110ms;

src/material-experimental/mdc-helpers/_focus-indicators-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// .demo-red-theme {
3131
/// @include mat-mdc-strong-focus-indicators-theme(#f00);
3232
/// }
33-
/* stylelint-disable-next-line material/theme-mixin-api */
33+
// stylelint-disable-next-line material/theme-mixin-api
3434
@mixin theme($theme-or-color) {
3535
@if meta.type-of($theme-or-color) != 'map' {
3636
@include _mat-mdc-strong-focus-indicators-border-color($theme-or-color);

src/material-experimental/mdc-helpers/_mdc-helpers.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ $mat-typography-2018-level-mappings: (
159159

160160
// Configures MDC's global variables to reflect the given theme, applies the given styles,
161161
// then resets the global variables to prevent unintended side effects.
162-
/* stylelint-disable-next-line material/theme-mixin-api */
162+
// stylelint-disable-next-line material/theme-mixin-api
163163
@mixin mat-using-mdc-theme($config) {
164164
$primary: theming.get-color-from-palette(map.get($config, primary));
165165
$accent: theming.get-color-from-palette(map.get($config, accent));
@@ -250,7 +250,7 @@ $mat-typography-2018-level-mappings: (
250250

251251
// Configures MDC's global variables to reflect the given typography config,
252252
// applies the given styles, then resets the global variables to prevent unintended side effects.
253-
/* stylelint-disable-next-line material/theme-mixin-api */
253+
// stylelint-disable-next-line material/theme-mixin-api
254254
@mixin mat-using-mdc-typography($config) {
255255
// Save the original values.
256256
$orig-mdc-typography-styles: mdc-typography.$styles;

src/material/autocomplete/autocomplete.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
@use '../core/style/menu-common';
22
@use '../../cdk/a11y/a11y';
33

4-
/**
5-
* The max-height of the panel, currently matching mat-select value.
6-
*/
4+
// The max-height of the panel, currently matching mat-select value.
75
$panel-max-height: 256px !default;
86
$panel-border-radius: 4px !default;
97

src/material/core/focus-indicators/_focus-indicators-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/// .demo-red-theme {
2424
/// @include mat-strong-focus-indicators-theme(#f00);
2525
/// }
26-
/* stylelint-disable-next-line material/theme-mixin-api */
26+
// stylelint-disable-next-line material/theme-mixin-api
2727
@mixin theme($theme-or-color) {
2828
@if meta.type-of($theme-or-color) != 'map' {
2929
@include _mat-strong-focus-indicators-border-color($theme-or-color);

src/material/core/ripple/_ripple-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@use 'sass:meta';
33
@use '../theming/theming';
44

5-
/* Colors for the ripple elements.*/
5+
// Colors for the ripple elements.
66
@mixin color($config-or-theme) {
77
$config: theming.get-color-config($config-or-theme);
88
$foreground: map.get($config, foreground);

src/material/core/style/_menu-common.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@use './layout-common';
44
@use './vendor-prefixes';
55

6-
/** The mixins below are shared between mat-menu and mat-select */
6+
// The mixins below are shared between mat-menu and mat-select
77

88
// menu width must be a multiple of 56px
99
$overlay-min-width: 112px !default; // 56 * 2

0 commit comments

Comments
 (0)