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

Export an object from the CSS-in-JS syntax #4824

Merged
merged 2 commits into from Jun 9, 2020

Conversation

m-allanson
Copy link
Member

Which issue, if any, is this issue related to?

This change is a small part of the changes in PR #4796.

Is there anything in the PR that needs further explanation?

The CSS-in-JS syntax was previously being exported as a function instead of an object. This worked because functions can still have properties attached to them. It was a bit confusing though.

This PR updates the syntax to export an object.

After the first commit in this PR, the test should fail like this:

 FAIL  lib/__tests__/syntaxes.test.js
  ● syntaxes › syntax is an object with parse and stringify keys: css-in-js

    expect(received).toMatchObject(expected)

    Matcher error: received value must be a non-null object

    Received has type:  function
    Received has value: [Function syntax]

      10 | describe('syntaxes', () => {
      11 |      it.each(inputs)('syntax is an object with parse and stringify keys: %s', (name, module) => {
    > 12 |              expect(module).toMatchObject({
         |                             ^
      13 |                      parse: expect.any(Function),
      14 |                      stringify: expect.any(Function),
      15 |              });

      at lib/__tests__/syntaxes.test.js:12:18

@m-allanson m-allanson mentioned this pull request Jun 6, 2020
14 tasks
@hudochenkov
Copy link
Member

Looks like this should be fixed in @stylelint/postcss-css-in-js, because it doesn't export an object.

@m-allanson
Copy link
Member Author

A couple of the other syntaxes do the same thing, check out:

module.exports = require('@stylelint/postcss-markdown')({
scss: require('postcss-scss'),
less: require('postcss-less'),
sass: require('postcss-sass'),
sugarss: require('sugarss'),
});

module.exports = require('postcss-html')({
scss: require('postcss-scss'),
less: require('postcss-less'),
sass: require('postcss-sass'),
sugarss: require('sugarss'),
});

I think the function export is by design, so it can be configured at require time. e.g. https://github.com/stylelint/postcss-css-in-js/tree/7a28eabd8851114b3394b89c8d510bd1da2e1690#advanced-use-cases

This seemed like the most pragmatic "fix" given that some of the other syntaxes work like this too. What do you think?

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Thanks.

@m-allanson m-allanson merged commit 7cf0c36 into master Jun 9, 2020
@m-allanson m-allanson deleted the issue-3935/syntaxes-test branch June 9, 2020 11:13
m-allanson added a commit that referenced this pull request Jun 10, 2020
# By Mike Allanson (6) and others
# Via GitHub
* master:
  Bump got from 11.2.0 to 11.3.0 (#4825)
  Export an object from the CSS-in-JS syntax (#4824)
  Add type `Formatter` for formatter functions (#4823)
  Update CHANGELOG.md
  Fix false positives for namespaced variables in property-no-unknown (#4803)
  Update CHANGELOG.md
  Fix TypeError for inline comments and autofix for sugarss in max-empty-lines (#4821)
  Create new 'lintPostcssResult' module (#4819)
  13.6.0
  Update deps
  Prepare 13.6.0
  Update CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants