SomMeri / less4j

Less language is an extension of css and less4j compiles it into regular css. Less adds several dynamic features into css: variables, expressions, nested rules, and so on. Less was designed to be compatible with css and any correct css file is also correct less file.
145 stars 47 forks source link

Better error messages #255

Closed gdelhumeau closed 9 years ago

gdelhumeau commented 9 years ago

Hi.

Example or error message:

ERROR 1055:16 required (...)+ loop did not match anything at input '{' in selectors (which started at 1055:16)

In my case, it do not always have the complete file which is compiled (it is computed internally by my program, and I have to use the debugger to see the problem).

What could be great is to display the lines which pose the problem.

Something like:

ERROR 1055:16 required (...)+ loop did not match anything at input '{' in selectors (which started at 1055:16)
...
a:hover,
  .active > a, {
    border-color: @brand-primary;
...

Thanks, Guillaume

SomMeri commented 9 years ago

Preview of the change, if you have improvements (even more context?) let me know:

Before:

Errors produced by compilation of testCase
ERROR 2:11 The variable "@undefinedVariable" was not declared.
ERROR 6:3 The namespace "#doesNotExists > .mixin(...)" was not declared.
ERROR 6:20 Could not find mixin named ".mixin".
ERROR 10:3 The namespace "#undefinedNamespace > #doesNotExists > .mixin(...)" was not declared.

After:

Errors produced by compilation of testCase
ERROR 2:11 The variable "@undefinedVariable" was not declared.
 1: #undefinedVariable {
 2:   margin: @undefinedVariable;
 3: }

ERROR 6:3 The namespace "#doesNotExists > .mixin(...)" was not declared.
 5:   padding: 2 2 2 2;
 6:   #doesNotExists > .mixin();
 7: }

ERROR 6:20 Could not find mixin named ".mixin".
 5:   padding: 2 2 2 2;
 6:   #doesNotExists > .mixin();
 7: }

ERROR 10:3 The namespace "#undefinedNamespace > #doesNotExists > .mixin(...)" was not declared.
  9:   padding: 2 2 2 2;
 10:   #undefinedNamespace > #doesNotExists > .mixin();
 11: }
gdelhumeau commented 9 years ago

Nice!

Maybe you could add the name of the file where the error happens, because it can be inside an imported file.

Thanks a lot, Guillaume

SomMeri commented 9 years ago

Thank you for answer, there are 69 tests with error so I wanted to get feedback/ideas before I change them all.

The 'testCase' is the file name in the above example. If the error happen in imported file, report looks like this:

Errors produced by compilation of testCase
ERROR import\syntactically-incorrect-wrong-variable.less 3:10 The variable "@undefinedVariable" was not declared.
 2: ruleset {
 3:   color: @undefinedVariable;
 4: }