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

Accept syntax object in customSyntax option #4839

Merged
merged 3 commits into from Jul 6, 2020
Merged

Conversation

m-allanson
Copy link
Member

This overloads the customSyntax option to also accept a syntax object. The option also maintains its previous behaviour of accepting a string. This should be a fully backwards compatible change.

The signature of this option has changed from string to string | { parse: Function }. This follows the convention of the formatter option, which has similar behaviour.

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

#3935.

Is there anything in the PR that needs further explanation?

This is based on a section of #4796. This is the only part of that PR that changes existing functionality.

The change itself is fairly straightforward, but it's probably worth detailing some of the why.

Why?

This API will be used to load non-standard CSS syntaxes (scss, less, css-in-js etc) when running in the browser.

What is a syntax?

A syntax is typically an object containing two functions, parse and stringify. Stylelint uses a syntax to transform your CSS-like code into a structure that can be linted, and then back again.

Why do you need a custom syntax?

stylelint ships with syntaxes for linting the various flavours of CSS-like code that people use. These syntaxes won't be included in the default browser bundle as they are quite large - several MB for all of stylelint's included syntaxes.

What's wrong with using a string, anyway?

The customSyntax option uses Node.JS's require function to load the syntax. It turns a string like my-excellent-syntax into a 'live' JS module. require is not available in the browser.

Allowing the customSyntax option to accept a syntax object means the host environment (whether a browser, Node.JS or something else) can deal with how to load the syntax, and then pass the object in for stylelint to use.

@m-allanson m-allanson mentioned this pull request Jun 23, 2020
14 tasks
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.

Looks great, thanks!

Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

Can't say I'm well-versed in the reason behind these changes, but looks good on my end. I don't see how an object without a parse and stringify function will pass through the check. LGTM!

@jeddy3 jeddy3 merged commit 03a0cea into master Jul 6, 2020
@jeddy3 jeddy3 deleted the custom-syntax-object branch July 6, 2020 14:52
@jeddy3
Copy link
Member

jeddy3 commented Jul 6, 2020

  • Added: syntax object acceptance to customSyntax option (#4839).

m-allanson added a commit that referenced this pull request Jul 8, 2020
# By Richard Hallows (4) and others
# Via GitHub
* master:
  Create codeql analysis workflow (#4850)
  Update CHANGELOG.md
  Add support for descriptions in stylelint command comments (#4848)
  Update CHANGELOG.md
  Add *-allowed-list/*-disallowed-list/*-required-list names for *-whitelist/*-blacklist/*-requirelist rules (#4845)
  Update CHANGELOG.md
  Add syntax object acceptance to customSyntax option (#4839)
  Bump typescript from 3.9.5 to 3.9.6 (#4853)
  Add ignoreComments[] to comment-empty-line-before (#4841)
  Bump autoprefixer from 9.8.0 to 9.8.2 (#4838)
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