editorconfig-core-java icon indicating copy to clipboard operation
editorconfig-core-java copied to clipboard

EditorConfig validator: support for line/column, offset info with ParsingException

Open angelozerr opened this issue 8 years ago • 3 comments

It should be cool if we could have an utility method validate which waits a String content of an editorconfig and throws ParsingException when this content is not well formatted:

public class  EditorConfig {

....
  public void validate(String editorConfigContent) throws ParsingException {
    // here parse editorConfigContent and throws ParsingException  with line/column, offset info
  }
}

Here a sample with miss of close of [ for section names:

[*]
charset = utf-8

[*.md // <- here there is an error because section is not closed

The exception ParsingException should contains offset and line/column info where there is an error.

With this utility method validate, any IDE could support validation with marker.

Many thanks!

angelozerr avatar May 26 '16 07:05 angelozerr

As I have worked about this topic several month ago, I have pushed my POC at https://github.com/angelozerr/editorconfig-java-parser

You can find a very basic demo which uses the parser:

EditorConfigDemo

If you are interested tell me.

angelozerr avatar May 26 '16 17:05 angelozerr

@angelozerr Thanks for your validator! The syntax validator is definitely useful. However, the core library should not validate any property/value names, as the editor plugins should be able to make some extensions on their own, without modifying core libraries.

xuhdev avatar May 27 '16 01:05 xuhdev

@angelozerr Thanks for your validator!

Glad this idea please you.

However, the core library should not validate any property/value names,

The parser DO NOT that. It throws an exception if section is not closed, etc, but it doesn't validate option name, value.

as the editor plugins should be able to make some extensions on their own, without modifying core libraries.

At first, the EditorConfig parser is a parser of editorconfig content. You can compare it to SAX parser which works with handler. See https://github.com/angelozerr/editorconfig-java-parser/blob/master/fr.opensagres.editorconfig/src/fr/opensagres/editorconfig/handlers/EditorConfigHandler.java

The parser is able to call those events. So after that you can implement handler like you wish:

  • to validate option name (ex: 'indent_style' is OK, but 'XXXindent_style' is not OK), option value (indent_style should have space or tab). It is in my scope.
  • you could implement the same feature that you have implemented to apply editorconfig in a file. You use Regexp to extract section (https://github.com/editorconfig/editorconfig-core-java/blob/master/src/main/java/org/editorconfig/core/EditorConfig.java#L190). With my parser you retrieve section by implementing handler (I will try to do it too).

angelozerr avatar May 27 '16 02:05 angelozerr