Open nex3 opened 6 years ago
I could tackle this in the future, but for now I just need help getting the project running. :man_shrugging:
Hi @nex3 , this one is pretty tricky, as Expression
has no isParenthesized
or anything. Looks to me like this would require a change to dart-sass, to track such things. WDYT?
That's possible, but it would add a lot of boilerplate to the parsing code. Could you use something like expression.span.text.codeUnitAt(0) == $lparen
?
The parens are actually not included in the expression's span either. Here's a little debug print:
Given IfNode: "@if 1 == 2 { @warn('uh oh'); }",
clause span is: "1 == 2"
Given IfNode: "@if (1 == 2) { @warn('uh oh'); }",
clause span is: "1 == 2"
Given IfNode: "@if (1+1)*2 == 2 { @warn('uh oh'); }",
clause span is: "1+1)*2 == 2"
Given IfNode: "@if ((1+1)*2) - 1 == 2 { @warn('uh oh'); }",
clause span is: "1+1)*2) - 1 == 2"
Since nested parethesized expressions also don't include their parens, I can't do some hack where I just subtract one from the leftmost character or something.
I ran into this when I was writing the formatter as well.
Oh, that's not good. I've filed https://github.com/sass/dart-sass/pull/503 to fix it, which should also make detecting parens much easier.
@mik01aj Want to tackle this one? I've got the project fixed up for Dart 2. This should be a fairly straight-forward rule; the existing ones would make fine examples, like use_falsey_null.
Sorry for the late reply - only now I had the time to setup the project, learn some Dart basics, and make a PR (#30). Please have a look :)
Sometimes users who are familiar with other languages forget that Sass doesn't need parentheses around its conditionals (as in,
@if (...) {
, or@else if (...) {
, or@while (...) {
). The linter should suggest that these parentheses be removed.