Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Distinguish helpers/mixins from component styles #244

Open
TrevorBurnham opened this issue Jan 7, 2019 · 5 comments
Open

Distinguish helpers/mixins from component styles #244

TrevorBurnham opened this issue Jan 7, 2019 · 5 comments

Comments

@TrevorBurnham
Copy link

I'm trying to write an in-house stylelint rule that we want to apply to mixins, e.g.

const mixin = css`
  /* Linter rule SHOULD apply here */
`;

but not to styled components, e.g.

const Component = styled.div`
  /* Linter rule should NOT apply here */
`;

Basically I want to access the result of isHelper() from within a stylelint rule. One way I could imagine this being implemented is to add another map to index.js (e.g. isHelperMap) and export it, so that in my rule I could run this check:

const { isHelperMap } = require('stylelint-processor-styled-components');

module.exports = stylelint.createPlugin(
  ruleName,
  (actual, secondary, context) => {
    return function(root, result) {
      if (isHelperMap[root.source.input.file]) {
        // ...
      }
    }
  }
);

It might be even more useful to provide the type of helper in the map, e.g. "css", "keyframes", or "injectGlobal".

@chinesedfan
Copy link
Member

It shares part of #253. And I don't think another processor should depend on this processor to parse helper names. Maybe a common util package is better.

@TrevorBurnham
Copy link
Author

@chinesedfan I like the approach in #258, but for that to be a solution here I'd need to be able to map different rules to different moduleName/importName settings. E.g. I want most rules to apply to all style blocks, but I want one rule to apply only to css blocks.

@chinesedfan
Copy link
Member

And I don't think another processor should depend on this processor to parse helper names. Maybe a common util package is better.

@TrevorBurnham I mistook your in-house rule as another processor. But the conclusion is the same. You'd better distinguish helpers/mixins by your rule itself, instead of depending on this processor.

@TrevorBurnham
Copy link
Author

You'd better distinguish helpers/mixins by your rule itself, instead of depending on this processor.

That's just the problem: As far as I can tell, there's no way for my rule to distinguish between helpers and mixins. Can you think of a way?

@chinesedfan
Copy link
Member

I am afraid not. Because rules have no information about the original codes.

codes -> processors -> css -> rules

On the other side, your problem seems not to be an issue belongs to this processor.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants