-
Notifications
You must be signed in to change notification settings - Fork 61
Conversation
ericberens
commented
Jan 18, 2018
- Updated processor to return the original input on SyntaxError errors so it can fall through to other processors
* Updated processor to return the original input on SyntaxError errors so it can fall through to other processors
Ideally, stylelint directly should handle whether or not a processor should process a particular file but since that is not supported I'd like to be able to pass off the input to other processors in the case where the stylelint-processor-styled-components is unable to parse the input. Originally I solved this by running separate npm command
but that was problematic trying to get https://github.com/shinnn/vscode-stylelint to work since it requires a single configuration and I was stuck choosing which type of implementation I wanted to lint at the IDE level. |
Interesting, so I'm assuming that what you did here works right? Could you add some tests please? But yeah this would be a very nice feature to have |
src/index.js
Outdated
// incorrect interpolations will throw CssSyntaxError and they'll be handled by stylelint | ||
if (e.name === 'CssSyntaxError') { | ||
throw e | ||
} | ||
if (name === 'SyntaxError') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a comment above here would be awesome too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add a comment and update PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericberens By the way, how about checking e.name
directly, without a new local variable declared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, especially because we use e.name
in the conditional above, that's odd and inconsistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it's necessary to even do the name === 'SyntaxError'
check, will it be sufficient to just return input
on all errors and let the stylelint engine process it?
@emilgoldsmith yes, returning the input in an explicit error branch or in general as a replacement to '' allows for the input to fall through to any additional configured processors or if no additional processors are configured assumed (by default usage) that it is vanilla CSS. Will add a comment regarding the additional conditional statement and look to add test to cover this scenario. |
Sounds good. Yeah my biggest question was also whether the But yeah otherwise I think I like this implementation as long as the if statement catches exactly the cases we want it to. As anything non-javascript shouldn't be passed to our processor anyway, so if it's CSS it'll just be processed and if it's a third language the rest of Stylelint can throw whatever errors it should as either there's another processor (as you mention) or someone accidentally gave an invalid file as input |
I was wondering why my global stylesheets weren't linting properly, and it turns out that there's a @ericberens are you still on this PR? I can help to update it with the comments if you're unable to do so 😄! |
Yeah I mention it in this issue: #155, though it should probably have been a separate issue. Feel free to make it throw a CssSyntaxError though that Stylelint can understand, and update the PR to do that. As to your suggestion of just returning The reason for this PR I believe (though it's been a while since I last looked at it) is to allow people to lint both css files and CSS-in-JS files with our processor, correct @ericberens ? @jiahaog if you want to help out feel free to update this one or just submit a new PR |
Any chance it'll be merged soon? 😄 |
If someone finishes it I guess |
Closed by #211. |