Skip to content

Commit c3aa933

Browse files
authored
Merge pull request #286 from humanmade/update-stylelint
Add stylelint tests
2 parents 9e40d14 + e5ce448 commit c3aa933

File tree

10 files changed

+296
-164
lines changed

10 files changed

+296
-164
lines changed

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,13 @@ jobs:
5656
- npm install --legacy-peer-deps
5757
- cd ../..
5858
script:
59-
- npm test
59+
- npm run test:eslint
60+
- language: node_js
61+
node_js: 16
62+
install:
63+
- npm install
64+
- cd packages/stylelint-config
65+
- npm install
66+
- cd ../..
67+
script:
68+
- npm run test:stylelint

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"publish:dev": "lerna publish --dist-tag next",
7979
"publish:legacy": "lerna publish --dist-tag legacy",
8080
"publish:prod": "lerna publish",
81-
"test": "npm run lint-pkg-json && npm run test:packages",
82-
"test:packages": "cd packages/eslint-config-humanmade && npm test"
81+
"test": "npm run lint-pkg-json && npm run test:eslint && npm run test:stylelint",
82+
"test:eslint": "cd packages/eslint-config-humanmade && npm test",
83+
"test:stylelint": "cd packages/stylelint-config && npm test"
8384
}
8485
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Bad BEM syntax */
2+
.foo__bar__foo,
3+
.foo--bar--foo,
4+
.foo--bar__foo {
5+
display: block;
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Max nesting depth.
2+
.element {
3+
display: block;
4+
5+
.child-element {
6+
display: block;
7+
8+
.child-element {
9+
display: block;
10+
11+
.child-element {
12+
display: block;
13+
}
14+
}
15+
}
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.element {
2+
background: red;
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* No color-named */
2+
.element {
3+
background: #f00;
4+
}
5+
6+
/* Valid BEM syntax */
7+
.block__element,
8+
.block__element--modifier,
9+
.block--modifier {
10+
display: block;
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Max nesting depth.
2+
.element {
3+
display: block;
4+
5+
// Nesting depth: 1
6+
.child-element {
7+
display: block;
8+
9+
// Nesting depth: 2. Maximum allowed.
10+
.child-element {
11+
display: block;
12+
}
13+
14+
// Allowed to be nested deeper because it's within a media query.
15+
@media screen {
16+
.child-element {
17+
display: block;
18+
}
19+
}
20+
}
21+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const stylelint = require( 'stylelint' );
2+
const chalk = require( 'chalk' );
3+
const path = require( 'path' );
4+
5+
stylelint.lint( {
6+
files: 'fixtures/pass/**/*.{css,scss}'
7+
} ).then( (resultObject) => {
8+
if ( resultObject.errored ) {
9+
console.log( chalk.bold.red( 'Stylelint detected the following errors in the test files that are expected to pass.' ) );
10+
resultObject.results.forEach( result => {
11+
if ( ! result.errored ) {
12+
return;
13+
}
14+
15+
console.log( '• ' + path.relative( process.cwd(), result.source ) );
16+
result.warnings.forEach( result => {
17+
console.log( ` • ${ result.text }. Line: ${ result.line }.` );
18+
} );
19+
} );
20+
process.exitCode = 1;
21+
} else {
22+
console.log( chalk.green( 'No errors detected in files that are expected to pass.' ) );
23+
}
24+
});
25+
26+
stylelint.lint( {
27+
files: 'fixtures/fail/**/*.{css,scss}'
28+
} ).then( (resultObject) => {
29+
if ( ! resultObject.errored ) {
30+
console.log( chalk.bold.red( 'The following files did not produce errors:' ) );
31+
resultObject.results.forEach( result => {
32+
if ( result.errored ) {
33+
return;
34+
}
35+
36+
console.log( ' ' + result.source );
37+
} );
38+
process.exitCode = 1;
39+
} else {
40+
console.log( chalk.green( 'All files that should fail log errors as expected.' ) );
41+
}
42+
});

0 commit comments

Comments
 (0)