css-modules / postcss-icss-values

Pass arbitrary constants between your module files
MIT License
203 stars 18 forks source link

Fail when you import invalid values #39

Open cesarandreu opened 8 years ago

cesarandreu commented 8 years ago

It would be extremely useful to get errors when you import a value which doesn't exist.

I've been using module values for a couple months now, and silent failures have definitely been one of my bigger pain-points.

(In the following example, the components folder would be symlinked to node_modules/components.)

For example:

components/styles/colors.css

@value Primary: #2196F3;

components/Foo/Foo.css

@value colors: 'components/styles/colors.css';
@value Primarry from colors;

.foo {
  background-color: Primarry;
}

In this scenario, it's a small typo, where I accidentally added an extra r when naming the imported value, and when I was typing the background color I just hit tab to autocomplete.

I've somewhat worked around this variation of the issue by using editor plugins such as All Autocomplete.

However, the other scenario in which it fails is when you're refactoring. There's no easy way of confirming that a value is no longer being used anywhere. On the other hand, if deleting a value from colors.css caused compilation to fail, I could follow the errors and update all references.

Would it be feasible to implement this kind of behavior?