-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure we don't explode on Vue and css-in-js solutions
Increases the peerDependency to stylelint 9.10.0. Stylelint 9.10.0 uses postcss-jsx to parse css-in-js solutions and postcss-html to parse vue/markdown/html files, These two together mean the funky languages landscape is a lot cleaner than a few months ago. We skip passing js-like files into prettier as the css fragments aren't parsable by prettier as they're either JS objects, or lists of properties without a wrapping selector (i.e. `color: red; background: green` instead of `.x { color: red; background: green; }`. For Vue / html / markdown files we can use the parser name that stylelint used as conviniently they all match up to parser names that prettier has (well except sugarss but who uses that?). This allows `<style lang="scss">` blocks to be parsed as scss. This also adds a handful of e2e tests as which allow us to keep testing these new languages.
- Loading branch information
Showing
17 changed files
with
531 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
!.eslintrc.js | ||
node_modules | ||
|
||
# This test file is deliberately unparsable | ||
test/fixtures/check.unparsable.js |
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
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,3 @@ | ||
.foo { | ||
background-image: url("x"); | ||
} |
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,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Page Title</title> | ||
<style> | ||
.foo { | ||
background-image: url("x"); | ||
} | ||
</style> | ||
|
||
<style lang="scss"> | ||
.foo { | ||
background-image: url("x"); | ||
} | ||
|
||
$map: ( | ||
'alpha': 10, | ||
'beta': 20, | ||
'gamma': 30 | ||
); | ||
</style> | ||
</head> | ||
|
||
<body> | ||
</body> | ||
</html> |
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 @@ | ||
const styled = require('styled-components'); | ||
|
||
const Button = styled.div` | ||
background-image: url("x"); | ||
color: red; | ||
`; | ||
|
||
const Button2 = styled.div({ | ||
'background-image': url("x"), | ||
'color': '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,19 @@ | ||
# TEST | ||
|
||
```css | ||
h2 { | ||
background-image: url("x"); | ||
} | ||
``` | ||
|
||
```scss | ||
h2 { | ||
background-image: url("x"); | ||
} | ||
|
||
$map: ( | ||
'alpha': 10, | ||
'beta': 20, | ||
'gamma': 30 | ||
); | ||
``` |
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,9 @@ | ||
.foo { | ||
background-image: url("x"); | ||
} | ||
|
||
$map: ( | ||
'alpha': 10, | ||
'beta': 20, | ||
'gamma': 30 | ||
); |
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 @@ | ||
<template> | ||
<span>Hi</span> | ||
</template> | ||
|
||
<style> | ||
.foo { | ||
background-image: url("x"); | ||
} | ||
</style> | ||
|
||
<style lang="scss"> | ||
.foo { | ||
background-image: url("x"); | ||
} | ||
$map: ( | ||
'alpha': 10, | ||
'beta': 20, | ||
'gamma': 30 | ||
); | ||
</style> |
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,7 @@ | ||
const styled = require('styled-components'); | ||
|
||
const But{ton = styled.div` | ||
background-image: url("x"); | ||
color: 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,7 @@ | ||
module.exports = { | ||
plugins: [`../..`], | ||
extends: ['stylelint-config-prettier'], | ||
rules: { | ||
'prettier/prettier': [true, {singleQuote: true, trailingComma: 'all'}], | ||
}, | ||
}; |
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,69 @@ | ||
const {spawnSync} = require('child_process'); | ||
const {resolve} = require('path'); | ||
|
||
describe('E2E Tests', () => { | ||
test('CSS/SCSS files', () => { | ||
const result = runStylelint('*.{css,scss}'); | ||
|
||
const expectedResult = ` | ||
check.invalid.css | ||
2:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
check.invalid.scss | ||
2:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
8:14 ✖ Insert "," prettier/prettier | ||
`.trim(); | ||
|
||
expect(result.status).toEqual(2); | ||
expect(result.output).toEqual(expectedResult); | ||
}); | ||
|
||
test('HTML/Markdown/Vue files', () => { | ||
const result = runStylelint('*.{html,md,vue}'); | ||
|
||
const expectedResult = ` | ||
check.invalid.html | ||
8:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
14:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
20:14 ✖ Insert "," prettier/prettier | ||
check.invalid.md | ||
5:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
11:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
17:14 ✖ Insert "," prettier/prettier | ||
check.invalid.vue | ||
7:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
13:25 ✖ Replace ""x"" with "'x'" prettier/prettier | ||
19:14 ✖ Insert "," prettier/prettier | ||
`.trim(); | ||
|
||
expect(result.status).toEqual(2); | ||
expect(result.output).toEqual(expectedResult); | ||
}); | ||
|
||
/** | ||
* Don't act upon CSS-in-JS files | ||
*/ | ||
test('CSS-in-JS files', () => { | ||
const result = runStylelint('*.js'); | ||
|
||
const expectedResult = ``; | ||
|
||
expect(result.status).toEqual(0); | ||
expect(result.output).toEqual(expectedResult); | ||
}); | ||
}); | ||
|
||
function runStylelint(pattern) { | ||
const stylelintCmd = resolve(`${__dirname}/../node_modules/.bin/stylelint`); | ||
|
||
const result = spawnSync(stylelintCmd, [pattern], { | ||
cwd: `${__dirname}/fixtures`, | ||
}); | ||
|
||
return { | ||
status: result.status, | ||
output: result.stdout.toString().trim(), | ||
}; | ||
} |
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
Oops, something went wrong.