Permalink
Browse files

Better error message on syntax as plugin

  • Loading branch information...
1 parent f2358c2 commit da790db2438726e9c341233928adfa4c708ef6c4 @ai ai committed Dec 24, 2016
Showing with 14 additions and 0 deletions.
  1. +5 −0 lib/processor.es6
  2. +9 −0 test/processor.js
View
@@ -104,6 +104,11 @@ class Processor {
normalized = normalized.concat(i.plugins);
} else if ( typeof i === 'function' ) {
normalized.push(i);
+ } else if ( typeof i === 'object' && (i.parse || i.stringify) ) {
+ throw new Error('You pass PostCSS syntax as plugin. ' +
+ 'Check you PostCSS runner docs ' +
+ 'and use syntax, parser or stringifier ' +
+ 'option instead.');
@ben-eb
ben-eb Dec 24, 2016 Member

PostCSS syntaxes cannot be used as plugins. Instead, please use the syntax/parser/stringifier option(s) outlined in your PostCSS runner documentation.

@ai
ai Dec 25, 2016 Member

Send PR. But you could set one option from this list, so option

@ben-eb
ben-eb Dec 25, 2016 Member

You can set a custom parser and a custom stringifier, so I think this is correct. 😄

For example postcss-safe-parser & midas' stringifier.

@ai
ai Dec 25, 2016 Member

You have syntax option to set it both

@ai
ai Dec 25, 2016 Member

Ouh, you mean different. But here use set some specific syntax 😆

@ben-eb
ben-eb Dec 25, 2016 edited Member

I think I don't like using the singular form of "option" here as it is describing options as a plural, so if it is correct to use only one maybe this should read like this instead:

PostCSS syntaxes cannot be used as plugins. Instead, please use one of the syntax/parser/stringifier options as outlined in your PostCSS runner documentation.

} else {
throw new Error(i + ' is not a PostCSS plugin');
}
View
@@ -429,3 +429,12 @@ test('uses custom syntax', t => {
test('contains PostCSS version', t => {
t.regex((new Processor()).version, /\d+.\d+.\d+/);
});
+
+test('throws on syntax as plugin', t => {
+ let processor = new Processor();
+ t.throws( () => {
+ processor.use({
+ parse() { }
+ });
+ }, /syntax/);
+});

0 comments on commit da790db

Please sign in to comment.