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

Add a lint for named colors as map keys #17

Open
nex3 opened this issue Sep 20, 2018 · 2 comments
Open

Add a lint for named colors as map keys #17

nex3 opened this issue Sep 20, 2018 · 2 comments

Comments

@nex3
Copy link

nex3 commented Sep 20, 2018

A mistake we see occasionally is users using unquoted strings as map keys, having one of those keys be named something like blue, and getting confused later on when that key compiles to #00f instead. We should add a lint rule to help out with this.

The most conservative way to do this is probably to warn the user when a map:

  • contains an unquoted string key,
  • contains a color name key, and
  • contains only unquoted string or color name keys.

Less conservatively, we could also warn about maps that have keys of mixed type in general or maps with any unquoted string keys, although this risks having more false positives.

@mik01aj
Copy link

mik01aj commented Sep 28, 2018

I see you want to prevent sass/libsass#652, but wouldn't #12 also solve it in a more generic way?

Also, do these examples describe what you expect here?

$theme1: (primary: #f00, secondary: #00f); // ok
map-get($theme1, primary); // ok
map-get($theme1, 'primary'); // ok

$theme2: (red: #f00, blue: #00f); // linter error
map-get($theme2, red); // linter error
map-get($theme2, 'red'); // ok (although this won't work, afaik)

$theme3: ('red': #f00, 'blue': #00f); // ok
map-get($theme3, red); // linter error
map-get($theme3, 'red'); // ok

@nex3
Copy link
Author

nex3 commented Sep 28, 2018

I see you want to prevent sass/libsass#652, but wouldn't #12 also solve it in a more generic way?

Yes, it is kind of redundant with #12. It may still be useful to have both, though, for users who find #12 to be too onerous and disable it.

Also, do these examples describe what you expect here?

$theme1: (primary: #f00, secondary: #00f); // ok
map-get($theme1, primary); // ok
map-get($theme1, 'primary'); // ok

$theme2: (red: #f00, blue: #00f); // linter error
map-get($theme2, red); // linter error
map-get($theme2, 'red'); // ok (although this won't work, afaik)

$theme3: ('red': #f00, 'blue': #00f); // ok
map-get($theme3, red); // linter error
map-get($theme3, 'red'); // ok

For this and other map key lints, I was just thinking that it would affect literal maps, not map-get() calls.

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

No branches or pull requests

2 participants