-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from humanmade/update-stylelint
Add stylelint tests
- Loading branch information
Showing
10 changed files
with
296 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* Bad BEM syntax */ | ||
.foo__bar__foo, | ||
.foo--bar--foo, | ||
.foo--bar__foo { | ||
display: block; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/stylelint-config/fixtures/fail/max-nesting-depth.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Max nesting depth. | ||
.element { | ||
display: block; | ||
|
||
.child-element { | ||
display: block; | ||
|
||
.child-element { | ||
display: block; | ||
|
||
.child-element { | ||
display: block; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.element { | ||
background: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* No color-named */ | ||
.element { | ||
background: #f00; | ||
} | ||
|
||
/* Valid BEM syntax */ | ||
.block__element, | ||
.block__element--modifier, | ||
.block--modifier { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Max nesting depth. | ||
.element { | ||
display: block; | ||
|
||
// Nesting depth: 1 | ||
.child-element { | ||
display: block; | ||
|
||
// Nesting depth: 2. Maximum allowed. | ||
.child-element { | ||
display: block; | ||
} | ||
|
||
// Allowed to be nested deeper because it's within a media query. | ||
@media screen { | ||
.child-element { | ||
display: block; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const stylelint = require( 'stylelint' ); | ||
const chalk = require( 'chalk' ); | ||
const path = require( 'path' ); | ||
|
||
stylelint.lint( { | ||
files: 'fixtures/pass/**/*.{css,scss}' | ||
} ).then( (resultObject) => { | ||
if ( resultObject.errored ) { | ||
console.log( chalk.bold.red( 'Stylelint detected the following errors in the test files that are expected to pass.' ) ); | ||
resultObject.results.forEach( result => { | ||
if ( ! result.errored ) { | ||
return; | ||
} | ||
|
||
console.log( '• ' + path.relative( process.cwd(), result.source ) ); | ||
result.warnings.forEach( result => { | ||
console.log( ` • ${ result.text }. Line: ${ result.line }.` ); | ||
} ); | ||
} ); | ||
process.exitCode = 1; | ||
} else { | ||
console.log( chalk.green( 'No errors detected in files that are expected to pass.' ) ); | ||
} | ||
}); | ||
|
||
stylelint.lint( { | ||
files: 'fixtures/fail/**/*.{css,scss}' | ||
} ).then( (resultObject) => { | ||
if ( ! resultObject.errored ) { | ||
console.log( chalk.bold.red( 'The following files did not produce errors:' ) ); | ||
resultObject.results.forEach( result => { | ||
if ( result.errored ) { | ||
return; | ||
} | ||
|
||
console.log( ' ' + result.source ); | ||
} ); | ||
process.exitCode = 1; | ||
} else { | ||
console.log( chalk.green( 'All files that should fail log errors as expected.' ) ); | ||
} | ||
}); |
Oops, something went wrong.