Promises support for the linter add-on

Hi,

I’m wondering why the linter plugin is not supporting Promises as hinter plugin does, but just the .async prop with callback.

Thanks for your amazing work!

The only reason is that it’s old, and no one has added promise support to it

OK thanks. I was asking just to know if there’s a design choice behind this.

I’d like to try pushing this change if I find time to implement it.

@keul Any chance you’ve done work on this?

Asking because I’m trying to implement Stylelint (Promises-based) into JSFiddle (which is CodeMirror-based), and that requires the linter add-ons to support Promises.

Done most work just to find out that the addon can’t handle the resolution of the Promise.

My code just in case:

(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    mod(require("../../lib/codemirror"));
  else if (typeof define == "function" && define.amd) // AMD
    define(["../../lib/codemirror"], mod);
  else // Plain browser env
    mod(CodeMirror);
})(function(CodeMirror) {
  "use strict";

  var defaultRules = Stylelint.standardConfig

  var validate = function(text, options) {
    var found = [];
    if (!window.Stylelint) {
      if (window.console) {
          window.console.error("Error: window.Stylelint not defined, CodeMirror CSS linting cannot run.");
      }
      return found;
    }

    Stylelint.verify({
      code: text,
      config: defaultRules
    }).then(output => {
      var messages = output.results[0].warnings

      for (const message of messages) {
        var startLine = message.line -1,
          endLine = message.line -1,
          startCol = message.column -1,
          endCol = message.column;

        found.push({
          from: CodeMirror.Pos(startLine, startCol),
          to: CodeMirror.Pos(endLine, endCol),
          message: message.text,
          severity: message.severity
        })
      }

    }).catch(err => {
      console.warn(`Failed to lint CSS! \n\n ${err}`)
    })

    return found
  };

  CodeMirror.registerHelper("lint", "css", validate)
});

@oskarkrawczyk after this old post I did a pull request for that change, and I’m using it.

My linter code plugin is something like:

export default (text, options, editor) => {
    return validationAPI(text).then((errors) => {
       return {
         message: ...
         severity: ....
         from: ...
         to: ...
       };
   }
}

Where validationAPI is a fetch call.

Thanks a lot @keul, that made things clearer!