On 01/07/2014 01:26 AM, Hallvord R. M. Steen wrote:
> Hey, I'd appreciate some code review of this method - just two methods in Python:
>
>
https://github.com/seiflotfy/mozcompat/blob/master/browser.py#L44 onwards to line 98
>
> I've added some special-casing for flexbox rules - the idea is that we want to warn if a site is doing
> .foo{display:box}
> but NOT warn if the site is doing
> .foo{display:box; display: flex}
> because it's not an issue when the standards-compliant CSS is included as well.
Nice!
Unfortunately, I think you'll need similar special-cases for a bunch of
other properties related to -webkit-box / flexbox, too, or else you'll
incorrectly flag pages as being incompatible.
For example, if you have styles like the following:
.foo { display:-webkit-box; display: flex }
.foo > * { -webkit-box-flex: 1; flex: 1 }
.foo > .childToReorder { -webkit-box-ordinal-group: 2; order: 2 }
...I suspect your tool would warn about the use of "-webkit-box-flex"
and "-webkit-box-ordinal-group" without unprefixed variants. But
really, it shouldn't warn, since those properties' new versions (from
new flexbox) are included - they just have different names.
I'm not sure if there's a comprehensive list of these flexbox
property-mappings anywhere (partly because they aren't direct mappings),
but [1] has some of them, and [2] has more in a less readable form.
A few more comments, with links to spots in the code:
***
*
https://github.com/seiflotfy/mozcompat/blob/master/browser.py#L61-62
You probably want something like this for "display:-ms-flexbox", too.
(IE10 uses that name because "display:flex" was going to be named
"display:flexbox" for a period of time, and IE10 was feature-frozen (as
part of Windows 8) with prefixed support for -ms-flexbox during that
time [3])
Similarly, you'll want to check for -ms-prefixed flexbox accessory
properties from IE10, listed here: [4]
***
*
https://github.com/seiflotfy/mozcompat/blob/master/browser.py#L65
I might be mistaken, but it looks like you're checking for (unprefixed)
"display: box" and "display: flexbox" here, correct? If so: I'm not sure
that's useful, because (as far as I know), no browser supports
unprefixed versions of either of those display values. WebKit/blink have
"display:-webkit-box" and IE has "display:-ms-flexbox", as noted above,
but neither have unprefixed support (because those aren't standard
property-names).
So this check might not actually be useful in practice, since any
"display:box"/"display:flexbox" style that it flags will be rejected by
*all* browsers (and hence isn't really a "compatibility" issue :) )
***
*
https://github.com/seiflotfy/mozcompat/blob/master/browser.py#L52
With the "at_keyword" check here, it looks like you're discarding
everything inside of @ rules. You probably don't want to do that -- a
lot of interesting mobile-specific (i.e. likely-webkit-prefixed) code
could easily be inside of an @media query based on the screen size. You
probably want to refactor this to have a "process_rule" function, which
would look something like:
def process_rule(rule):
if (rule.at_keyword is None):
process_concrete_rule(rule)
elif (rule.at_keyword == 'media'):
# Make recursive call on each subrule
# (which themselves could be @rules)
for subrule in rule.rules:
process_rule(rule);
elif (rule.at_keyword == 'page'):
# @page is like a special selector; treat it
# like a normal rule.
process_concrete_rule(rule)
else
# Maybe report an unsupported at_keyword here?
Footnotes:
[1]
http://css-tricks.com/using-flexbox/
[2]
https://gist.github.com/cimmanon/4461470#file-flexbox-scss-L46
[3]
http://msdn.microsoft.com/en-us/library/ie/hh673531%28v=vs.85%29.aspx
[4]
http://msdn.microsoft.com/en-us/library/ie/dn265027%28v=vs.85%29.aspx
~Daniel