Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Remove selector wrap from injectGlobal #116

Merged
merged 7 commits into from
Sep 2, 2017
Merged

Conversation

emilgoldsmith
Copy link
Member

@emilgoldsmith emilgoldsmith commented Aug 31, 2017

resolves #26.

Put this together on the plane, could possibly use a few more tests but I think it should be pretty okay?

Copy link
Member

@mxstbr mxstbr left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for digging into this! One comment above, why'd you remove that test?

Could also use some more specific tests, but then we should be good to ship 👌

margin: 0;
}
`

Copy link
Member

Choose a reason for hiding this comment

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

That should still be an error, that's wrong indentation. Just like we don't support it with css or styled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, I forgot to comment on this as I wrote the code yesterday. The problem is my removeBaseIndentation function and I don't see any good way to go around this, do you understand what I mean or should I be more explicit?

Copy link
Member

Choose a reason for hiding this comment

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

Not quite, why shouldn't this throw an error anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah sorry I'm also a bit jetlagged and sitting in an 8 hour orientation day at NYU but I'll do my best :P.

In order to avoid general indentation errors I need to remove all the base indentation, right? So as long as that function is being called this won't throw an error. And in order to make it throw an error we would somehow need to induce an error as if they don't indent anything like that we actually just want to straight up insert it. It's purely a Styled Components style problem, not a css problem.

I'm not saying we shouldn't, I'm saying it's maybe too hard

Copy link
Member

Choose a reason for hiding this comment

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

In order to avoid general indentation errors I need to remove all the base indentation, right?

Is it not the goal here to have exactly the same output as what styled-components' injectGlobal would output? Because that's basically what we want to lint right?

Copy link
Member

Choose a reason for hiding this comment

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

The whole point is that it looks ugly in JS! We aren't linting the resulting CSS we're linting the code the user wrote and we make sure it doesn't look ugly and has errors.

Copy link
Member

Choose a reason for hiding this comment

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

That's why

const Button = styled.button`
color: blue;
`

throws an error, eventhough the resulting CSS is the same it's still ugly and it's a stylelint error. That's the whole point of stylelint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah and I get that part, and while @ismay might be making a slightly different point than mine, my reason for removing that test was simply that my only way of implementing this in a simple way broke that test, so I deleted it thinking of it as collateral damage of this PR, not because I wanted to delete it but because I "had to" (not really I guess, I haven't thought it out yet but it seems like it'd get really ugly writing that code to handle this special case, and the code could possibly be error prone as well and yeah...).

The thing is, in order to prevent all the other cases of the indentation rule breaking we need to put everything on the baseline anyway, so we'd have to somehow implement the stylelint indentation rule ourselves in order to check if before we put it on the baseline whether it has broken our semantics and then somehow put in a purposefully wrongly indented piece of css into stylelint to force it to throw an error or something like that and that get's messy reeaaaalll fast I'm afraid.

That's my side of the story.

Copy link
Member

Choose a reason for hiding this comment

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

Ahhh okay, that makes sense. In that case, let's log that somewhere and move on!

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay haha :)

@emilgoldsmith
Copy link
Member Author

@mxstbr so if we're at least temporarily okay with deleting the broken test I deleted is there anything else you'd like changed specifically for you to approve the PR and we merge it in?

@mxstbr
Copy link
Member

mxstbr commented Sep 2, 2017

Just some tests that use injectGlobal, that's all!

@emilgoldsmith
Copy link
Member Author

Just some tests that use injectGlobal, that's all!

Hmmm... maybe I could add one to test/fixtures/simple/valid.js, but something that isn't visible from the PR as that was already in place is that there are already a few fixtures with injectGlobal I just deleted one of them that broke but the rest are still there:
https://github.com/styled-components/stylelint-processor-styled-components/blob/bddac5bdd15568d289fe33affbc95836d3eb3e54/test/fixtures/simple/helpers.js
and
https://github.com/styled-components/stylelint-processor-styled-components/blob/bddac5bdd15568d289fe33affbc95836d3eb3e54/test/fixtures/simple/imports.js

it's not like that's super hardcore tested, but it is in there, and I adjusted the expect x amount of warnings to our new expected behavior, so apart from maybe adding an injectGlobal to valid.js I'm not quite sure what else I'd add, does that sound okay?

@mxstbr
Copy link
Member

mxstbr commented Sep 2, 2017

Just add the code from the original issue that we're trying to fix as a test:

injectGlobal`
  html {
    color: blue;
  }
`;

to make sure we don't regress 😊 That's all!

@emilgoldsmith
Copy link
Member Author

Okay, I'll get it over and done with right away :)

@emilgoldsmith
Copy link
Member Author

Okay, I believe this should be ready now :).

There was more prettier weird errors like @mxstbr experienced recently and I also did in the start of my time contributing here, I had to do an npm install to be able to see the error as well, I'm not sure if I had an outdated version of prettier? Did we update it recently? Anyway I added the package-lock.json changes my npm install introduced and fixed the error that it seems was in code I hadn't even changed, maybe my old version of prettier had changed something that the new one didn't agree on or something.

Anyway, stuff should be good now.

I'll just rebase it now to get rid of the merge conflicts.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.598% when pulling ac5ef7d on fix/#26/inject-global-wrap into e0a30ae on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.598% when pulling ac5ef7d on fix/#26/inject-global-wrap into e0a30ae on master.

@mxstbr
Copy link
Member

mxstbr commented Sep 2, 2017

-0.4% coverage 😢

@mxstbr
Copy link
Member

mxstbr commented Sep 2, 2017

This part in removeBaseIndentation isn't covered:

screen shot 2017-09-02 at 6 20 04 pm

Any ideas if this code is necessary/if we can test it?

@emilgoldsmith
Copy link
Member Author

Oh yeah, I'll just pop in a unit test covering that :)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling ad0c864 on fix/#26/inject-global-wrap into e0a30ae on master.

@mxstbr mxstbr merged commit c3eb8b8 into master Sep 2, 2017
@mxstbr mxstbr deleted the fix/#26/inject-global-wrap branch September 2, 2017 19:30
@mxstbr
Copy link
Member

mxstbr commented Sep 2, 2017

Awesome!! Let's open an issue for that indentation thing?

@emilgoldsmith
Copy link
Member Author

Wuhuu! Doesn't this actually mean we're ready for publishing 1.0 now? :D.

We'd of course update the changelog as part of the publish, but I actually think this is all that I personally wanted fixed before 1.0 anyway.

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

Successfully merging this pull request may close these issues.

Don't prefix injectGlobal with a selector
4 participants