Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stylelint for css-in-js #815

Merged
merged 8 commits into from
May 28, 2019
Merged

feat: add stylelint for css-in-js #815

merged 8 commits into from
May 28, 2019

Conversation

montezume
Copy link
Contributor

@montezume montezume commented May 27, 2019

Summary

When we migrated to @emotion, we removed stylelint. It makes sense now to add it back. This PR adds a script yarn lint:css, and the necessary configs.

It lints inline styles, styles with the css prop, and styled components.

Huzzah! 🧙

Current status of stylelint report

Test Suites: 9 failed, 206 passed, 215 total
Tests:       9 failed, 206 passed, 215 total
Snapshots:   0 total
Time:        12.172s

Right now there are some failing tests, so my idea is to first add the script, and then fix the stylelint errors in another PR.

It even found some invalid css!

src/components/buttons/flat-button/flat-button.js
 64:11  ✖  Unexpected }   CssSyntaxError

There is an extra closing brace there. Cool!

Closes #815

"indentation": null,
"selector-descendant-combinator-no-non-space": null,
"no-descending-specificity": null,
"no-duplicate-selectors": null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took all of these up until here from mc-fe

.stylelintrc Outdated
"selector-descendant-combinator-no-non-space": null,
"no-descending-specificity": null,
"no-duplicate-selectors": null,
"no-empty-source": null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this line because we are linting some files that ... don't have CSS. Like utils and such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with excluding this is you would get an error from let's say, parseTime.js for having no css...

moduleFileExtensions: ['js'],
modulePathIgnorePatterns: [
'dist',
'.spec.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it made sense to exclude these

@montezume montezume requested a review from emmenko May 27, 2019 12:51
@montezume montezume self-assigned this May 27, 2019
@montezume montezume requested a review from jonnybel May 27, 2019 12:51
Copy link
Contributor

@jonnybel jonnybel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@montezume
Copy link
Contributor Author

I think it would make sense to do the same setup on app-kit. @emmenko do you have any thoughts?

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

.stylelintrc Outdated
"extends": [
"stylelint-config-standard"
],
"plugins": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"plugins": [
"plugins": [

@montezume
Copy link
Contributor Author

montezume commented May 27, 2019

One caveat: this is only working with css made with string literals.

// This is linted

<div css={css`
    color: green;
`}>
   Green
</div>

// this also is linted
const GreenText = styled.div`
   color: green;
`;

// this is not linted

<div css={{
    color: 'green',
}}>
   Green
</div>

// this is not linted

<div style={{
    color: 'green',
}}>
   Green
</div>

I'm trying to figure out a solution 😬

@emmenko
Copy link
Member

emmenko commented May 27, 2019

If only CSS could be typed... 😗😜

But anyway, shouldn’t VRTs provide feedback if the CSS is wrong? 🤔

@montezume
Copy link
Contributor Author

Yeah, VRTs should give us an idea. Linting isn't just about finding errors though, it's also about finding duplicated css, etc. Stuff like this won't show up in VRTs but it's nice to get rid of it.

47:3 ✖ Unexpected duplicate "display" declaration-block-no-duplicate-properties

@@ -0,0 +1,36 @@
// copied from https://github.com/keplersj/jest-runner-stylelint/blob/master/src/run.js
// because it uses an older version of stylelint as a dep (not peer dep)
// we need new version of stylelint for css in js support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using yarn resolutions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I didn't know it existed 👍 🤣

@@ -196,6 +203,9 @@
"react-intl": "2.x",
"react-router-dom": "5.x"
},
"resolutions": {
"jest-runner-stylelint/stylelint": "10.0.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gives this warning, but I think it's the intended result

warning Resolution field "[email protected]" is incompatible with requested version "stylelint@^8.3.1"

@montezume
Copy link
Contributor Author

Alright, using the new version of stylelint solved the problems with trying to lint object styles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants