Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit a384cd6

Browse files
authored
chore(infrastructure): Add stylelint config for screenshot tests (#2144)
This PR: - Adds `test/**/*.scss` to `npm run fix:css` and `npm run lint:css` - Requires all Sass symbols (variables/functions/mixins) to begin with `test-` or `custom-` rather than `mdc-` - Moves `ignoreFiles` from `.stylelintrc.yaml` to `.stylelintignore` According to the [stylelint configuration docs](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/configuration.md#ignorefiles): > _Note that `ignoreFiles` is not an efficient method for ignoring lots of files._ If you want to ignore a lot of files efficiently, use `.stylelintignore` or adjust your files globs. - Ignores all directories named `node_modules` or `out`, regardless of where they are - Extends the root `.stylelintrc.yaml` file
1 parent 43b8bb7 commit a384cd6

9 files changed

Lines changed: 37 additions & 14 deletions

File tree

.stylelintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/node_modules
2+
**/out
3+
build/

.stylelintrc.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
extends: stylelint-config-standard
2-
ignoreFiles:
3-
- node_modules/**/*
4-
- packages/**/node_modules/**/*
5-
- build/**/*
62
plugins:
73
- stylelint-selector-bem-pattern
84
- stylelint-scss

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"dist": "npm run build && npm run build:min",
1414
"dev": "npm run clean && cross-env MDC_ENV=development webpack-dev-server --config=demos/webpack.config.js --progress --inline --hot --host 0.0.0.0",
1515
"fix:js": "eslint --fix packages test webpack.config.js demos/webpack.config.js karma.conf.js",
16-
"fix:css": "stylelint --fix \"packages/**/*.scss\"",
16+
"fix:css": "stylelint --fix \"packages/**/*.scss\"; stylelint --fix --config=test/screenshot/.stylelintrc.yaml \"test/screenshot/**/*.scss\"",
1717
"fix": "npm-run-all --parallel fix:*",
18-
"lint:css": "stylelint \"packages/**/*.scss\"",
18+
"lint:css": "stylelint \"packages/**/*.scss\"; stylelint --config=test/screenshot/.stylelintrc.yaml \"test/screenshot/**/*.scss\"",
1919
"lint:js": "eslint packages test scripts webpack.config.js demos/webpack.config.js karma.conf.js",
2020
"lint:html": "find test/screenshot/spec/ -name '*.html' | grep -v 'index.html$' | xargs htmllint",
2121
"lint:imports": "node scripts/check-imports.js",

test/screenshot/.stylelintrc.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends: ../../.stylelintrc.yaml
2+
rules:
3+
# CSS
4+
custom-media-pattern: "^(?:test|custom|report)-.+"
5+
custom-property-pattern: "^(?:test|custom|report)-.+"
6+
selector-class-pattern:
7+
- "^(?:test|custom|report)-.+"
8+
- resolveNestedSelectors: true
9+
selector-id-pattern: "^(?:test|custom|report)-.+"
10+
11+
# Sass
12+
scss/dollar-variable-pattern:
13+
- "^(?:test|custom|report)-.+"
14+
- ignore: local
15+
scss/at-function-pattern: "^(?:test|custom|report)-.+"
16+
scss/at-mixin-pattern: "^(?:test|custom|report)-.+"

test/screenshot/report/report.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* THE SOFTWARE.
2121
*/
2222

23+
// stylelint-disable selector-max-type, selector-max-universal, no-descending-specificity, declaration-property-unit-whitelist
24+
2325
/*
2426
* Global
2527
*/
@@ -29,7 +31,7 @@
2931
html {
3032
box-sizing: border-box;
3133
}
32-
*, *:before, *:after {
34+
*, *:before, *:after { // stylelint-disable-line
3335
box-sizing: inherit;
3436
}
3537

@@ -75,7 +77,7 @@ th {
7577
.report-metadata__heading-content,
7678
.report-collection__heading-content,
7779
.report-html-file__heading-content,
78-
.report-user-agent__heading-content{
80+
.report-user-agent__heading-content {
7981
display: inline-block;
8082
width: calc(100% - 7em);
8183
vertical-align: top;
@@ -103,8 +105,8 @@ th {
103105
}
104106

105107
.report-metadata__table {
106-
border-collapse: collapse;
107108
border: 1px solid #eee;
109+
border-collapse: collapse;
108110
}
109111

110112
.report-metadata__row--top-divider {
@@ -294,13 +296,15 @@ th {
294296
.report-toolbar__button--approve {
295297
color: green;
296298
}
299+
297300
.report-toolbar__button--approve:disabled {
298301
color: rgba(green, .5);
299302
}
300303

301304
.report-toolbar__button--retry {
302305
color: red;
303306
}
307+
304308
.report-toolbar__button--retry:disabled {
305309
color: rgba(red, .5);
306310
}

test/screenshot/spec/fixture.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");
2525

2626
$test-viewport-trim-color: #abc123; // Value must match `TRIM_COLOR_CSS_VALUE` in `image-cropper.js`
27-
$test-layout-cell-grid-color: #dddddd;
27+
$test-layout-cell-grid-color: #ddd;
2828

2929
@mixin test-fixture-grid-bg {
3030
// Ruler grid pattern
3131
// https://stackoverflow.com/a/32861765/467582
3232
background-image:
33-
linear-gradient(to right, #{$test-layout-cell-grid-color} 1px, transparent 1.01px), // fraction for IE 11
33+
linear-gradient(to right, #{$test-layout-cell-grid-color} 1px, transparent 1.01px),
3434
linear-gradient(to bottom, #{$test-layout-cell-grid-color} 1px, transparent 1.01px); // fraction for IE 11
3535

3636
background-size: 10px 10px;
@@ -105,6 +105,7 @@ $test-layout-cell-grid-color: #dddddd;
105105
height: 20px;
106106
}
107107

108+
// stylelint-disable selector-max-universal
108109
.test-animation--paused,
109110
.test-animation--paused::before,
110111
.test-animation--paused::after,
@@ -114,3 +115,4 @@ $test-layout-cell-grid-color: #dddddd;
114115
animation-play-state: paused !important;
115116
transition: none !important;
116117
}
118+
// stylelint-enable selector-max-universal

test/screenshot/spec/mdc-drawer/fixture.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ $custom-drawer-color: $material-color-orange-900;
3333
.test-viewport--drawer {
3434
@include mdc-typography-base;
3535

36-
height: 100vh;
3736
display: flex;
3837
flex-direction: row;
38+
height: 100vh;
3939
overflow: hidden;
4040
}
4141

@@ -54,12 +54,12 @@ $custom-drawer-color: $material-color-orange-900;
5454

5555
.test-drawer-main-content {
5656
display: block; // Needed for IE 11
57+
box-sizing: border-box;
5758
height: 100%;
5859
padding-right: 16px;
5960
padding-left: 16px;
60-
overflow: auto;
61-
box-sizing: border-box;
6261
background: #fff;
62+
overflow: auto;
6363
}
6464

6565
.custom-drawer--fill-color {

test/screenshot/spec/mdc-radio/fixture.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $custom-radio-color: $material-color-red-300;
4343
cursor: pointer;
4444
}
4545

46+
// stylelint-disable-next-line selector-class-pattern
4647
.mdc-radio--disabled + .test-radio-label {
4748
background: rgba(0, 0, 0, .1);
4849
cursor: not-allowed;

test/screenshot/spec/mdc-switch/fixture.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ $custom-switch-color: $material-color-red-500;
4444
cursor: pointer;
4545
}
4646

47+
// stylelint-disable-next-line selector-class-pattern
4748
.mdc-switch--disabled + .test-switch-label {
4849
background: rgba(0, 0, 0, .1);
4950
cursor: not-allowed;

0 commit comments

Comments
 (0)